hexsha stringlengths 40 40 | size int64 5 1.05M | ext stringclasses 588 values | lang stringclasses 305 values | max_stars_repo_path stringlengths 3 363 | max_stars_repo_name stringlengths 5 118 | max_stars_repo_head_hexsha stringlengths 40 40 | max_stars_repo_licenses listlengths 1 10 | max_stars_count float64 1 191k ⌀ | max_stars_repo_stars_event_min_datetime stringdate 2015-01-01 00:00:35 2022-03-31 23:43:49 ⌀ | max_stars_repo_stars_event_max_datetime stringdate 2015-01-01 12:37:38 2022-03-31 23:59:52 ⌀ | max_issues_repo_path stringlengths 3 363 | max_issues_repo_name stringlengths 5 118 | max_issues_repo_head_hexsha stringlengths 40 40 | max_issues_repo_licenses listlengths 1 10 | max_issues_count float64 1 134k ⌀ | max_issues_repo_issues_event_min_datetime stringlengths 24 24 ⌀ | max_issues_repo_issues_event_max_datetime stringlengths 24 24 ⌀ | max_forks_repo_path stringlengths 3 363 | max_forks_repo_name stringlengths 5 135 | max_forks_repo_head_hexsha stringlengths 40 40 | max_forks_repo_licenses listlengths 1 10 | max_forks_count float64 1 105k ⌀ | max_forks_repo_forks_event_min_datetime stringdate 2015-01-01 00:01:02 2022-03-31 23:27:27 ⌀ | max_forks_repo_forks_event_max_datetime stringdate 2015-01-03 08:55:07 2022-03-31 23:59:24 ⌀ | content stringlengths 5 1.05M | avg_line_length float64 1.13 1.04M | max_line_length int64 1 1.05M | alphanum_fraction float64 0 1 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
b2bffc051893e188f137d6475092d38cf3e029cc | 3,534 | h | C | A06 - Octree/Octree.h | ico3939/Simplex_17-18_Spring-master | 1aceb404754cdc2775a224b67b87871e970f197d | [
"MIT"
] | null | null | null | A06 - Octree/Octree.h | ico3939/Simplex_17-18_Spring-master | 1aceb404754cdc2775a224b67b87871e970f197d | [
"MIT"
] | null | null | null | A06 - Octree/Octree.h | ico3939/Simplex_17-18_Spring-master | 1aceb404754cdc2775a224b67b87871e970f197d | [
"MIT"
] | null | null | null | #ifndef __OCTREE_H_
#define __OCTREE_H_
#include "MyEntityManager.h"
namespace Simplex
{
class Octree {
// Variables used throughtout
// --------------------------
static uint m_uiNumOctant;
static uint m_uiNumLeaves;
static uint m_uiMaxLevel;
static uint m_EntityCount;
uint m_uiOctID = 0; // Will store the current ID for this octant
uint m_uiCurrLevel = 0; // Will store the current level of the octant
uint m_uiNumChildren = 0;// Number of children on the octant (either 0 or 8)
MeshManager* m_pMeshMngr = nullptr; //Mesh Manager singleton
MyEntityManager* m_pEntityMngr = nullptr; //Entity Manager Singleton
vector3 m_v3OctantSize = ZERO_V3; // size of the octant
vector3 m_v3OctantCenter = ZERO_V3; // Will store the center point of the octant
vector3 m_v3OctantMin = ZERO_V3; // Will store the minimum vector of the octant
vector3 m_v3OctantMax = ZERO_V3; // Will store the maximum vector of the octant
Octree* m_pOctParent = nullptr; // Will store the parent of current octant
Octree* m_aOctChildren[8]; // Will store the children of the current octant
std::vector<uint> m_vEntityList; // List of Entities under this octant (Index in Entity Manager)
uint m_uiCurrEntityCount = 0;
Octree* m_pOctRoot = nullptr; // Root octant
std::vector<Octree*> m_v3RootChildren; // List of nodes that contain objects (this will be applied to root only)
// -----------------------------------
public:
bool wireFrameSwitch = true;
// Constructor, will create an octant containing all MagnaEntities Instances in the Mesh
Octree(uint p_MaxLevel = 2, uint p_EntityCount = 5);
// Constructor a_v3Center->Center of the octant in global space a_fSize->size of each side of the octant volume
Octree(vector3 p_Center, vector3 p_Size);
// Copy constructor
Octree(Octree const& other);
// Deconstructor
~Octree(void);
// Getter methods
// --------------
vector3 GetSize(void);
vector3 GetCenterGlobal(void);
vector3 GetMinGlobal(void);
vector3 GetMaxGlobal(void);
// ------------------------
// Asks if there is a collision with the Entity specified by index from the Bounding Object Manager
bool IsColliding(uint a_uRBIndex);
// Displays the Octree
void Display(uint a_uIndex, vector3 a_v3Color = C_GREEN);
// Displays the Octree
void DisplayCurrent(vector3 a_v3Color = C_GREEN);
// Displays the whole Octree
void DisplayAll(vector3 a_v3Color = C_GREEN);
// Clears the Entity list for each node
void ClearEntityList(void);
// Allocates 8 smaller octants in the child pointers
void Subdivide(void);
// Returns the child specified in the index
Octree* GetChild(uint a_nChild);
// Returns the parent of the Octree
Octree* GetParent(void);
// Asks the Octree if it does not contain any children
bool IsLeaf(void);
// Asks the Octree if it contains more than this many Bounding Objects
bool ContainsMoreThan(uint a_nEntities);
// Deletes all children and the children of their children
void KillBranches(void);
// Gets the total number of octants in the world
uint GetOctantCount(void);
// Gets the total number Leaves in the world
uint GetLeafCount(void);
// Assigns the appropriate to the entities in the dimension
void ConfigureDimensions(void);
private:
// Deallocates member fields
void Release(void);
// Allocates member fields
void Init(void);
};
}
#endif | 30.465517 | 115 | 0.693548 |
5ebbf8e85583a4fdce73b7c1d1f96957436d1ed3 | 4,536 | h | C | modfile/subrecords/srcontdatasubrecord.h | uesp/tes5lib | 07b052983f2e26b9ba798f234ada00f83c90e9a4 | [
"MIT"
] | 11 | 2015-07-19T08:33:00.000Z | 2021-07-28T17:40:26.000Z | modfile/subrecords/srcontdatasubrecord.h | uesp/tes5lib | 07b052983f2e26b9ba798f234ada00f83c90e9a4 | [
"MIT"
] | null | null | null | modfile/subrecords/srcontdatasubrecord.h | uesp/tes5lib | 07b052983f2e26b9ba798f234ada00f83c90e9a4 | [
"MIT"
] | 1 | 2015-02-28T22:52:18.000Z | 2015-02-28T22:52:18.000Z | /*===========================================================================
*
* File: SrContdatasubrecord.H
* Author: Dave Humphrey (dave@uesp.net)
* Created On: 17 December 2011
*
* Description
*
*=========================================================================*/
#ifndef __SRCONTDATASUBRECORD_H
#define __SRCONTDATASUBRECORD_H
/*===========================================================================
*
* Begin Required Includes
*
*=========================================================================*/
#include "srsubrecord.h"
/*===========================================================================
* End of Required Includes
*=========================================================================*/
/*===========================================================================
*
* Begin Definitions
*
*=========================================================================*/
#define SR_CONTDATA_SUBRECORD_SIZE 5
/*===========================================================================
* End of Definitions
*=========================================================================*/
/*===========================================================================
*
* Begin Type Definitions
*
*=========================================================================*/
#pragma pack(push, 1)
struct srcontdata_t
{
int Type;
byte Padding;
};
#pragma pack(pop)
/*===========================================================================
* End of Type Definitions
*=========================================================================*/
/*===========================================================================
*
* Begin Class CSrContDataSubrecord Definition
*
* Description
*
*=========================================================================*/
class CSrContDataSubrecord : public CSrSubrecord {
DECLARE_SRCLASS(CSrContDataSubrecord, CSrSubrecord)
/*---------- Begin Protected Class Members --------------------*/
protected:
srcontdata_t m_Data;
/*---------- Begin Protected Class Methods --------------------*/
protected:
/* Input/output the subrecord data */
virtual bool ReadData (CSrFile& File) { if (m_RecordSize != SR_CONTDATA_SUBRECORD_SIZE) return false; return File.Read(&m_Data, SR_CONTDATA_SUBRECORD_SIZE); }
virtual bool WriteData (CSrFile& File) { if (m_RecordSize != SR_CONTDATA_SUBRECORD_SIZE) return false; return File.Write(&m_Data, SR_CONTDATA_SUBRECORD_SIZE); }
/*---------- Begin Public Class Methods -----------------------*/
public:
/* Class Constructors/Destructors */
CSrContDataSubrecord() { }
virtual void Destroy (void) { CSrSubrecord::Destroy(); }
/* Change any matching formid in the subrecord */
virtual dword ChangeFormID (const srformid_t NewID, const srformid_t OldID)
{
return (0);
}
virtual dword CountUses (const srformid_t FormID)
{
return 0;
}
/* Fixup the modindex of formids */
virtual bool FixupFormID (CSrFormidFixupArray& FixupArray)
{
return true;
}
/* Copy the content from an existing subrecord */
virtual bool Copy (CSrSubrecord* pSubrecord)
{
CSrContDataSubrecord* pSubrecord1 = SrCastClassNull(CSrContDataSubrecord, pSubrecord);
m_RecordSize = SR_CONTDATA_SUBRECORD_SIZE;
if (pSubrecord1 != NULL) {
m_Data = pSubrecord1->GetContData();
}
else {
memset(&m_Data, 0, sizeof(m_Data));
}
return (true);
}
/* Create a class instance */
static CSrSubrecord* Create (void) { return (new CSrContDataSubrecord); }
virtual CSrSubrecord* CreateV (void) { return (new CSrContDataSubrecord); }
/* Get class members */
srcontdata_t& GetContData (void) { return (m_Data); }
virtual byte* GetData (void) { return (byte *)(&m_Data); }
/* Initialize a new record */
void InitializeNew (void) { CSrSubrecord::InitializeNew(); memset(&m_Data, 0, sizeof(m_Data)); m_RecordSize = SR_CONTDATA_SUBRECORD_SIZE; }
};
/*===========================================================================
* End of Class CSrContDataSubrecord Definition
*=========================================================================*/
#endif
/*===========================================================================
* End of File SrContDataSubrecord.H
*=========================================================================*/
| 32.170213 | 163 | 0.430115 |
19772fea187669b1fa8a3fdd87bac444d4a36e8d | 116 | h | C | ClientProject/src/wav_reader.h | pqviet07/SocketAppplication | 736beab7bf711e97bd53591c0359634447feffe9 | [
"MIT"
] | null | null | null | ClientProject/src/wav_reader.h | pqviet07/SocketAppplication | 736beab7bf711e97bd53591c0359634447feffe9 | [
"MIT"
] | null | null | null | ClientProject/src/wav_reader.h | pqviet07/SocketAppplication | 736beab7bf711e97bd53591c0359634447feffe9 | [
"MIT"
] | null | null | null | #ifndef WAV_READER_H
#define WAV_READER_H
class WAV_Reader
{
public:
WAV_Reader();
};
#endif // WAV_READER_H
| 9.666667 | 22 | 0.724138 |
19c7eaefd384a7e8417ce7d481191f338311f730 | 3,614 | h | C | Plugins/SierraPlotTools/pqPlotter.h | mathstuf/ParaView | e867e280545ada10c4ed137f6a966d9d2f3db4cb | [
"Apache-2.0"
] | 17 | 2015-02-17T00:30:26.000Z | 2022-03-17T06:13:02.000Z | Plugins/SierraPlotTools/pqPlotter.h | mathstuf/ParaView | e867e280545ada10c4ed137f6a966d9d2f3db4cb | [
"Apache-2.0"
] | null | null | null | Plugins/SierraPlotTools/pqPlotter.h | mathstuf/ParaView | e867e280545ada10c4ed137f6a966d9d2f3db4cb | [
"Apache-2.0"
] | 10 | 2015-08-31T18:20:17.000Z | 2022-02-02T15:16:21.000Z |
// -*- c++ -*-
/*=========================================================================
Program: Visualization Toolkit
Module: pqPlotter.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/*-------------------------------------------------------------------------
Copyright 2009 Sandia Corporation.
Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------*/
#ifndef __pqPlotter_h
#define __pqPlotter_h
#include <QList>
#include <QMap>
#include <QObject>
#include <QStringList>
class QLabel;
class pqOutputPort;
class pqPipelineSource;
class pqServer;
class pqView;
class QAction;
class vtkPVArrayInformation;
class vtkPVDataInformation;
class vtkPVDataSetAttributesInformation;
class vtkSMProperty;
class vtkSMProxy;
//=============================================================================
class pqPlotter : public QObject
{
Q_OBJECT;
public:
enum plotDomain
{
eTime,
ePath,
eVariable
};
pqPlotter();
virtual ~pqPlotter();
virtual QStringList getTheVars(vtkSMProxy * meshReaderProxy);
virtual void setDomain(plotDomain theDomain);
virtual plotDomain getDomain();
virtual vtkSMProperty * getSMVariableProperty(vtkSMProxy * meshReaderProxy);
virtual vtkPVDataSetAttributesInformation * getDataSetAttributesInformation(vtkPVDataInformation * pvDataInfo);
virtual vtkPVArrayInformation * getArrayInformation(vtkPVDataSetAttributesInformation *);
virtual bool amIAbleToSelectByNumber();
virtual pqPipelineSource * getPlotFilter();
virtual pqPipelineSource * findPipelineSource(const char *SMName);
virtual pqServer * getActiveServer();
pqView * getPlotView(pqPipelineSource * plotFilter);
pqView * getMeshView(pqPipelineSource * meshReader);
pqView * findView(pqPipelineSource *source, int port, const QString &viewType);
virtual void setVarsStatus(vtkSMProxy * meshReaderProxy, bool flag);
virtual void setVarsActive(vtkSMProxy * meshReaderProxy, QString varName, bool activeFlag);
virtual QString getFilterName();
virtual QMap<QString, QList<pqOutputPort*> > buildNamedInputs(
pqPipelineSource * meshReader, QList<int> itemList, bool & success);
virtual QString getNumberItemsLabel();
// for plots that need some sort of selection range
virtual bool selectionWithinRange(QList<int> selectedItems, pqPipelineSource * meshReader);
void setDisplayOfVariables(pqPipelineSource * meshReader, const QMap<QString,QString> & vars);
virtual void popUpHelp();
virtual QString getPlotterHeadingHoverText();
virtual QString getPlotterTextEditObjectName();
signals:
void activateAllVariables(pqPlotter *);
protected:
virtual QStringList getStringsFromProperty(vtkSMProperty * prop);
virtual void setVarElementsStatus(vtkSMProperty * prop, bool flag);
virtual void setVarElementsActive(vtkSMProperty * prop, QString varName, bool activeFlag);
virtual vtkSMProperty * getSMNamedVariableProperty(vtkSMProxy *meshReaderProxy, QString propName);
plotDomain domain;
class pqInternal;
pqInternal * Internal;
};
#endif // __pqPlotter_h
| 28.015504 | 113 | 0.696735 |
d7a98d6ae35968ea236ad22770e2a30009d92d6d | 446 | h | C | hex/Classes/WelcomeScene.h | LMJW/cocohex | 366bc0c9f401881800da164db80c26919981c068 | [
"Apache-2.0"
] | null | null | null | hex/Classes/WelcomeScene.h | LMJW/cocohex | 366bc0c9f401881800da164db80c26919981c068 | [
"Apache-2.0"
] | 1 | 2019-03-16T01:38:38.000Z | 2019-03-16T01:38:38.000Z | hex/Classes/WelcomeScene.h | LMJW/cocohex | 366bc0c9f401881800da164db80c26919981c068 | [
"Apache-2.0"
] | null | null | null | #ifndef _WELCOME_SCENE_H_
#define _WELCOME_SCENE_H_
#include "cocos2d.h"
class WelcomeScene : public cocos2d::Layer {
public:
static cocos2d::Scene* createScene();
virtual bool init();
CREATE_FUNC(WelcomeScene);
/// Define callbacks for different menuitems
void menuItemExitCallback();
void menuItemSettingCallback();
void menuItemPlayCallback();
void menuItemAboutCallback();
};
#endif //_WELCOME_SCENE_H_
| 20.272727 | 48 | 0.733184 |
4a3390bfbbc20953c4a702925b7efc606f964064 | 1,181 | h | C | OCLex/oclex/src/OCLexGenerator.h | w3woody/OCTools | 0d0f64ae77229435c4b8451a825cffb9ba77112a | [
"Unlicense"
] | 16 | 2018-08-27T03:17:15.000Z | 2021-11-04T06:16:43.000Z | OCLex/oclex/src/OCLexGenerator.h | w3woody/OCTools | 0d0f64ae77229435c4b8451a825cffb9ba77112a | [
"Unlicense"
] | null | null | null | OCLex/oclex/src/OCLexGenerator.h | w3woody/OCTools | 0d0f64ae77229435c4b8451a825cffb9ba77112a | [
"Unlicense"
] | 2 | 2019-11-28T15:17:36.000Z | 2021-08-30T17:52:37.000Z | //
// OCLexGenerator.h
// oclex
//
// Created by William Woody on 7/30/17.
// Copyright © 2017 Glenview Software. All rights reserved.
//
#ifndef OCLexGenerator_h
#define OCLexGenerator_h
#include <stdio.h>
#include "OCLexDFA.h"
/************************************************************************/
/* */
/* Parser Definitions */
/* */
/************************************************************************/
/* OCLexGenerator
*
* Inherits from the DFA and contains the code which writes the
* resulting Objective C output file
*/
class OCLexGenerator : public OCLexDFA
{
public:
OCLexGenerator(std::map<std::string,std::string> &defn): OCLexDFA(defn)
{
}
~OCLexGenerator()
{
}
/*
* Write the Objective C file, after the DFA is generated.
*/
void WriteOCHeader(const char *className, const char *outputName, FILE *f);
void WriteOCFile(const char *className, const char *outputName, FILE *f);
private:
void WriteStarts(FILE *f);
void WriteArray(FILE *f, uint32_t *list, size_t len);
void WriteActions(FILE *f);
void WriteStates(FILE *f);
};
#endif /* OCLexGenerator_h */
| 21.87037 | 77 | 0.569856 |
7d6ce744d9e14fbb746ec029c90d56153760d89f | 11,950 | h | C | projects/RTED/CppRuntimeSystem/PointerManager.h | maurizioabba/rose | 7597292cf14da292bdb9a4ef573001b6c5b9b6c0 | [
"BSD-3-Clause"
] | 488 | 2015-01-09T08:54:48.000Z | 2022-03-30T07:15:46.000Z | projects/RTED/CppRuntimeSystem/PointerManager.h | sujankh/rose-matlab | 7435d4fa1941826c784ba97296c0ec55fa7d7c7e | [
"BSD-3-Clause"
] | 174 | 2015-01-28T18:41:32.000Z | 2022-03-31T16:51:05.000Z | projects/RTED/CppRuntimeSystem/PointerManager.h | sujankh/rose-matlab | 7435d4fa1941826c784ba97296c0ec55fa7d7c7e | [
"BSD-3-Clause"
] | 146 | 2015-04-27T02:48:34.000Z | 2022-03-04T07:32:53.000Z | #ifndef POINTERMANAGER_H_
#define POINTERMANAGER_H_
#include <map>
#include <set>
#include <vector>
#include <list>
#include <iosfwd>
#include "Util.h"
#include "TypeSystem.h"
#include "ptrops.h"
#include "ptrops_operators.h"
#include "rted_typedefs.h"
class VariablesType;
class MemoryType;
/**
* Stores infos for a dereferentiable memory region (mostly but not always a pointer)
* Example char ** b; for this case we have two PointerInfos, one for c, and one for *c.
*/
struct PointerInfo
{
typedef Address Location;
Location getSourceAddress() const { return source; }
Location getTargetAddress() const { return target; }
const RsType* getBaseType() const { return baseType; }
// \pp \todo remove
void setBaseType(const RsType& newtype){ baseType = &newtype; }
/// Checks if there is a variable registered for sourceAddress
/// if not @c NULL is returned
const VariablesType* getVariable() const;
/// Less operator uses sourceAddress (should be unique)
bool operator< (const PointerInfo& other) const;
void print(std::ostream& os) const;
PointerInfo(Location loc, Location points_to, const RsType& t)
: source(loc), target(nullAddr()), baseType(&t)
{
setTargetAddress(points_to);
}
/// Used only for creating DummyObject to search set
explicit
PointerInfo(Location s)
: source(s), target(nullAddr()), baseType(NULL)
{}
~PointerInfo();
void setTargetAddress(Location t, bool checks=false);
void setTargetAddressForce(Location t) { target = t; }
private:
Location source; ///< where pointer is stored in memory
Location target; ///< where pointer points to
const RsType* baseType; ///< the base type of the pointer i.e. type of target
};
std::ostream& operator<< (std::ostream& os, const PointerInfo& m);
/**
* Keeps track of all dereferentiable memory regions. It is expected that
* PointerManager is used indirectly via the API for RuntimeSystem.
*/
//~
//~ /// \brief represents a pointer that does not have a named memory location
//~ /// (i.e., pointers returned from functions).
//~ /// \details The memory returned from a function cannot be reclaimed
//~ /// until the next statement level (does not necessarily have to
//~ /// be the call site) is executed.
//~ /// Consider an example int* foo() { int* p = new int; return p; }
//~ /// bar(foo()); /* assuming int bar(int* p) { return *p; } */
//~ /// The body of bar may be instrumented with a transient value clean-up
//~ /// statement. This does not do any harm (except for introducing a little
//~ /// source location inaccuracy), because the memory pointed
//~ /// to by the return value is referenced by bar's p.
//~ struct TransientPointer : PointerInfo
//~ {
//~ TransientPointer();
//~
//~ TransientPointer(Location where, Location points_to, RsType& t)
//~ : PointerInfo(where, points_to, t)
//~ {}
//~
//~ TransientPointer(const TransientPointer& orig)
//~ : PointerInfo(rted_Addr(&ptr), orig.getTargetAddress(), *orig.getBaseType()), ptr(reinterpret_cast<const char*>(this))
//~ {}
//~
//~ TransientPointer& operator=(const TransientPointer& rhs)
//~ {
//~ target = rhs.target;
//~ baseType = rhs.baseType;
//~
//~ return *this;
//~ }
//~
//~ private:
//~ const char* ptr; ///< so we have an address for the pointer
//~ /// since we do not need to use it, this could be
//~ /// static in case that memory becomes a issue
//~ };
struct PointerManager
{
typedef Address Location;
typedef std::set<PointerInfo*, PointerCompare> PointerSet;
typedef PointerSet::const_iterator PointerSetIter;
typedef std::multimap<Location, PointerInfo*> TargetToPointerMap;
// \todo check if PointerInfo is sufficient ...
typedef std::pair<PointerInfo, Address> TransientPointer;
// TransientPointerList must not relocate data
typedef std::list<TransientPointer> TransientPointerList;
static const bool check = true;
static const bool nocheck = !check;
/// Registers a memory region from sourceAddress to sourceAddress+sizeof(void*)
/// which stores another address
/// second parameter specifies the type of the target
PointerSet::iterator
createDereferentiableMem(Location sourceAddress, const RsType& targetType);
/// Call this function if a class was instantiated
/// it iterates over the subtypes and if they are pointer or arrays
/// they get registered as dereferentiable mem-regions
/// @param classBaseAddr the address where the class was instantiated
/// @param type class type
void createPointer(Location classBaseAddr, const RsType* type, long blocksz);
/// Delete a registered pointer
void deletePointer(Location sourceAddress, bool checkleaks);
/// Deletes all pointer within the region defined by mt
/// @param delaychecks, true iff the leakchecks are carried out delayed
void deletePointerInRegion( const MemoryType& mt );
/// Registers that targetAddress is stored at sourceAddress, and the type of targetAddress
/// sourceAddress has to be registered first with createPointer
/// if the pointer is not found, create a new one
void registerPointerChange(Location sourceAddress, Location targetAddress, const RsType& baseType, bool checks);
#if OBSOLETE_CODE
/// Registers that targetAddress is stored at sourceAddress, and the type of targetAddress
/// sourceAddress has to be registered first with createPointer
// void registerPointerChange( Location sourceAddress, Location targetAddress, bool checkPointerMove, bool checkMemLeaks);
#endif /* OBSOLETE_CODE */
#if UNUSED_CODE
/// Behaves like registerPointerChange(sourceAddress,deref_address,true), but after the
/// function the same targetAddress is registered for the pointer,
/// Example: *(p++) call registerPointerChange()
/// *(p+1) call checkPointerDereference()
void checkPointerDereference( Location sourceAddress, Location derefed_address );
#endif /* UNUSED_CODE */
void checkIfPointerNULL( const void* pointer) const;
/// Invalidates all "Pointer" i.e. dereferentiable memory regions
/// point in memory chunk defined by mt
void invalidatePointerToRegion( const MemoryType& mt );
/// Use this to get pointerInfos which have sourceAddr in a specific region
/// to iterate over region a1 until a2 (where a2 is exclusive!) use
/// for(PointerSetIter i = sourceRegionIter(a1); i!= sourceRegionIter(a2); ++i)
/// PointerInfo * info = *i;
PointerSetIter sourceRegionIter(Location sourceAddr) const;
/// Use this to get pointerInfos which have targetAddr in a specific region
/// to iterate over region a1 until a2 (where a2 is exclusive!) use
/// for(TargetToPointerMapIter i = targetRegionIterBegin(a1); i!= targetRegionIterEnd(a2); ++i)
/// PointerInfo * info = i->second; (i->first is the targetAddr)
TargetToPointerMap::const_iterator targetRegionIterBegin(Location targetAddr) const
{
return targetToPointerMap.lower_bound(targetAddr);
}
/// \overload
TargetToPointerMap::iterator targetRegionIterBegin(Location targetAddr)
{
return targetToPointerMap.lower_bound(targetAddr);
}
TargetToPointerMap::const_iterator targetRegionIterEnd(Location targetAddr) const
{
return targetToPointerMap.upper_bound(targetAddr);
}
TargetToPointerMap::iterator targetRegionIterEnd(Location targetAddr)
{
return targetToPointerMap.upper_bound(targetAddr);
}
TargetToPointerMap::const_iterator targetBegin() const
{
return targetToPointerMap.begin();
}
TargetToPointerMap::const_iterator targetEnd() const
{
return targetToPointerMap.end();
}
size_t targetSize() const
{
return targetToPointerMap.size();
}
const PointerSet& getPointerSet() const { return pointerInfoSet; }
/// Print status to a stream
void print(std::ostream& os) const;
/// Print pointers pointing into @mt on the stream @os
void printPointersToThisChunk(std::ostream& os, const MemoryType& mt) const;
/// clears status for debugging purposes
void clearStatus();
#if OBSOLETE_CODE
/// checks whether a pointer to heap memory exists
void leakCheckDelayed();
/// stores scope info for delayed checks
void delayedScopeExit(const SourceInfo& si);
#endif /* OBSOLETE_CODE */
/// \brief stores the pointer info for the transient pointer
void createTransientPointer(Location points_to, const RsType& t);
/// \brief removes all transient pointers from the list
/// and checks for remaining memory leaks
/// \details this function can only be called AFTER the transient pointer
/// was assigned to another pointer (or we can assume that the
/// memory reference vanished).
void clearTransientPtr();
/// \brief returns the number of transient pointers
size_t transientPtrSize() { return transientPointers.size(); }
/// \brief checks 0 or 1 transient pointers for deallocated memory
bool checkTransientPtr();
/// \brief Checks to see if some pointer is still pointing to target
/// \param target
/// \param len size of memory chunk
/// \param culprit if not NULL, @culprit will be reported as the last pointer
/// to that memory chunk.
/// \details Note that this will give false positives for
/// memory chunks, pointers to which are "computable", e.g. if the user
/// stores some fixed offset to its address. Avoiding such false
/// positives will require data flow analysis on our part.
void checkForMemoryLeaks( Location target, size_t len, const PointerInfo* culprit = 0 ) const;
protected:
/// Removes the a PointerInfo from targetToPointerMap
/// @return false if not found in map
bool removeFromRevMap(PointerInfo * p);
#if OBSOLETE_CODE
/// Checks to see if pointer_being_removed was the last pointer pointing
/// to some memory chunk.
void checkForMemoryLeaks( const PointerInfo& pi ) const
{
checkForMemoryLeaks( pi.getTargetAddress(), pi );
}
#endif /* OBSOLETE_CODE */
/// Checks to see if any pointer exists that points to address, and
/// whose base type is of size type_size. If not, a violation is
/// raised. @pi is reported as the source of the memory
/// leak.
void checkForMemoryLeaks(Location address, const PointerInfo& pi) const
{
checkForMemoryLeaks(address, pi.getBaseType()->getByteSize(), &pi);
}
PointerSet pointerInfoSet; ///< contains all pointers (aka dereferential memory)
TargetToPointerMap targetToPointerMap; ///< Map to get all pointer which point to a specific target address
/// maps targetAddress -> Set of PointerInfos
TransientPointerList transientPointers;
};
#endif
| 40.508475 | 130 | 0.642176 |
621abbbd3c03d198c60243ab289ea5963ee5e183 | 3,126 | c | C | apps/prime.c | vigortls/vigortls | 96d5ef366291a7a5976bda43025b054021dbf1bf | [
"OpenSSL",
"0BSD"
] | 3 | 2017-02-21T06:57:01.000Z | 2018-11-21T09:57:43.000Z | apps/prime.c | vigortls/vigortls | 96d5ef366291a7a5976bda43025b054021dbf1bf | [
"OpenSSL",
"0BSD"
] | null | null | null | apps/prime.c | vigortls/vigortls | 96d5ef366291a7a5976bda43025b054021dbf1bf | [
"OpenSSL",
"0BSD"
] | 1 | 2018-05-22T02:28:43.000Z | 2018-05-22T02:28:43.000Z | /*
* Copyright 2004-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <limits.h>
#include <string.h>
#include <openssl/bn.h>
#include <stdcompat.h>
#include "apps.h"
int prime_main(int argc, char **argv)
{
int hex = 0;
int checks = 20;
int generate = 0;
int bits = 0;
int safe = 0;
const char *stnerr = NULL;
BIGNUM *bn = NULL;
BIO *bio_out;
if (bio_err == NULL)
if ((bio_err = BIO_new(BIO_s_file())) != NULL)
BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT);
--argc;
++argv;
while (argc >= 1 && **argv == '-') {
if (!strcmp(*argv, "-hex"))
hex = 1;
else if (!strcmp(*argv, "-generate"))
generate = 1;
else if (!strcmp(*argv, "-bits")) {
if (--argc < 1)
goto bad;
else
bits = strtonum(*(++argv), 0, INT_MAX, &stnerr);
if (stnerr)
goto bad;
} else if (!strcmp(*argv, "-safe"))
safe = 1;
else if (!strcmp(*argv, "-checks")) {
if (--argc < 1)
goto bad;
else
checks = strtonum(*(++argv), 0, INT_MAX, &stnerr);
if (stnerr)
goto bad;
} else {
BIO_printf(bio_err, "Unknown option '%s'\n", *argv);
goto bad;
}
--argc;
++argv;
}
if (argv[0] == NULL && !generate) {
BIO_printf(bio_err, "No prime specified\n");
goto bad;
}
if ((bio_out = BIO_new(BIO_s_file())) != NULL) {
BIO_set_fp(bio_out, stdout, BIO_NOCLOSE);
}
if (generate) {
char *s;
if (!bits) {
BIO_printf(bio_err, "Specify the number of bits.\n");
return 1;
}
bn = BN_new();
BN_generate_prime_ex(bn, bits, safe, NULL, NULL, NULL);
s = hex ? BN_bn2hex(bn) : BN_bn2dec(bn);
BIO_printf(bio_out, "%s\n", s);
free(s);
} else {
if (hex) {
if (!BN_hex2bn(&bn, argv[0])) {
BIO_printf(bio_err, "BN_hex2bn() failed\n");
goto bad;
}
} else {
if (!BN_dec2bn(&bn, argv[0])) {
BIO_printf(bio_err, "BN_dec2bn() failed\n");
goto bad;
}
}
BN_print(bio_out, bn);
BIO_printf(bio_out, " is %sprime\n",
BN_is_prime_ex(bn, checks, NULL, NULL) ? "" : "not ");
}
BIO_free_all(bio_out);
return 0;
bad:
BN_free(bn);
if (stnerr)
BIO_printf(bio_err, "invalid argument %s, errmsg=%s\n", *argv, stnerr);
else {
BIO_printf(bio_err, "options are\n");
BIO_printf(bio_err, "%-14s hex\n", "-hex");
BIO_printf(bio_err, "%-14s number of checks\n", "-checks <n>");
}
return 1;
}
| 26.491525 | 79 | 0.495521 |
4abab3b10c5f94537acf0ae511db5173cce06264 | 1,981 | h | C | SCTK/src/asclite/core/properties.h | IIP-Sogang/Audio-Visual-Speech-Recognition | bd03be91135acbc6162b83092d462b7fe71dd007 | [
"MIT"
] | 113 | 2018-11-20T06:00:39.000Z | 2022-03-29T06:01:55.000Z | SCTK/src/asclite/core/properties.h | IIP-Sogang/Audio-Visual-Speech-Recognition | bd03be91135acbc6162b83092d462b7fe71dd007 | [
"MIT"
] | 28 | 2017-09-11T16:20:26.000Z | 2022-02-13T14:16:33.000Z | SCTK/src/asclite/core/properties.h | IIP-Sogang/Audio-Visual-Speech-Recognition | bd03be91135acbc6162b83092d462b7fe71dd007 | [
"MIT"
] | 47 | 2015-01-27T06:22:57.000Z | 2021-11-11T20:59:04.000Z | /*
* ASCLITE
* Author: Jerome Ajot, Jon Fiscus, Nicolas Radde, Chris Laprun
*
* This software was developed at the National Institute of Standards and Technology by
* employees of the Federal Government in the course of their official duties. Pursuant
* to title 17 Section 105 of the United States Code this software is not subject to
* copyright protection and is in the public domain. ASCLITE is an experimental system.
* NIST assumes no responsibility whatsoever for its use by other parties, and makes no
* guarantees, expressed or implied, about its quality, reliability, or any other
* characteristic. We would appreciate acknowledgement if the software is used.
*
* THIS SOFTWARE IS PROVIDED "AS IS." With regard to this software, NIST MAKES NO EXPRESS
* OR IMPLIED WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING MERCHANTABILITY,
* OR FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef PROPERTIES_H
#define PROPERTIES_H
#include "stdinc.h"
/**
* Contain the global properties of the aligner.
* This object in created once and for all during the argument parsing.
*/
class Properties
{
public:
/** Determines if the properties were updated since the last call to GetProperty. */
static bool IsDirty() { return dirty; }
/**
* Set the property to the desired value
*/
static void SetProperty(const string& name, const string& value);
/**
* Retrieve the value of the specified property
*/
static string GetProperty(const string& name);
/**
* Set the properties with a all set of predefined values
*/
static void SetProperties(const map<string, string> & props);
/**
* Initialize the properties.
* Nothing to do for now there...
*/
static void Initialize();
private:
/**
* Internal representation of the properties
*/
static map<string, string> properties;
static bool dirty;
};
#endif // PROPERTIES_H
| 34.155172 | 90 | 0.695103 |
433f353f29f926afd52f798df8fc07f1c655b700 | 3,389 | h | C | mst/mscope_guard.h | MartijnTerpstra/mst | c2cc5daa787b668ddb6b0740cda96277c98a777c | [
"MIT"
] | 1 | 2021-01-27T06:34:01.000Z | 2021-01-27T06:34:01.000Z | mst/mscope_guard.h | MartijnTerpstra/mst | c2cc5daa787b668ddb6b0740cda96277c98a777c | [
"MIT"
] | 46 | 2020-11-05T23:41:37.000Z | 2021-11-12T12:22:11.000Z | mst/mscope_guard.h | MartijnTerpstra/mst | c2cc5daa787b668ddb6b0740cda96277c98a777c | [
"MIT"
] | null | null | null | //////////////////////////////////////////////////////////////////////////////////////////////
// //
// MST Utility Library //
// Copyright (c)2021 Martinus Terpstra //
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy //
// of this software and associated documentation files (the "Software"), to deal //
// in the Software without restriction, including without limitation the rights //
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell //
// copies of the Software, and to permit persons to whom the Software is //
// furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE //
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, //
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN //
// THE SOFTWARE. //
// //
//////////////////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <mcore.h>
#include <mcommon.h>
namespace mst {
namespace _Details {
template<typename _Fun>
class _scope_guard
{
public:
inline _scope_guard(_Fun _Func)
: _MyFunc(std::move(_Func))
, _Dismissed(false)
{ }
inline ~_scope_guard()
{
if(!_Dismissed)
{
_MyFunc();
}
}
inline bool is_dismissed()
{
return _Dismissed;
}
inline void dismiss()
{
_Dismissed = true;
}
private:
_Fun _MyFunc;
bool _Dismissed;
}; // class _scope_guard
class _on_exit_scope_guard
{
public:
template<typename _Fun>
inline friend _scope_guard<_Fun> operator+(_on_exit_scope_guard left, _Fun _Func)
{
return _scope_guard<_Fun>(std::move(_Func));
}
}; // class _on_exit_scope_guard
}; // namespace _Details
template<typename _Fun>
::mst::_Details::_scope_guard<_Fun> scope_guard(_Fun _Func)
{
return ::mst::_Details::_scope_guard<_Fun>(std::move(_Func));
}
#define mst_on_exit_scope \
auto _MST_ANONYMOUS_VAR(__ONEXITSTATE) = ::mst::_Details::_on_exit_scope_guard() + [&]()
}; // namespace mst
| 37.241758 | 100 | 0.474476 |
9e599b4f77602008fa6734815804bae4e65b5bd5 | 5,046 | c | C | src/menu.c | civts/emb2020 | 54d3f38782004ef9ee431e5b16410ff007b3f164 | [
"MIT"
] | null | null | null | src/menu.c | civts/emb2020 | 54d3f38782004ef9ee431e5b16410ff007b3f164 | [
"MIT"
] | null | null | null | src/menu.c | civts/emb2020 | 54d3f38782004ef9ee431e5b16410ff007b3f164 | [
"MIT"
] | null | null | null | #include "gameState.h"
#include "menu.h"
#include <stdio.h>
#include "hw_dependent/display.h"
#include "hw_dependent/joystick.h"
#include "hw_dependent/light_sensor.h"
//Vertical offset for the options
const int optionsOffset = 60;
const char *const options[] = {"Game 1", "Snake"};
const int optionsLength = 2;
void showMenu()
{
clearDisplay();
int currentlySelected = 0;
int stepBetweenOptions = getFontHeight() * 2;
int previouslySelected = currentlySelected;
gameState.buttonClicked = false;
bool previouslyDark = false;
Graphics_Rectangle previousRect;
previousRect.xMin = 0;
previousRect.xMax = 0;
previousRect.yMin = 0;
previousRect.yMax = 0;
while ((!gameState.buttonClicked) || currentlySelected >= optionsLength)
{
readJoystickPosition();
adjustBrightness(&previouslyDark);
if (gameState.joystickY < J_DOWN_TRESH)
{
currentlySelected = min(currentlySelected + 1, optionsLength);
gameState.joystickY = J_DOWN_TRESH + 1;
int i;
for (i = 0; i < 400000; i++)
;
}
else if (gameState.joystickY > J_UP_TRESH)
{
currentlySelected = max(currentlySelected - 1, 0);
gameState.joystickY = J_UP_TRESH - 1;
int i;
for (i = 0; i < 400000; i++)
;
}
_drawTitle();
if (previouslySelected != currentlySelected)
{
_cleanRectangle(&previousRect);
previouslySelected = currentlySelected;
}
previousRect = _drawSelectionRectangle(currentlySelected, stepBetweenOptions);
_drawOptions(stepBetweenOptions);
_drawLightDarkSwitch();
if (gameState.buttonClicked)
{
if (currentlySelected == optionsLength)
{
gameState.brightness++;
gameState.brightness %= 3;
gameState.buttonClicked = false;
}
}
}
gameState.buttonClicked = false;
gameState.selectedGame = currentlySelected;
}
void _drawTitle()
{
uint32_t previousColor = getForegroundColor();
setForegroundColor(GRAPHICS_COLOR_GREEN);
int width = DISPLAY_WIDTH;
const Graphics_Font *previousFont = getFont();
setFont(titleFont);
drawStringCentered(
"MSP Games",
width / 2,
22,
false);
setFont(previousFont);
setForegroundColorTranslated(previousColor);
}
void _drawOptions(int step)
{
int halfWidth = DISPLAY_WIDTH / 2;
int yOffset = optionsOffset;
int i;
for (i = 0; i < optionsLength; i++)
{
drawStringCentered(
options[i],
halfWidth,
yOffset,
false);
yOffset += step;
}
}
Graphics_Rectangle _drawSelectionRectangle(const int selected, const int step)
{
const int pad = 20;
Graphics_Rectangle rectangle;
rectangle.xMin = pad;
rectangle.xMax = DISPLAY_WIDTH - pad;
rectangle.yMin = optionsOffset + selected * step - step / 2;
rectangle.yMax = optionsOffset + selected * step + step / 2;
if (selected == optionsLength)
{
rectangle.xMin = DISPLAY_WIDTH - 20;
rectangle.xMax = DISPLAY_WIDTH - 1;
rectangle.yMin = DISPLAY_HEIGHT - 15;
rectangle.yMax = DISPLAY_HEIGHT - 2;
}
drawRectangle(&rectangle);
return rectangle;
}
void _cleanRectangle(const Graphics_Rectangle *rect)
{
uint32_t fgColor = getForegroundColor();
setForegroundColorTranslated(getBackgroundColor());
drawRectangle(rect);
setForegroundColorTranslated(fgColor);
}
void _drawLightDarkSwitch()
{
char str[2];
str[1] = '\0';
switch (gameState.brightness)
{
case LIGHT:
str[0] = 'L';
break;
case DARK:
str[0] = 'D';
break;
case AUTO:
str[0] = 'A';
break;
}
drawString(
str,
DISPLAY_WIDTH - 12,
DISPLAY_HEIGHT - getFontHeight() - 3,
true);
}
void adjustBrightness(bool *previouslyDark)
{
bool useDark = previouslyDark;
switch (gameState.brightness)
{
case AUTO:
{ //Get luminosity
unsigned long int lux = getLux();
if (lux > 20)
{
useDark = false;
}
else if (lux < 10)
{
useDark = true;
}
break;
}
case DARK:
{
useDark = true;
break;
}
case LIGHT:
{
useDark = false;
}
}
if (useDark)
{
if (!(*previouslyDark))
{
setBackgroundColor(0x00232323);
setForegroundColor(GRAPHICS_COLOR_ANTIQUE_WHITE);
*previouslyDark = true;
clearDisplay();
}
}
else
{
if (*previouslyDark)
{
setBackgroundColor(GRAPHICS_COLOR_WHITE);
setForegroundColor(GRAPHICS_COLOR_BLACK);
*previouslyDark = false;
clearDisplay();
}
}
}
| 23.690141 | 86 | 0.581649 |
9ebc33211e9204ad14448c8130c478e42bfa7f5f | 7,706 | c | C | libraries/freertos_plus/standard/freertos_plus_posix/source/FreeRTOS_POSIX_clock.c | LibreWireless/amazon-freertos-uno | 2ddb5c0ac906e4ab5340062641776f44e0f1d67d | [
"MIT"
] | 1 | 2020-05-09T03:38:29.000Z | 2020-05-09T03:38:29.000Z | libraries/freertos_plus/standard/freertos_plus_posix/source/FreeRTOS_POSIX_clock.c | LibreWireless/amazon-freertos-uno | 2ddb5c0ac906e4ab5340062641776f44e0f1d67d | [
"MIT"
] | null | null | null | libraries/freertos_plus/standard/freertos_plus_posix/source/FreeRTOS_POSIX_clock.c | LibreWireless/amazon-freertos-uno | 2ddb5c0ac906e4ab5340062641776f44e0f1d67d | [
"MIT"
] | null | null | null | /*
* FreeRTOS POSIX V1.1.3
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/**
* @file FreeRTOS_POSIX_clock.c
* @brief Implementation of clock functions in time.h
*/
/* C standard library includes. */
#include <stddef.h>
#include <string.h>
/* FreeRTOS+POSIX includes. */
#include "FreeRTOS_POSIX.h"
#include "FreeRTOS_POSIX/errno.h"
#include "FreeRTOS_POSIX/time.h"
#include "FreeRTOS_POSIX/utils.h"
/* Declaration of snprintf. The header stdio.h is not included because it
* includes conflicting symbols on some platforms. */
extern int snprintf( char * s,
size_t n,
const char * format,
... );
/*-----------------------------------------------------------*/
clock_t clock( void )
{
/* This function is currently unsupported. It will always return -1. */
return ( clock_t ) -1;
}
/*-----------------------------------------------------------*/
int clock_getcpuclockid( pid_t pid,
clockid_t * clock_id )
{
/* Silence warnings about unused parameters. */
( void ) pid;
( void ) clock_id;
/* This function is currently unsupported. It will always return EPERM. */
return EPERM;
}
/*-----------------------------------------------------------*/
int clock_getres( clockid_t clock_id,
struct timespec * res )
{
/* Silence warnings about unused parameters. */
( void ) clock_id;
/* Convert FreeRTOS tick resolution as timespec. */
if( res != NULL )
{
res->tv_sec = 0;
res->tv_nsec = NANOSECONDS_PER_TICK;
}
return 0;
}
/*-----------------------------------------------------------*/
int clock_gettime( clockid_t clock_id,
struct timespec * tp )
{
TimeOut_t xCurrentTime = { 0 };
/* Intermediate variable used to convert TimeOut_t to struct timespec.
* Also used to detect overflow issues. It must be unsigned because the
* behavior of signed integer overflow is undefined. */
uint64_t ullTickCount = 0ULL;
/* Silence warnings about unused parameters. */
( void ) clock_id;
/* Get the current tick count and overflow count. vTaskSetTimeOutState()
* is used to get these values because they are both static in tasks.c. */
vTaskSetTimeOutState( &xCurrentTime );
/* Adjust the tick count for the number of times a TickType_t has overflowed.
* portMAX_DELAY should be the maximum value of a TickType_t. */
ullTickCount = ( uint64_t ) ( xCurrentTime.xOverflowCount ) << ( sizeof( TickType_t ) * 8 );
/* Add the current tick count. */
ullTickCount += xCurrentTime.xTimeOnEntering;
/* Convert ullTickCount to timespec. */
UTILS_NanosecondsToTimespec( ( int64_t ) ullTickCount * NANOSECONDS_PER_TICK, tp );
return 0;
}
/*-----------------------------------------------------------*/
int clock_nanosleep( clockid_t clock_id,
int flags,
const struct timespec * rqtp,
struct timespec * rmtp )
{
int iStatus = 0;
TickType_t xSleepTime = 0;
struct timespec xCurrentTime = { 0 };
/* Silence warnings about unused parameters. */
( void ) clock_id;
( void ) rmtp;
( void ) flags; /* This is only ignored if INCLUDE_vTaskDelayUntil is 0. */
/* Check rqtp. */
if( UTILS_ValidateTimespec( rqtp ) == false )
{
iStatus = EINVAL;
}
/* Get current time */
if( ( iStatus == 0 ) && ( clock_gettime( CLOCK_REALTIME, &xCurrentTime ) != 0 ) )
{
iStatus = EINVAL;
}
if( iStatus == 0 )
{
/* Check for absolute time sleep. */
if( ( flags & TIMER_ABSTIME ) == TIMER_ABSTIME )
{
/* Get current time */
if( clock_gettime( CLOCK_REALTIME, &xCurrentTime ) != 0 )
{
iStatus = EINVAL;
}
/* Get number of ticks until absolute time. */
if( ( iStatus == 0 ) && ( UTILS_AbsoluteTimespecToDeltaTicks( rqtp, &xCurrentTime, &xSleepTime ) == 0 ) )
{
/* Delay until absolute time if vTaskDelayUntil is available. */
#if ( INCLUDE_vTaskDelayUntil == 1 )
/* Get the current tick count. This variable isn't declared
* at the top of the function because it's only used and needed
* if vTaskDelayUntil is available. */
TickType_t xCurrentTicks = xTaskGetTickCount();
/* Delay until absolute time. */
vTaskDelayUntil( &xCurrentTicks, xSleepTime );
#else
/* If vTaskDelayUntil isn't available, ignore the TIMER_ABSTIME flag
* and sleep for a relative time. */
vTaskDelay( xSleepTime );
#endif
}
}
else
{
/* If TIMER_ABSTIME isn't specified, convert rqtp to ticks and
* sleep for a relative time. */
if( UTILS_TimespecToTicks( rqtp, &xSleepTime ) == 0 )
{
vTaskDelay( xSleepTime );
}
}
}
return iStatus;
}
/*-----------------------------------------------------------*/
int clock_settime( clockid_t clock_id,
const struct timespec * tp )
{
/* Silence warnings about unused parameters. */
( void ) clock_id;
( void ) tp;
/* This function is currently unsupported. It will always return -1 and
* set errno to EPERM. */
errno = EPERM;
return -1;
}
/*-----------------------------------------------------------*/
int nanosleep( const struct timespec * rqtp,
struct timespec * rmtp )
{
int iStatus = 0;
TickType_t xSleepTime = 0;
/* Silence warnings about unused parameters. */
( void ) rmtp;
/* Check rqtp. */
if( UTILS_ValidateTimespec( rqtp ) == false )
{
errno = EINVAL;
iStatus = -1;
}
if( iStatus == 0 )
{
/* Convert rqtp to ticks and delay. */
if( UTILS_TimespecToTicks( rqtp, &xSleepTime ) == 0 )
{
vTaskDelay( xSleepTime );
}
}
return iStatus;
}
/*-----------------------------------------------------------*/
| 31.975104 | 118 | 0.548274 |
9ae87c6c166d2562a53ac4e2aa2de4ec26a47ba8 | 341 | h | C | core/src/chr/cross/Context.h | arielm/chronotext-cross | e3fafbd4b688797c3dfa39b1d7b2cfecb90c2297 | [
"MIT"
] | 23 | 2015-07-18T14:07:08.000Z | 2022-01-03T10:31:56.000Z | core/src/chr/cross/Context.h | arielm/chronotext-cross | e3fafbd4b688797c3dfa39b1d7b2cfecb90c2297 | [
"MIT"
] | null | null | null | core/src/chr/cross/Context.h | arielm/chronotext-cross | e3fafbd4b688797c3dfa39b1d7b2cfecb90c2297 | [
"MIT"
] | 6 | 2015-09-17T17:56:47.000Z | 2018-10-31T13:54:13.000Z | #pragma once
#include "chr/cross/CrossDelegate.h"
#include "chr/system/SystemManager.h"
namespace chr
{
CrossSketch* createSketch();
// ---
extern CrossDelegate& delegate();
extern SystemManager& systemManager();
template <class T>
inline T& checkedReference(T *instance)
{
assert(instance);
return *instance;
}
}
| 15.5 | 41 | 0.695015 |
b13f8488ac8540df3764e0882f3d3944b8294cd5 | 1,043 | h | C | arch/x86/include/asm/page_32.h | jainsakshi2395/linux | 7ccb860232bb83fb60cd6bcf5aaf0c008d903acb | [
"Linux-OpenIB"
] | null | null | null | arch/x86/include/asm/page_32.h | jainsakshi2395/linux | 7ccb860232bb83fb60cd6bcf5aaf0c008d903acb | [
"Linux-OpenIB"
] | null | null | null | arch/x86/include/asm/page_32.h | jainsakshi2395/linux | 7ccb860232bb83fb60cd6bcf5aaf0c008d903acb | [
"Linux-OpenIB"
] | null | null | null | /* SPDX-License-Identifier: GPL-2.0 */
#ifndef _ASM_X86_PAGE_32_H
#define _ASM_X86_PAGE_32_H
#include <asm/page_32_types.h>
#ifndef __ASSEMBLY__
#define __phys_addr_nodebug(x) ((x) - PAGE_OFFSET)
#ifdef CONFIG_DEBUG_VIRTUAL
extern unsigned long __phys_addr(unsigned long);
#else
#define __phys_addr(x) __phys_addr_nodebug(x)
#endif
#define __phys_addr_symbol(x) __phys_addr(x)
#define __phys_reloc_hide(x) RELOC_HIDE((x), 0)
#ifdef CONFIG_FLATMEM
#define pfn_valid(pfn) ((pfn) < max_mapnr)
#endif /* CONFIG_FLATMEM */
#ifdef CONFIG_X86_USE_3DNOW
#include <asm/mmx.h>
static inline void clear_page(void *page)
{
mmx_clear_page(page);
}
static inline void copy_page(void *to, void *from)
{
mmx_copy_page(to, from);
}
#else /* !CONFIG_X86_USE_3DNOW */
#include <linux/string.h>
static inline void clear_page(void *page)
{
memset(page, 0, PAGE_SIZE);
}
static inline void copy_page(void *to, void *from)
{
memcpy(to, from, PAGE_SIZE);
}
#endif /* CONFIG_X86_USE_3DNOW */
#endif /* !__ASSEMBLY__ */
#endif /* _ASM_X86_PAGE_32_H */
| 20.86 | 50 | 0.746884 |
7f4228d72bc314c6c450f2f5bde72c159d5da022 | 2,644 | h | C | src/media/playback/mediaplayer/graph/nodes/input.h | opensource-assist/fuschia | 66646c55b3d0b36aae90a4b6706b87f1a6261935 | [
"BSD-3-Clause"
] | 3 | 2020-08-02T04:46:18.000Z | 2020-08-07T10:10:53.000Z | src/media/playback/mediaplayer/graph/nodes/input.h | opensource-assist/fuschia | 66646c55b3d0b36aae90a4b6706b87f1a6261935 | [
"BSD-3-Clause"
] | null | null | null | src/media/playback/mediaplayer/graph/nodes/input.h | opensource-assist/fuschia | 66646c55b3d0b36aae90a4b6706b87f1a6261935 | [
"BSD-3-Clause"
] | 1 | 2020-08-07T10:11:49.000Z | 2020-08-07T10:11:49.000Z | // Copyright 2016 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SRC_MEDIA_PLAYBACK_MEDIAPLAYER_GRAPH_NODES_INPUT_H_
#define SRC_MEDIA_PLAYBACK_MEDIAPLAYER_GRAPH_NODES_INPUT_H_
#include <atomic>
#include "src/media/playback/mediaplayer/graph/packet.h"
#include "src/media/playback/mediaplayer/graph/payloads/payload_manager.h"
namespace media_player {
class Node;
class Output;
// Represents a node's connector to an adjacent upstream node.
class Input {
public:
Input(Node* node, size_t index);
Input(Input&& input);
~Input();
// The node of which this input is a part.
Node* node() const { return node_; }
// The index of this input with respect to the node.
size_t index() const { return index_; }
// The output to which this input is connected.
Output* mate() const { return mate_; }
// Establishes a connection.
void Connect(Output* output);
// Breaks a connection. Called only by the engine.
void Disconnect() {
mate_ = nullptr;
payload_manager_.OnDisconnect();
}
// Determines whether the input is connected to an output.
bool connected() const { return mate_; }
// Indicates current need for a packet. Called only by the upstream |Output|.
bool needs_packet() const;
// Updates packet. Called only by the upstream |Output|.
void PutPacket(PacketPtr packet);
// A packet supplied from upstream.
const PacketPtr& packet() const { return packet_; }
// Takes ownership of the packet supplied from upstream and requests another
// if |request_another| is true.
PacketPtr TakePacket(bool request_another);
// Requests a packet if |packet()| is empty. Called only by the downstream
// node.
void RequestPacket();
// Flushes retained media.
void Flush();
// Returns a reference to the payload configuration.
PayloadConfig& payload_config() { return payload_config_; }
const PayloadConfig& payload_config() const { return payload_config_; }
// Returns a reference to the buffer manager for this input.
PayloadManager& payload_manager() { return payload_manager_; }
const PayloadManager& payload_manager() const { return payload_manager_; }
private:
enum class State { kNeedsPacket, kRefusesPacket, kHasPacket };
void RegisterConnectionReadyCallbacks();
Node* node_;
size_t index_;
Output* mate_ = nullptr;
PacketPtr packet_;
std::atomic<State> state_;
PayloadConfig payload_config_;
PayloadManager payload_manager_;
};
} // namespace media_player
#endif // SRC_MEDIA_PLAYBACK_MEDIAPLAYER_GRAPH_NODES_INPUT_H_
| 28.430108 | 79 | 0.740923 |
2c5fe9b7b80a9b454c3d06dc6f34d9500492b32b | 18,647 | c | C | Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/Library/Private/PeiDxeSmmScSmbusCommonLib/ScSmbusExec.c | bcran/edk2-platforms | 7c914946bd014dc1f3cf0a0ef189e7c2d33d382f | [
"BSD-2-Clause"
] | null | null | null | Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/Library/Private/PeiDxeSmmScSmbusCommonLib/ScSmbusExec.c | bcran/edk2-platforms | 7c914946bd014dc1f3cf0a0ef189e7c2d33d382f | [
"BSD-2-Clause"
] | null | null | null | Silicon/BroxtonSoC/BroxtonSiPkg/SouthCluster/Library/Private/PeiDxeSmmScSmbusCommonLib/ScSmbusExec.c | bcran/edk2-platforms | 7c914946bd014dc1f3cf0a0ef189e7c2d33d382f | [
"BSD-2-Clause"
] | null | null | null | /** @file
Apollo Lake South Cluster Smbus Executive Code (common PEI/DXE/SMM code).
Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Uefi/UefiBaseType.h>
#include <Library/IoLib.h>
#include <Library/DebugLib.h>
#include <Library/TimerLib.h>
#include <IndustryStandard/SmBus.h>
#include <IndustryStandard/Pci30.h>
#include <ScAccess.h>
#include <Library/MmPciLib.h>
#include <Private/Library/ScSmbusCommonLib.h>
/**
Get SMBUS IO Base address.
@param[in] None
@retval UINT32 The SMBUS IO Base Address
**/
UINT32
SmbusGetIoBase (
VOID
)
{
UINT32 SmbusIoBase;
SmbusIoBase = MmioRead32 (
MmPciBase (
DEFAULT_PCI_BUS_NUMBER_SC,
PCI_DEVICE_NUMBER_SMBUS,
PCI_FUNCTION_NUMBER_SMBUS)
+ R_SMBUS_BASE) & B_SMBUS_BASE_BAR;
ASSERT (SmbusIoBase != B_SMBUS_BASE_BAR && SmbusIoBase != 0);
return SmbusIoBase;
}
/**
This function provides a standard way to read PCH Smbus IO registers.
@param[in] Offset Register offset from Smbus base IO address.
@retval UINT8 Returns data read from IO.
**/
UINT8
EFIAPI
SmbusIoRead (
IN UINT8 Offset
)
{
return IoRead8 (SmbusGetIoBase () + Offset);
}
/**
This function provides a standard way to write PCH Smbus IO registers.
@param[in] Offset Register offset from Smbus base IO address.
@param[in] Data Data to write to register.
**/
VOID
EFIAPI
SmbusIoWrite (
IN UINT8 Offset,
IN UINT8 Data
)
{
IoWrite8 (SmbusGetIoBase () + Offset, Data);
return;
}
/**
This function provides a standard way to check if a SMBus transaction has
completed.
@param[in] StsReg Not used for input. On return, contains the
value of the SMBus status register.
@retval TRUE Transaction is complete
@retval FALSE Otherwise.
**/
BOOLEAN
EFIAPI
IoDone (
IN UINT8 *StsReg
)
{
UINTN StallIndex;
UINTN StallTries;
StallTries = STALL_TIME / STALL_PERIOD;
for (StallIndex = 0; StallIndex < StallTries; StallIndex++) {
*StsReg = SmbusIoRead (R_SMBUS_HSTS);
if (*StsReg & (B_SMBUS_INTR | B_SMBUS_BYTE_DONE_STS | B_SMBUS_DERR | B_SMBUS_BERR)) {
return TRUE;
} else {
MicroSecondDelay (STALL_PERIOD);
}
}
return FALSE;
}
/**
Check if it's ok to use the bus.
@retval EFI_SUCCESS SmBus is acquired and it's safe to send commands.
@retval EFI_TIMEOUT SmBus is busy, it's not safe to send commands.
**/
EFI_STATUS
AcquireBus (
VOID
)
{
UINT8 StsReg;
StsReg = 0;
StsReg = SmbusIoRead (R_SMBUS_HSTS);
if (StsReg & B_SMBUS_IUS) {
return EFI_TIMEOUT;
} else if (StsReg & B_SMBUS_HBSY) {
///
/// Clear Status Register and exit
///
SmbusIoWrite (R_SMBUS_HSTS, B_SMBUS_HSTS_ALL);
return EFI_TIMEOUT;
} else {
///
/// Clear out any odd status information (Will Not Clear In Use)
///
SmbusIoWrite (R_SMBUS_HSTS, StsReg);
return EFI_SUCCESS;
}
}
/**
This function provides a standard way to execute Smbus protocols
as defined in the SMBus Specification. The data can either be of
the Length byte, word, or a block of data. The resulting transaction will be
either the SMBus Slave Device accepts this transaction or this function
returns with an error
@param[in] SlaveAddress Smbus Slave device the command is directed at
@param[in] Command Slave Device dependent
@param[in] Operation Which SMBus protocol will be used
@param[in] PecCheck Defines if Packet Error Code Checking is to be used
@param[in, out] Length How many bytes to read. Must be 0 <= Length <= 32 depending on Operation
It will contain the actual number of bytes read/written.
@param[in, out] Buffer Contain the data read/written.
@retval EFI_SUCCESS The operation completed successfully.
@exception EFI_UNSUPPORTED The operation is unsupported.
@retval EFI_INVALID_PARAMETER Length or Buffer is NULL for any operation besides
quick read or quick write.
@retval EFI_TIMEOUT The transaction did not complete within an internally
specified timeout period, or the controller is not
available for use.
@retval EFI_DEVICE_ERROR There was an Smbus error (NACK) during the operation.
This could indicate the slave device is not present
or is in a hung condition.
**/
EFI_STATUS
SmbusExec (
IN EFI_SMBUS_DEVICE_ADDRESS SlaveAddress,
IN EFI_SMBUS_DEVICE_COMMAND Command,
IN EFI_SMBUS_OPERATION Operation,
IN BOOLEAN PecCheck,
IN OUT UINTN *Length,
IN OUT VOID *Buffer
)
{
EFI_STATUS Status;
UINT8 AuxcReg;
UINT8 AuxStsReg;
UINT8 SmbusOperation;
UINT8 StsReg;
UINT8 SlvAddrReg;
UINT8 HostCmdReg;
UINT8 BlockCount;
BOOLEAN BufferTooSmall;
UINTN Index;
UINTN BusIndex;
UINT8 *CallBuffer;
UINT8 SmbusHctl;
UINT32 Timeout;
CallBuffer = Buffer;
BlockCount = 0;
///
/// For any operations besides quick read & write, the pointers to
/// Length and Buffer must not be NULL.
///
if ((Operation != EfiSmbusQuickRead) && (Operation != EfiSmbusQuickWrite)) {
if ((Length == NULL) || (Buffer == NULL)) {
return EFI_INVALID_PARAMETER;
}
}
///
/// See if its ok to use the bus based upon INUSE_STS bit.
///
Status = AcquireBus ();
if (EFI_ERROR (Status)) {
return Status;
}
///
/// This is the main operation loop. If the operation results in a Smbus
/// collision with another master on the bus, it attempts the requested
/// transaction again at least BUS_TRIES attempts.
///
for (BusIndex = 0; BusIndex < BUS_TRIES; BusIndex++) {
///
/// Operation Specifics (pre-execution)
///
Status = EFI_SUCCESS;
SmbusOperation = V_SMBUS_SMB_CMD_QUICK;
SlvAddrReg = (UINT8) ((SlaveAddress.SmbusDeviceAddress << 1) | 1);
HostCmdReg = (UINT8) Command;
AuxcReg = 0;
switch (Operation) {
case EfiSmbusQuickWrite:
SlvAddrReg--;
///
/// The "break;" command is not present here to allow code execution
/// do drop into the next case, which contains common code to this case.
///
case EfiSmbusQuickRead:
if (PecCheck == TRUE) {
Status = EFI_UNSUPPORTED;
}
break;
case EfiSmbusSendByte:
HostCmdReg = CallBuffer[0];
SlvAddrReg--;
///
/// The "break;" command is not present here to allow code execution
/// do drop into the next case, which contains common code to this case.
///
case EfiSmbusReceiveByte:
SmbusOperation = V_SMBUS_SMB_CMD_BYTE;
if (*Length < 1) {
Status = EFI_BUFFER_TOO_SMALL;
}
*Length = 1;
break;
case EfiSmbusWriteByte:
SmbusIoWrite (R_SMBUS_HD0, CallBuffer[0]);
SlvAddrReg--;
*Length = 1;
///
/// The "break;" command is not present here to allow code execution
/// do drop into the next case, which contains common code to this case.
///
case EfiSmbusReadByte:
if (*Length < 1) {
Status = EFI_BUFFER_TOO_SMALL;
} else if (*Length == 1) {
SmbusOperation = V_SMBUS_SMB_CMD_BYTE_DATA;
} else if (*Length <= 256) {
if (PecCheck == TRUE) {
///
/// The I2C Read command with either PEC_EN or AAC bit set
/// produces undefined results.
///
Status = EFI_UNSUPPORTED;
}
SmbusOperation = V_SMBUS_SMB_CMD_IIC_READ;
} else {
Status = EFI_INVALID_PARAMETER;
}
break;
case EfiSmbusReadWord:
SmbusOperation = V_SMBUS_SMB_CMD_WORD_DATA;
if (*Length < 2) {
Status = EFI_BUFFER_TOO_SMALL;
}
*Length = 2;
break;
case EfiSmbusWriteWord:
SmbusOperation = V_SMBUS_SMB_CMD_WORD_DATA;
SlvAddrReg--;
SmbusIoWrite (R_SMBUS_HD1, CallBuffer[1]);
SmbusIoWrite (R_SMBUS_HD0, CallBuffer[0]);
if (*Length < 2) {
Status = EFI_BUFFER_TOO_SMALL;
}
*Length = 2;
break;
case EfiSmbusWriteBlock:
SmbusIoWrite (R_SMBUS_HD0, *(UINT8 *) Length);
SlvAddrReg--;
BlockCount = (UINT8) (*Length);
///
/// The "break;" command is not present here to allow code execution
/// do drop into the next case, which contains common code to this case.
///
case EfiSmbusReadBlock:
SmbusOperation = V_SMBUS_SMB_CMD_BLOCK;
if ((*Length < 1) || (*Length > 32)) {
Status = EFI_INVALID_PARAMETER;
break;
}
AuxcReg |= B_SMBUS_E32B;
break;
case EfiSmbusProcessCall:
SmbusOperation = V_SMBUS_SMB_CMD_PROCESS_CALL;
SmbusIoWrite (R_SMBUS_HD1, CallBuffer[1]);
SmbusIoWrite (R_SMBUS_HD0, CallBuffer[0]);
if (*Length < 2) {
Status = EFI_BUFFER_TOO_SMALL;
}
*Length = 2;
break;
case EfiSmbusBWBRProcessCall:
///
/// The write byte count cannot be zero or more than
/// 32 bytes.
///
if ((*Length < 1) || (*Length > 32)) {
Status = EFI_INVALID_PARAMETER;
break;
}
SmbusIoWrite (R_SMBUS_HD0, *(UINT8 *) Length);
BlockCount = (UINT8) (*Length);
SmbusOperation = V_SMBUS_SMB_CMD_BLOCK_PROCESS;
AuxcReg |= B_SMBUS_E32B;
break;
default:
Status = EFI_INVALID_PARAMETER;
break;
}
if (EFI_ERROR (Status)) {
break;
}
if (PecCheck == TRUE) {
AuxcReg |= B_SMBUS_AAC;
}
///
/// Set Auxiliary Control register
///
SmbusIoWrite (R_SMBUS_AUXC, AuxcReg);
///
/// Reset the pointer of the internal buffer
///
SmbusIoRead (R_SMBUS_HCTL);
///
/// Now that the 32 byte buffer is turned on, we can write th block data
/// into it
///
if ((Operation == EfiSmbusWriteBlock) || (Operation == EfiSmbusBWBRProcessCall)) {
for (Index = 0; Index < BlockCount; Index++) {
///
/// Write next byte
///
SmbusIoWrite (R_SMBUS_HBD, CallBuffer[Index]);
}
}
///
/// Set SMBus slave address for the device to send/receive from
///
SmbusIoWrite (R_SMBUS_TSA, SlvAddrReg);
///
/// For I2C read, send DATA1 register for the offset (address)
/// within the serial memory chips
///
if ((Operation == EfiSmbusReadByte) && (*Length > 1)) {
SmbusIoWrite (R_SMBUS_HD1, HostCmdReg);
} else {
///
/// Set Command register
///
SmbusIoWrite (R_SMBUS_HCMD, HostCmdReg);
}
///
/// Set Control Register (Initiate Operation, Interrupt disabled)
///
SmbusIoWrite (R_SMBUS_HCTL, (UINT8) (SmbusOperation + B_SMBUS_START));
///
/// Wait for IO to complete
///
if (!IoDone (&StsReg)) {
Status = EFI_TIMEOUT;
break;
} else if (StsReg & B_SMBUS_DERR) {
AuxStsReg = SmbusIoRead (R_SMBUS_AUXS);
if (AuxStsReg & B_SMBUS_CRCE) {
Status = EFI_CRC_ERROR;
} else {
Status = EFI_DEVICE_ERROR;
}
break;
} else if (StsReg & B_SMBUS_BERR) {
///
/// Clear the Bus Error for another try
///
Status = EFI_DEVICE_ERROR;
SmbusIoWrite (R_SMBUS_HSTS, B_SMBUS_BERR);
///
/// Clear Status Registers
///
SmbusIoWrite (R_SMBUS_HSTS, B_SMBUS_HSTS_ALL);
SmbusIoWrite (R_SMBUS_AUXS, B_SMBUS_CRCE);
///
/// If bus collision happens, stall some time, then try again
/// Here we choose 10 milliseconds to avoid MTCP transfer.
///
MicroSecondDelay (STALL_PERIOD);
continue;
}
///
/// successfull completion
/// Operation Specifics (post-execution)
///
switch (Operation) {
case EfiSmbusReadWord:
///
/// The "break;" command is not present here to allow code execution
/// do drop into the next case, which contains common code to this case.
///
case EfiSmbusProcessCall:
CallBuffer[1] = SmbusIoRead (R_SMBUS_HD1);
CallBuffer[0] = SmbusIoRead (R_SMBUS_HD0);
break;
case EfiSmbusReadByte:
if (*Length > 1) {
for (Index = 0; Index < *Length; Index++) {
///
/// Read the byte
///
CallBuffer[Index] = SmbusIoRead (R_SMBUS_HBD);
///
/// After receiving byte n-1 (1-base) of the message, the
/// software will then set the LAST BYTE bit. The software
/// will then clear the BYTE_DONE_STS bit.
///
if (Index == ((*Length - 1) - 1)) {
SmbusHctl = SmbusIoRead (R_SMBUS_HCTL) | (UINT8) B_SMBUS_LAST_BYTE;
SmbusIoWrite (R_SMBUS_HCTL, SmbusHctl);
} else if (Index == (*Length - 1)) {
///
/// Clear the LAST BYTE bit after receiving byte n (1-base) of the message
///
SmbusHctl = SmbusIoRead (R_SMBUS_HCTL) & (UINT8) ~B_SMBUS_LAST_BYTE;
SmbusIoWrite (R_SMBUS_HCTL, SmbusHctl);
}
///
/// Clear the BYTE_DONE_STS bit
///
SmbusIoWrite (R_SMBUS_HSTS, B_SMBUS_BYTE_DONE_STS);
///
/// Check BYTE_DONE_STS bit to know if it has completed transmission
/// of a byte. No need to check it for the last byte.
///
if (Index < (*Length - 1)) {
///
/// If somehow board operates at 10Khz, it will take 0.9 ms (9/10Khz) for another byte.
/// Add 10 us delay for a loop of 100 that the total timeout is 1 ms to take care of
/// the slowest case.
///
for (Timeout = 0; Timeout < 100; Timeout++) {
if ((SmbusIoRead (R_SMBUS_HSTS) & (UINT8) B_SMBUS_BYTE_DONE_STS) != 0) {
break;
}
///
/// Delay 10 us
///
MicroSecondDelay (STALL_PERIOD);
}
if (Timeout >= 100) {
Status = EFI_TIMEOUT;
break;
}
}
}
break;
}
case EfiSmbusReceiveByte:
CallBuffer[0] = SmbusIoRead (R_SMBUS_HD0);
break;
case EfiSmbusWriteBlock:
SmbusIoWrite (R_SMBUS_HSTS, B_SMBUS_BYTE_DONE_STS);
break;
case EfiSmbusReadBlock:
BufferTooSmall = FALSE;
///
/// Find out how many bytes will be in the block
///
BlockCount = SmbusIoRead (R_SMBUS_HD0);
if (*Length < BlockCount) {
BufferTooSmall = TRUE;
} else {
for (Index = 0; Index < BlockCount; Index++) {
///
/// Read the byte
///
CallBuffer[Index] = SmbusIoRead (R_SMBUS_HBD);
}
}
*Length = BlockCount;
if (BufferTooSmall) {
Status = EFI_BUFFER_TOO_SMALL;
}
break;
case EfiSmbusBWBRProcessCall:
///
/// Find out how many bytes will be in the block
///
BlockCount = SmbusIoRead (R_SMBUS_HD0);
///
/// The read byte count cannot be zero.
///
if (BlockCount < 1) {
Status = EFI_BUFFER_TOO_SMALL;
break;
}
///
/// The combined data payload (the write byte count + the read byte count)
/// must not exceed 32 bytes
///
if (((UINT8) (*Length) + BlockCount) > 32) {
Status = EFI_DEVICE_ERROR;
break;
}
for (Index = 0; Index < BlockCount; Index++) {
///
/// Read the byte
///
CallBuffer[Index] = SmbusIoRead (R_SMBUS_HBD);
}
*Length = BlockCount;
break;
default:
break;
};
if ((StsReg & B_SMBUS_BERR) && (Status != EFI_BUFFER_TOO_SMALL)) {
///
/// Clear the Bus Error for another try
///
Status = EFI_DEVICE_ERROR;
SmbusIoWrite (R_SMBUS_HSTS, B_SMBUS_BERR);
///
/// If bus collision happens, stall some time, then try again
/// Here we choose 10 milliseconds to avoid MTCP transfer.
///
MicroSecondDelay (STALL_PERIOD);
continue;
} else {
break;
}
}
///
/// Clear Status Registers and exit
///
SmbusIoWrite (R_SMBUS_HSTS, B_SMBUS_HSTS_ALL);
SmbusIoWrite (R_SMBUS_AUXS, B_SMBUS_CRCE);
SmbusIoWrite (R_SMBUS_AUXC, 0);
return Status;
}
/**
This function initializes the Smbus Registers.
@param[in] None
@retval[in] None
**/
VOID
InitializeSmbusRegisters (
VOID
)
{
UINTN SmbusRegBase;
SmbusRegBase = MmPciBase (
DEFAULT_PCI_BUS_NUMBER_SC,
PCI_DEVICE_NUMBER_SMBUS,
PCI_FUNCTION_NUMBER_SMBUS
);
///
/// Enable the Smbus I/O Enable
///
MmioOr8 (SmbusRegBase + PCI_COMMAND_OFFSET, (UINT8) EFI_PCI_COMMAND_IO_SPACE);
///
/// Enable the Smbus host controller
///
MmioAndThenOr8 (
SmbusRegBase + R_SMBUS_HOSTC,
(UINT8) (~(B_SMBUS_HOSTC_SMI_EN | B_SMBUS_HOSTC_I2C_EN)),
B_SMBUS_HOSTC_HST_EN
);
SmbusIoWrite (R_SMBUS_HSTS, B_SMBUS_HSTS_ALL);
} | 28.555896 | 107 | 0.568563 |
82dd7669068ef0e9bcc1d61bd678d535625e7359 | 199 | h | C | CarDetection/src/libs/TimeUtils.h | carlosmccosta/Car-Detection | 2c2c8e2172fb606f7e2b974a7e9f46de0e4199a2 | [
"MIT"
] | 41 | 2015-03-22T08:57:08.000Z | 2020-09-12T21:07:39.000Z | CarDetection/src/libs/TimeUtils.h | Ewenwan/Car-Detection | 2c2c8e2172fb606f7e2b974a7e9f46de0e4199a2 | [
"MIT"
] | 1 | 2016-07-21T07:07:25.000Z | 2016-07-21T08:49:40.000Z | CarDetection/src/libs/TimeUtils.h | carlosmccosta/Car-Detection | 2c2c8e2172fb606f7e2b974a7e9f46de0e4199a2 | [
"MIT"
] | 32 | 2015-03-23T06:14:37.000Z | 2021-01-23T00:00:12.000Z | #pragma once
#include <string>
#include <sstream>
#include <cmath>
using std::string;
using std::stringstream;
class TimeUtils {
public:
static string formatSecondsToDate(double seconds);
};
| 12.4375 | 52 | 0.738693 |
32452f6fb4b046a7ad5cefa81c47ed00d14bb3ac | 266 | h | C | Example/BasicTools/PCAppDelegate.h | pcyan3166/BasicTools | 626a63e376165686ffc4cd24056481e824385896 | [
"MIT"
] | 1 | 2020-08-11T07:41:59.000Z | 2020-08-11T07:41:59.000Z | Example/BasicTools/PCAppDelegate.h | pcyan3166/BasicTools | 626a63e376165686ffc4cd24056481e824385896 | [
"MIT"
] | null | null | null | Example/BasicTools/PCAppDelegate.h | pcyan3166/BasicTools | 626a63e376165686ffc4cd24056481e824385896 | [
"MIT"
] | 1 | 2020-08-17T06:22:53.000Z | 2020-08-17T06:22:53.000Z | //
// PCAppDelegate.h
// BasicTools
//
// Created by pcyan on 08/03/2020.
// Copyright (c) 2020 pcyan. All rights reserved.
//
@import UIKit;
@interface PCAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
| 16.625 | 62 | 0.710526 |
c5920fc6744a9961bd1db86b2cbe02a987894a34 | 3,807 | c | C | gempak/source/gemlib/cfl/cflperms.c | oxelson/gempak | e7c477814d7084c87d3313c94e192d13d8341fa1 | [
"BSD-3-Clause"
] | 42 | 2015-06-03T15:26:21.000Z | 2022-02-28T22:36:03.000Z | gempak/source/gemlib/cfl/cflperms.c | oxelson/gempak | e7c477814d7084c87d3313c94e192d13d8341fa1 | [
"BSD-3-Clause"
] | 60 | 2015-05-11T21:36:08.000Z | 2022-03-29T16:22:42.000Z | gempak/source/gemlib/cfl/cflperms.c | oxelson/gempak | e7c477814d7084c87d3313c94e192d13d8341fa1 | [
"BSD-3-Clause"
] | 27 | 2016-06-06T21:55:14.000Z | 2022-03-18T18:23:28.000Z | #include "geminc.h"
#include "gemprm.h"
void cfl_perms ( char *file, Boolean *can_read, Boolean *can_write, int *iret )
/************************************************************************
* cfl_perms *
* *
* This function checks the permissions on the passed in file to see if *
* the user has read and write permission. If the file is not found, *
* can_read is FALSE, and the write permission of the directory is *
* checked. If the directory is not found, can_write is FALSE. Due to *
* policy, the user is only allowed to write in a directory owned by *
* user. *
* *
* void cfl_perms ( file, can_read, can_write, iret ) *
* *
* Input parameters: *
* *file char filename to be checked *
* *
* Output parameters: *
* *can_read Boolean read permission result *
* *can_write Boolean write permission result *
* *iret int Status = -1 if file cannot be verified *
* *
** *
* Log: *
* T. Piper/SAIC 5/02 Created from another function *
***********************************************************************/
{
uid_t uid;
gid_t gid;
struct stat fstat;
char cpath[LLPATH], basnam[MXFLSZ], newfile[FILE_FULLSZ];
int istat, ier;
/*---------------------------------------------------------------------*/
*iret = 0;
/*
* Expand any environment variables in the file name.
*/
css_envr ( file, newfile, &ier );
uid = getuid();
gid = getgid();
*can_read = *can_write = FALSE;
/*
* If the file can be found, check the read and write permissions.
*/
istat = stat( newfile, &fstat );
if ( istat == 0 ) {
/*
* Check read permissions (other, then group, then user).
*/
if (fstat.st_mode & S_IROTH ||
(gid == fstat.st_gid && (fstat.st_mode & S_IRGRP)) ||
(uid == fstat.st_uid && (fstat.st_mode & S_IRUSR)))
*can_read = TRUE;
/*
* Check write permission (other, then group, then user).
*/
if (fstat.st_mode & S_IWOTH ||
(gid == fstat.st_gid && (fstat.st_mode & S_IWGRP)) ||
(uid == fstat.st_uid && (fstat.st_mode & S_IWUSR)))
*can_write = TRUE;
}
else {
*iret = -1;
/*
* If the newfile was determined to contain a subdirectory then
* pull file name off and test for write permission on the target
* directory.
*/
cfl_path ( file, cpath, basnam, &ier );
if ( cpath == NULL ) strcpy(cpath,"./");
/*
* If the directory can be found, check the write permissions.
*/
if (stat (cpath, &fstat) == 0) {
/*
* Check write permission (other, then group, then user).
*/
if (fstat.st_mode & S_IWOTH ||
(gid == fstat.st_gid && (fstat.st_mode & S_IWGRP)) ||
(uid == fstat.st_uid && (fstat.st_mode & S_IWUSR))) {
*can_write = TRUE;
}
}
}
}
| 40.073684 | 79 | 0.405043 |
a90ddfcfd6272351789761db7ed6c63c582133db | 5,701 | h | C | vtkm/worklet/connectivities/ImageConnectivity.h | Kitware/VTK-m | d1fd72e71a251dd69318a42d01a1231a2716a241 | [
"BSD-3-Clause"
] | 14 | 2019-10-25T03:25:47.000Z | 2022-01-19T02:14:53.000Z | vtkm/worklet/connectivities/ImageConnectivity.h | Kitware/VTK-m | d1fd72e71a251dd69318a42d01a1231a2716a241 | [
"BSD-3-Clause"
] | null | null | null | vtkm/worklet/connectivities/ImageConnectivity.h | Kitware/VTK-m | d1fd72e71a251dd69318a42d01a1231a2716a241 | [
"BSD-3-Clause"
] | 3 | 2019-08-20T10:49:49.000Z | 2021-12-22T17:39:15.000Z | //============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#ifndef vtk_m_worklet_connectivity_ImageConnectivity_h
#define vtk_m_worklet_connectivity_ImageConnectivity_h
#include <vtkm/cont/Invoker.h>
#include <vtkm/cont/UncertainArrayHandle.h>
#include <vtkm/worklet/WorkletMapField.h>
#include <vtkm/worklet/WorkletPointNeighborhood.h>
#include <vtkm/worklet/connectivities/InnerJoin.h>
#include <vtkm/worklet/connectivities/UnionFind.h>
namespace vtkm
{
namespace worklet
{
namespace connectivity
{
namespace detail
{
class ImageGraft : public vtkm::worklet::WorkletPointNeighborhood
{
public:
using ControlSignature = void(CellSetIn,
FieldInNeighborhood neighborComp,
FieldInNeighborhood neighborColor,
AtomicArrayInOut compOut);
using ExecutionSignature = void(Boundary, _2, _3, _4);
// compOut is a "linear" alias of neightborComp such that we can update component labels
template <typename Boundary,
typename NeighborComp,
typename NeighborColor,
typename AtomicCompOut>
VTKM_EXEC void operator()(Boundary boundary,
const NeighborComp& neighborComp,
const NeighborColor& neighborColor,
AtomicCompOut& compOut) const
{
auto thisColor = neighborColor.Get(0, 0, 0);
auto minIndices = boundary.MinNeighborIndices(1);
auto maxIndices = boundary.MaxNeighborIndices(1);
for (int k = minIndices[2]; k <= maxIndices[2]; k++)
{
for (int j = minIndices[1]; j <= maxIndices[1]; j++)
{
for (int i = minIndices[0]; i <= maxIndices[0]; i++)
{
if (thisColor == neighborColor.Get(i, j, k))
{
// We need to reload thisComp and thatComp every iteration since
// they might have been changed by Unite(), both as a result of
// attaching one tree to the other or as a result of path compaction
// in findRoot().
auto thisComp = neighborComp.Get(0, 0, 0);
auto thatComp = neighborComp.Get(i, j, k);
// Merge the two components one way or the other, the order will
// be resolved by Unite().
UnionFind::Unite(compOut, thisComp, thatComp);
}
}
}
}
}
};
}
// Single pass connected component algorithm from
// Jaiganesh, Jayadharini, and Martin Burtscher.
// "A high-performance connected components implementation for GPUs."
// Proceedings of the 27th International Symposium on High-Performance
// Parallel and Distributed Computing. 2018.
class ImageConnectivity
{
public:
class RunImpl
{
public:
template <int Dimension, typename T, typename StorageT, typename OutputPortalType>
void operator()(const vtkm::cont::ArrayHandle<T, StorageT>& pixels,
const vtkm::cont::CellSetStructured<Dimension>& input,
OutputPortalType& componentsOut) const
{
using Algorithm = vtkm::cont::Algorithm;
// Initialize the parent pointer to point to the pixel itself. There are other
// ways to initialize the parent pointers, for example, a smaller or the minimal
// neighbor.
Algorithm::Copy(vtkm::cont::ArrayHandleIndex(pixels.GetNumberOfValues()), componentsOut);
vtkm::cont::Invoker invoke;
invoke(detail::ImageGraft{}, input, componentsOut, pixels, componentsOut);
invoke(PointerJumping{}, componentsOut);
// renumber connected component to the range of [0, number of components).
Renumber::Run(componentsOut);
}
};
class ResolveDynamicCellSet
{
public:
template <int Dimension, typename T, typename StorageT, typename OutputPortalType>
void operator()(const vtkm::cont::CellSetStructured<Dimension>& input,
const vtkm::cont::ArrayHandle<T, StorageT>& pixels,
OutputPortalType& components) const
{
vtkm::cont::CastAndCall(pixels, RunImpl(), input, components);
}
};
template <int Dimension, typename OutputPortalType>
void Run(const vtkm::cont::CellSetStructured<Dimension>& input,
const vtkm::cont::UnknownArrayHandle& pixels,
OutputPortalType& componentsOut) const
{
using Types = vtkm::TypeListScalarAll;
using Storages = VTKM_DEFAULT_STORAGE_LIST;
vtkm::cont::CastAndCall(pixels.ResetTypes<Types, Storages>(), RunImpl(), input, componentsOut);
}
template <int Dimension, typename T, typename S, typename OutputPortalType>
void Run(const vtkm::cont::CellSetStructured<Dimension>& input,
const vtkm::cont::ArrayHandle<T, S>& pixels,
OutputPortalType& componentsOut) const
{
vtkm::cont::CastAndCall(pixels, RunImpl(), input, componentsOut);
}
template <typename CellSetTag, typename T, typename S, typename OutputPortalType>
void Run(const vtkm::cont::DynamicCellSetBase<CellSetTag>& input,
const vtkm::cont::ArrayHandle<T, S>& pixels,
OutputPortalType& componentsOut) const
{
input.ResetCellSetList(vtkm::cont::CellSetListStructured())
.CastAndCall(ResolveDynamicCellSet(), pixels, componentsOut);
}
};
}
}
}
#endif // vtk_m_worklet_connectivity_ImageConnectivity_h
| 35.63125 | 99 | 0.65392 |
a93312c816c28bc7ae788693056aa8bcd13c1204 | 3,305 | h | C | contrib/libs/linux-headers/asm/signal_powerpc.h | jochenater/catboost | de2786fbc633b0d6ea6a23b3862496c6151b95c2 | [
"Apache-2.0"
] | 6,989 | 2017-07-18T06:23:18.000Z | 2022-03-31T15:58:36.000Z | contrib/libs/linux-headers/asm/signal_powerpc.h | birichie/catboost | de75c6af12cf490700e76c22072fbdc15b35d679 | [
"Apache-2.0"
] | 1,978 | 2017-07-18T09:17:58.000Z | 2022-03-31T14:28:43.000Z | contrib/libs/linux-headers/asm/signal_powerpc.h | birichie/catboost | de75c6af12cf490700e76c22072fbdc15b35d679 | [
"Apache-2.0"
] | 1,228 | 2017-07-18T09:03:13.000Z | 2022-03-29T05:57:40.000Z | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
#ifndef _ASM_POWERPC_SIGNAL_H
#define _ASM_POWERPC_SIGNAL_H
#include <linux/types.h>
#define _NSIG 64
#ifdef __powerpc64__
#define _NSIG_BPW 64
#else
#define _NSIG_BPW 32
#endif
#define _NSIG_WORDS (_NSIG / _NSIG_BPW)
typedef unsigned long old_sigset_t; /* at least 32 bits */
typedef struct {
unsigned long sig[_NSIG_WORDS];
} sigset_t;
#define SIGHUP 1
#define SIGINT 2
#define SIGQUIT 3
#define SIGILL 4
#define SIGTRAP 5
#define SIGABRT 6
#define SIGIOT 6
#define SIGBUS 7
#define SIGFPE 8
#define SIGKILL 9
#define SIGUSR1 10
#define SIGSEGV 11
#define SIGUSR2 12
#define SIGPIPE 13
#define SIGALRM 14
#define SIGTERM 15
#define SIGSTKFLT 16
#define SIGCHLD 17
#define SIGCONT 18
#define SIGSTOP 19
#define SIGTSTP 20
#define SIGTTIN 21
#define SIGTTOU 22
#define SIGURG 23
#define SIGXCPU 24
#define SIGXFSZ 25
#define SIGVTALRM 26
#define SIGPROF 27
#define SIGWINCH 28
#define SIGIO 29
#define SIGPOLL SIGIO
/*
#define SIGLOST 29
*/
#define SIGPWR 30
#define SIGSYS 31
#define SIGUNUSED 31
/* These should not be considered constants from userland. */
#define SIGRTMIN 32
#define SIGRTMAX _NSIG
/*
* SA_FLAGS values:
*
* SA_ONSTACK is not currently supported, but will allow sigaltstack(2).
* SA_RESTART flag to get restarting signals (which were the default long ago)
* SA_NOCLDSTOP flag to turn off SIGCHLD when children stop.
* SA_RESETHAND clears the handler when the signal is delivered.
* SA_NOCLDWAIT flag on SIGCHLD to inhibit zombies.
* SA_NODEFER prevents the current signal from being masked in the handler.
*
* SA_ONESHOT and SA_NOMASK are the historical Linux names for the Single
* Unix names RESETHAND and NODEFER respectively.
*/
#define SA_NOCLDSTOP 0x00000001U
#define SA_NOCLDWAIT 0x00000002U
#define SA_SIGINFO 0x00000004U
#define SA_ONSTACK 0x08000000U
#define SA_RESTART 0x10000000U
#define SA_NODEFER 0x40000000U
#define SA_RESETHAND 0x80000000U
#define SA_NOMASK SA_NODEFER
#define SA_ONESHOT SA_RESETHAND
#define SA_RESTORER 0x04000000U
#define MINSIGSTKSZ 2048
#define SIGSTKSZ 8192
#include <asm-generic/signal-defs.h>
struct old_sigaction {
__sighandler_t sa_handler;
old_sigset_t sa_mask;
unsigned long sa_flags;
__sigrestore_t sa_restorer;
};
struct sigaction {
__sighandler_t sa_handler;
unsigned long sa_flags;
__sigrestore_t sa_restorer;
sigset_t sa_mask; /* mask last for extensibility */
};
typedef struct sigaltstack {
void *ss_sp;
int ss_flags;
size_t ss_size;
} stack_t;
#ifndef __powerpc64__
/*
* These are parameters to dbg_sigreturn syscall. They enable or
* disable certain debugging things that can be done from signal
* handlers. The dbg_sigreturn syscall *must* be called from a
* SA_SIGINFO signal so the ucontext can be passed to it. It takes an
* array of struct sig_dbg_op, which has the debug operations to
* perform before returning from the signal.
*/
struct sig_dbg_op {
int dbg_type;
unsigned long dbg_value;
};
/* Enable or disable single-stepping. The value sets the state. */
#define SIG_DBG_SINGLE_STEPPING 1
/* Enable or disable branch tracing. The value sets the state. */
#define SIG_DBG_BRANCH_TRACING 2
#endif /* ! __powerpc64__ */
#endif /* _ASM_POWERPC_SIGNAL_H */
| 24.124088 | 78 | 0.768533 |
04bafdb0059b18df99178082c97844ae51ff27df | 317 | h | C | FileSystemSimulation/block.h | Acytoo/OS_fs | 32458ea0cd5bcaa75c7c943f4dc8352e4c0cf26c | [
"MIT"
] | 1 | 2018-07-10T11:47:28.000Z | 2018-07-10T11:47:28.000Z | FileSystemSimulation/block.h | Acytoo/File_system_simulation | 32458ea0cd5bcaa75c7c943f4dc8352e4c0cf26c | [
"MIT"
] | null | null | null | FileSystemSimulation/block.h | Acytoo/File_system_simulation | 32458ea0cd5bcaa75c7c943f4dc8352e4c0cf26c | [
"MIT"
] | null | null | null | #ifndef BLOCK_H
#define BLOCK_H
#include <iostream>
int free_blk(int);//释放相应的磁盘块
int get_blk(void);//获取磁盘块
//void show_disk_usage();
//void show_inode_usage();
std::string get_disk_info(); //显示磁盘使用情况
std::string get_inode_info(); //显示inode节点使用情况
int get_disk_percentage();
int get_inode_percentage();
#endif
| 18.647059 | 47 | 0.747634 |
aa98a87f434466648fe9569e6fb6cc95f4b5261f | 6,693 | h | C | aws-cpp-sdk-shield/include/aws/shield/model/ListProtectionsResult.h | woohoou/aws-sdk-cpp | a42835a8aad2eac1e334d899a3fbfedcaa341d51 | [
"Apache-2.0"
] | 1 | 2020-07-16T19:03:13.000Z | 2020-07-16T19:03:13.000Z | aws-cpp-sdk-shield/include/aws/shield/model/ListProtectionsResult.h | woohoou/aws-sdk-cpp | a42835a8aad2eac1e334d899a3fbfedcaa341d51 | [
"Apache-2.0"
] | 18 | 2018-05-15T16:41:07.000Z | 2018-05-21T00:46:30.000Z | aws-cpp-sdk-shield/include/aws/shield/model/ListProtectionsResult.h | woohoou/aws-sdk-cpp | a42835a8aad2eac1e334d899a3fbfedcaa341d51 | [
"Apache-2.0"
] | 1 | 2019-10-31T11:19:50.000Z | 2019-10-31T11:19:50.000Z | /*
* Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
#pragma once
#include <aws/shield/Shield_EXPORTS.h>
#include <aws/core/utils/memory/stl/AWSVector.h>
#include <aws/core/utils/memory/stl/AWSString.h>
#include <aws/shield/model/Protection.h>
#include <utility>
namespace Aws
{
template<typename RESULT_TYPE>
class AmazonWebServiceResult;
namespace Utils
{
namespace Json
{
class JsonValue;
} // namespace Json
} // namespace Utils
namespace Shield
{
namespace Model
{
class AWS_SHIELD_API ListProtectionsResult
{
public:
ListProtectionsResult();
ListProtectionsResult(const Aws::AmazonWebServiceResult<Aws::Utils::Json::JsonValue>& result);
ListProtectionsResult& operator=(const Aws::AmazonWebServiceResult<Aws::Utils::Json::JsonValue>& result);
/**
* <p>The array of enabled <a>Protection</a> objects.</p>
*/
inline const Aws::Vector<Protection>& GetProtections() const{ return m_protections; }
/**
* <p>The array of enabled <a>Protection</a> objects.</p>
*/
inline void SetProtections(const Aws::Vector<Protection>& value) { m_protections = value; }
/**
* <p>The array of enabled <a>Protection</a> objects.</p>
*/
inline void SetProtections(Aws::Vector<Protection>&& value) { m_protections = std::move(value); }
/**
* <p>The array of enabled <a>Protection</a> objects.</p>
*/
inline ListProtectionsResult& WithProtections(const Aws::Vector<Protection>& value) { SetProtections(value); return *this;}
/**
* <p>The array of enabled <a>Protection</a> objects.</p>
*/
inline ListProtectionsResult& WithProtections(Aws::Vector<Protection>&& value) { SetProtections(std::move(value)); return *this;}
/**
* <p>The array of enabled <a>Protection</a> objects.</p>
*/
inline ListProtectionsResult& AddProtections(const Protection& value) { m_protections.push_back(value); return *this; }
/**
* <p>The array of enabled <a>Protection</a> objects.</p>
*/
inline ListProtectionsResult& AddProtections(Protection&& value) { m_protections.push_back(std::move(value)); return *this; }
/**
* <p>If you specify a value for <code>MaxResults</code> and you have more
* Protections than the value of MaxResults, AWS Shield Advanced returns a
* NextToken value in the response that allows you to list another group of
* Protections. For the second and subsequent ListProtections requests, specify the
* value of NextToken from the previous response to get information about another
* batch of Protections.</p>
*/
inline const Aws::String& GetNextToken() const{ return m_nextToken; }
/**
* <p>If you specify a value for <code>MaxResults</code> and you have more
* Protections than the value of MaxResults, AWS Shield Advanced returns a
* NextToken value in the response that allows you to list another group of
* Protections. For the second and subsequent ListProtections requests, specify the
* value of NextToken from the previous response to get information about another
* batch of Protections.</p>
*/
inline void SetNextToken(const Aws::String& value) { m_nextToken = value; }
/**
* <p>If you specify a value for <code>MaxResults</code> and you have more
* Protections than the value of MaxResults, AWS Shield Advanced returns a
* NextToken value in the response that allows you to list another group of
* Protections. For the second and subsequent ListProtections requests, specify the
* value of NextToken from the previous response to get information about another
* batch of Protections.</p>
*/
inline void SetNextToken(Aws::String&& value) { m_nextToken = std::move(value); }
/**
* <p>If you specify a value for <code>MaxResults</code> and you have more
* Protections than the value of MaxResults, AWS Shield Advanced returns a
* NextToken value in the response that allows you to list another group of
* Protections. For the second and subsequent ListProtections requests, specify the
* value of NextToken from the previous response to get information about another
* batch of Protections.</p>
*/
inline void SetNextToken(const char* value) { m_nextToken.assign(value); }
/**
* <p>If you specify a value for <code>MaxResults</code> and you have more
* Protections than the value of MaxResults, AWS Shield Advanced returns a
* NextToken value in the response that allows you to list another group of
* Protections. For the second and subsequent ListProtections requests, specify the
* value of NextToken from the previous response to get information about another
* batch of Protections.</p>
*/
inline ListProtectionsResult& WithNextToken(const Aws::String& value) { SetNextToken(value); return *this;}
/**
* <p>If you specify a value for <code>MaxResults</code> and you have more
* Protections than the value of MaxResults, AWS Shield Advanced returns a
* NextToken value in the response that allows you to list another group of
* Protections. For the second and subsequent ListProtections requests, specify the
* value of NextToken from the previous response to get information about another
* batch of Protections.</p>
*/
inline ListProtectionsResult& WithNextToken(Aws::String&& value) { SetNextToken(std::move(value)); return *this;}
/**
* <p>If you specify a value for <code>MaxResults</code> and you have more
* Protections than the value of MaxResults, AWS Shield Advanced returns a
* NextToken value in the response that allows you to list another group of
* Protections. For the second and subsequent ListProtections requests, specify the
* value of NextToken from the previous response to get information about another
* batch of Protections.</p>
*/
inline ListProtectionsResult& WithNextToken(const char* value) { SetNextToken(value); return *this;}
private:
Aws::Vector<Protection> m_protections;
Aws::String m_nextToken;
};
} // namespace Model
} // namespace Shield
} // namespace Aws
| 41.06135 | 133 | 0.709697 |
43f707a0d52ecf79e679db8b6066f4fa6c217d13 | 9,753 | h | C | VST2_SDK/base/source/fmemory.h | jatinchowdhury18/JUCE | 732fc829501461066f4f53da0ff0e64b3b67c52f | [
"ISC"
] | null | null | null | VST2_SDK/base/source/fmemory.h | jatinchowdhury18/JUCE | 732fc829501461066f4f53da0ff0e64b3b67c52f | [
"ISC"
] | null | null | null | VST2_SDK/base/source/fmemory.h | jatinchowdhury18/JUCE | 732fc829501461066f4f53da0ff0e64b3b67c52f | [
"ISC"
] | null | null | null | //------------------------------------------------------------------------
// Project : SDK Base
// Version : 1.0
//
// Category : Helpers
// Filename : base/source/fmemory.h
// Created by : Steinberg, 1998
// Description : memory allocation helper functions and classes
//
//-----------------------------------------------------------------------------
// LICENSE
// (c) 2015, Steinberg Media Technologies GmbH, All Rights Reserved
//-----------------------------------------------------------------------------
// This Software Development Kit may not be distributed in parts or its entirety
// without prior written agreement by Steinberg Media Technologies GmbH.
// This SDK must not be used to re-engineer or manipulate any technology used
// in any Steinberg or Third-party application or software module,
// unless permitted by law.
// Neither the name of the Steinberg Media Technologies nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SDK IS PROVIDED BY STEINBERG MEDIA TECHNOLOGIES GMBH "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL STEINBERG MEDIA TECHNOLOGIES GMBH BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
//-----------------------------------------------------------------------------
//----------------------------------------------------------------------------------
/** @file base/source/fmemory.h
Memory allocation helper functions and classes. */
//----------------------------------------------------------------------------------
#ifndef __fmemory__
#define __fmemory__
#include "base/source/fthread.h"
#include "base/source/tarray.h"
namespace Steinberg {
//------------------------------------------------------------------------
/** Allocate memory aligned to a given alignment
\param[in] size : size of the memory to be allocated
\param[in] alignment : specifies the desired byte alignment of the returned address. This must be even and greater than 2.
You will get undefined behavior if the alignment is not a power of 2.
\return the aligned memory address, or 0 if the alignment is invalid or the allocation from the heap failed
Allocation is done on the heap of the standard runtime by allocating more memory and returning the first address that
meets the alignment demands.
You must free the memory by calling alignedFree.
*/
void* alignedMalloc (int32 size, int32 alignment = 16);
//------------------------------------------------------------------------
/** Free aligned memory allocated by alignedMalloc
\param[in] buffer : pointer to the memory allocated by alignedMalloc
*/
bool alignedFree (void* buffer);
//------------------------------------------------------------------------
//------------------------------------------------------------------------
/** FMemoryPool provides a pool of equal sized cached memory blocks
When a lot of equal sized objects are needed, FMemoryPool can be used for fast allocation.
A standard application is overloading the new operator of a class that is often allocated and deallocated.
FMemoryPool starts empty and allocates requested memory blocks from the heap. If a block is returned
to the pool, it is placed on top of a stack of cached objects that are used for fast handling of later
allocations.
The number of objects that are kept in memory for fast re-use is given with the constructor. Requests beyond this threshold
are returned to the heap.
FMemoryPool is thread safe, as it uses FLock to synchronize modifications to the pool.
\see FMemoryBlockPool
*/
//------------------------------------------------------------------------
class FMemoryPool
{
public:
//------------------------------------------------------------------------
/** Constructor specifying the properties of the pool
\param[in] maxElements : the maximum number of unused memory blocks that are kept in memory
\param[in] elementSize : the size of each memory block. It must be greater than sizeof(void*).
*/
FMemoryPool (int32 maxElements, int32 elementSize);
~FMemoryPool (); ///< Destructor. Releases cached memory back to the heap.
void* newElement (); ///< allocate an uninitialized memory block from the pool. If no unused block exists in the pool, allocate it from the heap.
#if WINDOWS && DEVELOPMENT
void* newElement (const char8 *, int32); ///< debug version of newElement () to trace filename and line number
#endif
void deleteElement (void* el); ///< return a block, that has been allocated with newElement ()
//------------------------------------------------------------------------
private:
int32 maxElements;
int32 elementSize;
int32 elementCount;
void** firstElement;
FLock lock;
};
//------------------------------------------------------------------------
/** FMemoryBlockPool provides a pool of equal sized preallocated memory blocks
When a lot of equal sized objects are needed, FMemoryPool can be used for fast allocation and with
little memory overhead.
A standard application is overloading the new operator of a class that is often allocated and deallocated.
FMemoryPool starts empty and preallocates a given number of memory blocks from the heap. If a block is returned
to the pool, it is placed on top of a stack of cached objects that are used for fast handling of later
allocations.
Memory is not released to the heap until the destructor.
FMemoryPool is thread safe, as it uses FLock to synchronize modifications to the pool.
\see FMemoryPool
*/
//------------------------------------------------------------------------
class FMemoryBlockPool
{
public:
//------------------------------------------------------------------------
/** Constructor specifying the properties of the pool
\param[in] delta : number of memory blocks that are preallocated when there is no unused block available
\param[in] elementSize : the size of each memory block. It must be greater than sizeof(void*).
*/
FMemoryBlockPool (uint32 delta, uint32 elementSize);
~FMemoryBlockPool (); ///< destructor
void* newElement (); ///< allocate an uninitialized memory block from the pool.
void deleteElement (void* el); ///< return a block, that has been allocated with newElement ()
//------------------------------------------------------------------------
private:
void** grow ();
uint32 delta;
uint32 elementSize;
void** freeElement;
TArray<void*> buffers;
FLock lock;
};
//------------------------------------------------------------------------
/** FBlockAllocator provides a simple allocator that works on larger blocks of memory
FBlockAllocator is used to allocate chunks of memory that are placed in
larger memory blocks.
Memory is not released to the heap until the destructor of FBlockAllocator.
FBlockAllocator is thread safe, as it uses FLock to synchronize modifications.
*/
class FBlockAllocator
{
public:
//------------------------------------------------------------------------
/** Constructor
\param[in] blockSize : size of the memory blocks, that provide space for smaller allocations
*/
FBlockAllocator (uint32 blockSize);
~FBlockAllocator (); ///< Destructor. Releases allocated memory back to the heap.
void* allocate (uint32 size); ///< allocate memory from within a preallocated memory block. If size is larger than blockSize, blockSize is increased in multiples of 2.
void free (void* p); ///< free memory allocated with allocate()
//------------------------------------------------------------------------
protected:
///\cond ignore
struct ChunkHeader // chunks are items of a block
{
uint32 magic;
uint32 size; // size of chunk (without this header)
bool used;
};
struct Block
{
uint32 size; // size of data in bytes
void* data;
int operator == (const Block& b) const {return b.size == size && b.data == data;}
};
///\endcond
TArray<Block> blocks;
uint32 blockSize;
FLock lock;
};
class FObjectBlock;
//------------------------------------------------------------------------
/** FObjectPool allocates objects in blocks with MAX_USHORT elements per block
FObjectPool can be used, if a lot of small equal sized elements are needed. Allocation
and deallocation are fast and have little memory overhead. FObjectPool should not
be used for large objects.
Memory is not released to the heap until the destructor of FBlockAllocator.
FObjectPool is thread safe, as it uses FLock to synchronize modifications.
*/
class FObjectPool
{
public:
//------------------------------------------------------------------------
/** Constructor
\param[in] elementSize : size of one element
*/
FObjectPool (uint16 elementSize);
~FObjectPool (); ///< Destructor. Releases allocated memory back to the heap.
void* newElement (); ///< allocate memory from within the preallocated memory block. If no more free entries are found, a new memory block is allocated.
void deleteElement (void* el); ///< return element to the pool.
//------------------------------------------------------------------------
private:
FLock lock;
uint16 objectSize;
TArray <FObjectBlock*> blocks;
};
} // namespace Steinberg
#endif
| 41.151899 | 168 | 0.620835 |
c88867187ec5d5744f36ba990d4bad789acfb01f | 2,735 | h | C | engines/ep/src/config_static.h | jimwwalker/kv_engine | a9d39e3125210525b686ff3acec232f63d70db56 | [
"BSD-3-Clause"
] | 24 | 2015-03-17T02:41:27.000Z | 2022-03-19T20:28:08.000Z | engines/ep/src/config_static.h | jimwwalker/kv_engine | a9d39e3125210525b686ff3acec232f63d70db56 | [
"BSD-3-Clause"
] | 2 | 2016-06-14T23:17:06.000Z | 2016-07-25T11:55:13.000Z | engines/ep/src/config_static.h | jimwwalker/kv_engine | a9d39e3125210525b686ff3acec232f63d70db56 | [
"BSD-3-Clause"
] | 20 | 2015-01-27T09:36:16.000Z | 2017-03-22T20:06:56.000Z | /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Copyright 2010 Couchbase, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Consider this file as an extension to config.h, just that it contains
* static text. The intention is to reduce the number of #ifdefs in the rest
* of the source files without having to put all of them in AH_BOTTOM
* in configure.ac.
*/
#ifndef SRC_CONFIG_STATIC_H
#define SRC_CONFIG_STATIC_H 1
#include "config.h"
#define _FILE_OFFSET_BITS 64
#if ((defined (__SUNPRO_C) || defined(__SUNPRO_CC)) || defined __GNUC__)
#define EXPORT_FUNCTION __attribute__ ((visibility("default")))
#elif defined(_MSC_VER)
#define EXPORT_FUNCTION __declspec(dllexport)
#else
#define EXPORT_FUNCTION
#endif
#if HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_NETINET_TCP_H
#include <netinet/tcp.h>
#endif
#ifdef HAVE_POLL_H
#include <poll.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#include <sys/types.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#define SOCKETPAIR_AF AF_INET
#define getppid() 2
#include <io.h>
#define F_OK 0
#define W_OK 2
#define R_OK 4
#pragma warning(disable: 4291)
#pragma warning(disable: 4244)
#pragma warning(disable: 4267)
#pragma warning(disable: 4996)
#pragma warning(disable: 4800)
/*
#pragma warning(disable: )
#pragma warning(disable: )
*/
#define sched_yield() SwitchToThread()
#if _MSC_VER < 1900
#define snprintf _snprintf
#endif
#define sleep(a) Sleep(a * 1000)
#define random() (long)rand()
/* TROND FIXME */
#define IOV_MAX 1024
typedef unsigned int useconds_t;
#else
#define INVALID_SOCKET -1
#define SOCKET_ERROR -1
#define SOCKETPAIR_AF AF_UNIX
#endif
#if defined(linux) || defined(__linux__) || defined(__linux)
#undef ntohs
#undef ntohl
#undef htons
#undef htonl
#endif
#ifdef HAVE_SCHED_H
#include <sched.h>
#endif
#include <platform/platform.h>
#endif /* SRC_CONFIG_STATIC_H */
| 21.706349 | 77 | 0.740402 |
aebba92d87c0cbb0565d1a30b79b8c86dfb57b2f | 7,732 | c | C | src/libretro-common/file/nbio/nbio_orbis.c | ToadKing/mame2003-plus-libretro | c86f3b3e446cee9f951c15320d9b2d14875601e2 | [
"RSA-MD"
] | 2 | 2020-02-03T04:16:51.000Z | 2020-02-05T19:00:38.000Z | src/libretro-common/file/nbio/nbio_orbis.c | ToadKing/mame2003-plus-libretro | c86f3b3e446cee9f951c15320d9b2d14875601e2 | [
"RSA-MD"
] | null | null | null | src/libretro-common/file/nbio/nbio_orbis.c | ToadKing/mame2003-plus-libretro | c86f3b3e446cee9f951c15320d9b2d14875601e2 | [
"RSA-MD"
] | 1 | 2020-08-04T04:19:50.000Z | 2020-08-04T04:19:50.000Z | /* Copyright (C) 2010-2018 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (nbio_orbis.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <file/nbio.h>
#if defined(ORBIS)
#include <stdio.h>
#include <stdlib.h>
#include <orbisFile.h>
#include <unistd.h>
#include <sys/fcntl.h>
struct nbio_orbis_t
{
int fd;
void* data;
size_t progress;
size_t len;
/*
* possible values:
* NBIO_READ, NBIO_WRITE - obvious
* -1 - currently doing nothing
* -2 - the pointer was reallocated since the last operation
*/
signed char op;
unsigned int mode;
};
static void *nbio_orbis_open(const char * filename, unsigned int mode)
{
static const int o_flags[] = { O_RDONLY, O_RDWR | O_CREAT | O_TRUNC,
O_RDWR, O_RDONLY, O_RDWR | O_CREAT | O_TRUNC };
void *buf = NULL;
struct nbio_orbis_t* handle = NULL;
size_t len = 0;
int fd = orbisOpen(filename, o_flags[mode], 0644);
RARCH_LOG("[NBIO_ORBIS] open %s\n" , filename);
if (fd < 0)
return NULL;
handle = (struct nbio_orbis_t*)malloc(sizeof(struct nbio_orbis_t));
if (!handle)
goto error;
handle->fd = fd;
switch (mode)
{
case NBIO_WRITE:
case BIO_WRITE:
break;
default:
len=orbisLseek(handle->fd, 0, SEEK_END);
orbisLseek(handle->fd, 0, SEEK_SET);
break;
}
handle->mode = mode;
if (len)
buf = malloc(len);
if (!buf)
{
RARCH_LOG("[NBIO_ORBIS] open error malloc %d bytes\n",len);
}
if (len && !buf)
goto error;
handle->data = buf;
handle->len = len;
handle->progress = handle->len;
handle->op = -2;
return handle;
error:
if (handle)
free(handle);
RARCH_LOG("[NBIO_ORBIS] open error closing %s\n" , filename);
orbisClose(fd);
return NULL;
}
static void nbio_orbis_begin_read(void *data)
{
struct nbio_orbis_t *handle = (struct nbio_orbis_t*)data;
if (!handle)
return;
RARCH_LOG("[NBIO_ORBIS] begin read fd=%d\n", handle->fd );
if (handle->op >= 0)
{
RARCH_LOG("[NBIO_ORBIS] ERROR - attempted file read operation while busy\n");
return;
}
orbisLseek(handle->fd, 0, SEEK_SET);
handle->op = NBIO_READ;
handle->progress = 0;
}
static void nbio_orbis_begin_write(void *data)
{
struct nbio_orbis_t *handle = (struct nbio_orbis_t*)data;
if (!handle)
return;
RARCH_LOG("[NBIO_ORBIS] begin write fd=%d\n", handle->fd );
if (handle->op >= 0)
{
RARCH_LOG("[NBIO_ORBIS] ERROR - attempted file write operation while busy\n");
return;
}
orbisLseek(handle->fd, 0, SEEK_SET);
handle->op = NBIO_WRITE;
handle->progress = 0;
}
static bool nbio_orbis_iterate(void *data)
{
size_t amount = 65536;
struct nbio_orbis_t *handle = (struct nbio_orbis_t*)data;
if (!handle)
return false;
RARCH_LOG("[NBIO_ORBIS] begin iterate fd=%d\n", handle->fd );
if (amount > handle->len - handle->progress)
amount = handle->len - handle->progress;
switch (handle->op)
{
case NBIO_READ:
if (handle->mode == BIO_READ)
{
amount = handle->len;
RARCH_LOG("[NBIO_ORBIS] iterate BIO_READ fd=%d readbytes=%d\n", handle->fd, orbisRead(handle->fd, (char*)handle->data, amount));
}
else
{
RARCH_LOG("[NBIO_ORBIS] iterate read fd=%d handle->progress=%d readbytes=%d\n", handle->fd, handle->progress, orbisRead(handle->fd, (char*)handle->data + handle->progress, amount));
}
break;
case NBIO_WRITE:
if (handle->mode == BIO_WRITE)
{
size_t written = 0;
amount = handle->len;
written = orbisWrite(handle->fd, (char*)handle->data, amount);
RARCH_LOG("[NBIO_ORBIS] iterate BIO_WRITE fd=%d writebytes=%d\n", handle->fd, written);
if (written != amount)
{
RARCH_LOG("[NBIO_ORBIS] iterate BIO_WRITE error fd=%d amount=%d != writebytes=%d\n", handle->fd, amount, written);
return false;
}
}
else
{
RARCH_LOG("[NBIO_ORBIS] iterate write fd=%d writebytes=%d\n", handle->fd, orbisWrite(handle->fd, (char*)handle->data + handle->progress, amount));
}
break;
}
handle->progress += amount;
RARCH_LOG("[NBIO_ORBIS] end iterate fd=%d\n", handle->fd );
if (handle->progress == handle->len)
handle->op = -1;
return (handle->op < 0);
}
static void nbio_orbis_resize(void *data, size_t len)
{
struct nbio_orbis_t *handle = (struct nbio_orbis_t*)data;
if (!handle)
return;
if (handle->op >= 0)
{
RARCH_LOG("[NBIO_ORBIS] ERROR - attempted file resize operation while busy\n");
return;
}
if (len < handle->len)
{
RARCH_LOG("[NBIO_ORBIS] ERROR - attempted file shrink operation, not implemented");
return;
}
handle->len = len;
handle->data = realloc(handle->data, handle->len);
handle->op = -1;
handle->progress = handle->len;
}
static void *nbio_orbis_get_ptr(void *data, size_t* len)
{
struct nbio_orbis_t *handle = (struct nbio_orbis_t*)data;
if (!handle)
return NULL;
RARCH_LOG("[NBIO_ORBIS] get pointer\n");
if (len)
*len = handle->len;
if (handle->op == -1)
return handle->data;
return NULL;
}
static void nbio_orbis_cancel(void *data)
{
struct nbio_orbis_t *handle = (struct nbio_orbis_t*)data;
if (!handle)
return;
RARCH_LOG("[NBIO_ORBIS] cancel \n");
handle->op = -1;
handle->progress = handle->len;
}
static void nbio_orbis_free(void *data)
{
struct nbio_orbis_t *handle = (struct nbio_orbis_t*)data;
if (!handle)
return;
RARCH_LOG("[NBIO_ORBIS] begin free fd=%d\n", handle->fd );
if (handle->op >= 0)
{
RARCH_LOG("[NBIO_ORBIS] ERROR - attempted free() while busy\n");
return;
}
RARCH_LOG("[NBIO_ORBIS] free close fd=%d\n",handle->fd);
orbisClose(handle->fd);
free(handle->data);
handle->data = NULL;
free(handle);
}
nbio_intf_t nbio_orbis = {
nbio_orbis_open,
nbio_orbis_begin_read,
nbio_orbis_begin_write,
nbio_orbis_iterate,
nbio_orbis_resize,
nbio_orbis_get_ptr,
nbio_orbis_cancel,
nbio_orbis_free,
"nbio_orbis",
};
#endif
| 27.41844 | 194 | 0.605406 |
eab12c7d359c865767f22436fef6310d1fad3dbc | 909 | c | C | Source/backtrace.c | cianciosa/RAYS | 0a15af58174d7483f42e9479973e1c598bacc18c | [
"MIT"
] | null | null | null | Source/backtrace.c | cianciosa/RAYS | 0a15af58174d7483f42e9479973e1c598bacc18c | [
"MIT"
] | null | null | null | Source/backtrace.c | cianciosa/RAYS | 0a15af58174d7483f42e9479973e1c598bacc18c | [
"MIT"
] | null | null | null | //******************************************************************************
/// @file backtrace.c
/// @brief Functions to fast copy files.
///
/// Routines to print out stack traces.
//******************************************************************************
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
//------------------------------------------------------------------------------
/// @brief Print out a stacktrace then abort the program.
//------------------------------------------------------------------------------
void abort() {
void *buffer = malloc(BACKTRACE_SIZE*sizeof(void *));
int num_pointers = backtrace(buffer, BACKTRACE_SIZE);
char **strings = backtrace_symbols(buffer, num_pointers);
if (strings) {
for (int i = 0; i < num_pointers; i++) {
printf("%s\n", strings[i]);
}
}
free(strings);
exit(1);
}
| 31.344828 | 80 | 0.39604 |
fccb09f3dffc3a1ed8c08f6086c61b0f54e9ae82 | 3,198 | h | C | glide/3dfx.h | metarutaiga/xxGraphic | b0d4d5e26b7751db867bddf78f6d4563598b778f | [
"MIT"
] | 11 | 2019-10-16T18:54:39.000Z | 2021-10-04T20:04:52.000Z | glide/3dfx.h | metarutaiga/xxGraphic | b0d4d5e26b7751db867bddf78f6d4563598b778f | [
"MIT"
] | null | null | null | glide/3dfx.h | metarutaiga/xxGraphic | b0d4d5e26b7751db867bddf78f6d4563598b778f | [
"MIT"
] | null | null | null | /*
** Copyright (c) 1995, 3Dfx Interactive, Inc.
** All Rights Reserved.
**
** This is UNPUBLISHED PROPRIETARY SOURCE CODE of 3Dfx Interactive, Inc.;
** the contents of this file may not be disclosed to third parties, copied or
** duplicated in any form, in whole or in part, without the prior written
** permission of 3Dfx Interactive, Inc.
**
** RESTRICTED RIGHTS LEGEND:
** Use, duplication or disclosure by the Government is subject to restrictions
** as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
** and Computer Software clause at DFARS 252.227-7013, and/or in similar or
** successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
** rights reserved under the Copyright Laws of the United States.
**
** $Revision: 9 $
** $Date: 12/23/97 9:57a $
*/
#ifndef __3DFX_H__
#define __3DFX_H__
/*
** basic data types
*/
typedef unsigned char FxU8;
typedef signed char FxI8;
typedef unsigned short FxU16;
typedef signed short FxI16;
typedef unsigned int FxU32;
typedef signed int FxI32;
typedef int FxBool;
typedef float FxFloat;
typedef double FxDouble;
/*
** color types
*/
typedef unsigned int FxColor_t;
typedef struct { float r, g, b, a; } FxColor4;
/*
** fundamental types
*/
#define FXTRUE 1
#define FXFALSE 0
/*
** helper macros
*/
#define FXUNUSED( a ) ((void)(a))
#define FXBIT( i ) ( 1L << (i) )
/*
** export macros
*/
#if defined(__MSC__)
# if defined (MSVC16)
# define FX_ENTRY
# define FX_CALL
# else
# define FX_ENTRY extern
# define FX_CALL __stdcall
# endif
#elif defined(_MSC_VER)
# define FX_ENTRY extern
# define FX_CALL __stdcall
#elif defined(__WATCOMC__)
# define FX_ENTRY extern
# define FX_CALL __stdcall
#elif defined (__IBMC__) || defined (__IBMCPP__)
/* IBM Visual Age C/C++: */
# define FX_ENTRY extern
# define FX_CALL __stdcall
#elif defined(__DJGPP__)
# define FX_ENTRY extern
# define FX_CALL
#elif defined(__unix__)
# define FX_ENTRY extern
# define FX_CALL
#elif defined(__GNUC__)
# define FX_ENTRY extern
# define FX_CALL
#elif defined(__MWERKS__)
# if macintosh
# define FX_ENTRY extern
# define FX_CALL
# else /* !macintosh */
# error "Unknown MetroWerks target platform"
# endif /* !macintosh */
#else
# warning define FX_ENTRY & FX_CALL for your compiler
# define FX_ENTRY extern
# define FX_CALL
#endif
/*
** x86 compiler specific stuff
*/
#if defined(__BORLANDC_)
# define REALMODE
# define REGW( a, b ) ((a).x.b)
# define REGB( a, b ) ((a).h.b)
# define INT86( a, b, c ) int86(a,b,c)
# define INT86X( a, b, c, d ) int86x(a,b,c,d)
# define RM_SEG( a ) FP_SEG( a )
# define RM_OFF( a ) FP_OFF( a )
#elif defined(__WATCOMC__)
# undef FP_SEG
# undef FP_OFF
# define REGW( a, b ) ((a).w.b)
# define REGB( a, b ) ((a).h.b)
# define INT86( a, b, c ) int386(a,b,c)
# define INT86X( a, b, c, d ) int386x(a,b,c,d)
# define RM_SEG( a ) ( ( ( ( FxU32 ) (a) ) & 0x000F0000 ) >> 4 )
# define RM_OFF( a ) ( ( FxU16 ) (a) )
#endif
#endif /* !__3DFX_H__ */
| 25.584 | 79 | 0.642276 |
0052383be6d42fe871b8be57b1e957152acec4a9 | 2,154 | h | C | include/tulips/system/Utils.h | IBM/tulips | 040f79f9a54bb7da85bdb87daefb9e9b2cdeade2 | [
"BSD-2-Clause"
] | 5 | 2020-09-22T06:02:48.000Z | 2021-11-17T09:26:30.000Z | include/tulips/system/Utils.h | xguerin/tulips | 040f79f9a54bb7da85bdb87daefb9e9b2cdeade2 | [
"BSD-2-Clause"
] | null | null | null | include/tulips/system/Utils.h | xguerin/tulips | 040f79f9a54bb7da85bdb87daefb9e9b2cdeade2 | [
"BSD-2-Clause"
] | 4 | 2021-03-22T09:00:24.000Z | 2021-06-28T09:13:44.000Z | /*
* Copyright (c) 2020, International Business Machines
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
namespace tulips { namespace system { namespace utils {
#define likely(__x) __builtin_expect((__x), 1)
#define unlikely(__x) __builtin_expect((__x), 0)
#ifdef TULIPS_DEBUG
#define LOG(__hdr, __msg) \
std::cout << "[ " << std::setw(8) << __hdr << " ] " << __msg << std::endl
#else
#define LOG(__hdr, __msg) ((void)0)
#endif
inline uint32_t
log2(const uint32_t x)
{
uint32_t y;
asm("\tbsr %1, %0\n" : "=r"(y) : "r"(x));
return y;
}
void join(std::vector<std::string> const& r, const char d, std::string& s);
void split(std::string const& s, const char d, std::vector<std::string>& r);
}}}
| 35.9 | 80 | 0.712628 |
9b8783406bbb30d5c93561c3257391735cf1fd76 | 124 | h | C | libraries/libwidget/Widgets.h | moneytech/skift | fce119cb9364bdc95beaa61bace24df23956ef0c | [
"MIT"
] | null | null | null | libraries/libwidget/Widgets.h | moneytech/skift | fce119cb9364bdc95beaa61bace24df23956ef0c | [
"MIT"
] | null | null | null | libraries/libwidget/Widgets.h | moneytech/skift | fce119cb9364bdc95beaa61bace24df23956ef0c | [
"MIT"
] | null | null | null | #pragma once
#include <libwidget/core/Window.h>
#include <libwidget/widgets/Button.h>
#include <libwidget/widgets/Panel.h>
| 20.666667 | 37 | 0.774194 |
763ef846094868b5171278c826c4ea469daa2d25 | 1,058 | h | C | iOSOpenDev/frameworks/OfficeImport.framework/Headers/OAVStroke.h | bzxy/cydia | f8c838cdbd86e49dddf15792e7aa56e2af80548d | [
"MIT"
] | 678 | 2017-11-17T08:33:19.000Z | 2022-03-26T10:40:20.000Z | iOSOpenDev/frameworks/OfficeImport.framework/Headers/OAVStroke.h | chenfanfang/Cydia | 5efce785bfd5f1064b9c0f0e29a9cc05aa24cad0 | [
"MIT"
] | 22 | 2019-04-16T05:51:53.000Z | 2021-11-08T06:18:45.000Z | iOSOpenDev/frameworks/OfficeImport.framework/Headers/OAVStroke.h | chenfanfang/Cydia | 5efce785bfd5f1064b9c0f0e29a9cc05aa24cad0 | [
"MIT"
] | 170 | 2018-06-10T07:59:20.000Z | 2022-03-22T16:19:33.000Z | /**
* This header is generated by class-dump-z 0.2b.
*
* Source: /System/Library/PrivateFrameworks/OfficeImport.framework/OfficeImport
*/
#import <OfficeImport/OAVStroke.h>
#import <OfficeImport/XXUnknownSuperclass.h>
__attribute__((visibility("hidden")))
@interface OAVStroke : XXUnknownSuperclass {
}
+ (id)readFromManager:(id)manager; // 0x19d7c1
@end
@interface OAVStroke (Private)
+ (int)readCompoundType:(id)type; // 0x19e7f1
+ (int)readPresetDashStyle:(id)style; // 0x19dfa9
+ (int)readLineEndType:(id)type; // 0x19e3b5
+ (int)readLineEndWidth:(id)width; // 0x19e421
+ (int)readLineEndLength:(id)length; // 0x19e48d
+ (int)readCapStyle:(id)style; // 0x19e71d
+ (void)readLineEnd:(id)end type:(id)type width:(id)width length:(id)length; // 0x19e325
+ (void)readDashStyleFromManager:(id)manager toStroke:(id)stroke; // 0x19dddd
+ (void)readJoinStyleFromManager:(id)manager toStroke:(id)stroke; // 0x19e025
+ (id)targetFgColorWithManager:(id)manager; // 0x19da01
+ (void)readFillStyleFromManager:(id)manager toStroke:(id)stroke; // 0x19db45
@end
| 35.266667 | 88 | 0.750473 |
63a51eb2be6056a7db2469df0f152639bcb09174 | 1,788 | c | C | DAY07/02-EvaluationSetA.c | Razdeep/Operating-System-Lab | e089f1a0c00c18fc14e60a09295abefa2b08bfd3 | [
"MIT"
] | 4 | 2019-02-12T15:10:03.000Z | 2019-02-23T15:59:09.000Z | DAY07/02-EvaluationSetA.c | Razdeep/Operating-System-Lab | e089f1a0c00c18fc14e60a09295abefa2b08bfd3 | [
"MIT"
] | null | null | null | DAY07/02-EvaluationSetA.c | Razdeep/Operating-System-Lab | e089f1a0c00c18fc14e60a09295abefa2b08bfd3 | [
"MIT"
] | null | null | null | /**
* ------------------
* SET A Question 2
* ------------------
* Create a scenario where there are three threads -
* One is writing the value of the shared variable
* and the other two are reading the value of the shared
* variable. Whne thread is writinh, no thrad is allowed to
* read and there can be concurrent reads by 2 threads.
* Synchronize the threads.
*
* NOTE: Compile with `gcc -lpthread`
*
*/
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
int shared_variable = 0;
pthread_mutex_t mutex1, mutex2;
void *readProcess1()
{
pthread_mutex_lock(&mutex1);
int x = shared_variable;
sleep(1);
printf("In read process1, Read value of shared variable is %d\n", x);
pthread_mutex_unlock(&mutex1);
}
void *readProcess2()
{
pthread_mutex_lock(&mutex2);
int x = shared_variable;
sleep(1);
printf("In read process2, Read value of shared variable is %d\n", x);
pthread_mutex_unlock(&mutex2);
}
void *writeProcess()
{
pthread_mutex_lock(&mutex1);
pthread_mutex_lock(&mutex2);
int x = shared_variable;
sleep(1);
x++;
shared_variable = x;
printf("In write process, Updated the shared variable to %d\n", x);
pthread_mutex_unlock(&mutex1);
pthread_mutex_unlock(&mutex2);
}
int main()
{
pthread_mutex_init(&mutex1, 0);
pthread_mutex_init(&mutex2, 0);
pthread_t thread1, thread2, thread3;
// pthread_create(&thread2, NULL, &readProcess1, NULL);
// pthread_create(&thread3, NULL, &readProcess2, NULL);
printf("Initial value of shared variable is %d\n", shared_variable);
pthread_create(&thread1, NULL, &writeProcess, NULL);
pthread_create(&thread2, NULL, &readProcess1, NULL);
pthread_create(&thread3, NULL, &readProcess2, NULL);
pthread_join(thread1, NULL);
pthread_join(thread2, NULL);
pthread_join(thread3, NULL);
return 0;
}
| 24.833333 | 70 | 0.708613 |
49b6f0ae61df89e696998cd283c5f90adb711f2e | 3,437 | c | C | a8/a8_p10/a8_p10.c | henrisota/Programming-in-C-and-Cpp | ff09d8b698bf4ed8084a7d24808a642defc4b729 | [
"MIT"
] | null | null | null | a8/a8_p10/a8_p10.c | henrisota/Programming-in-C-and-Cpp | ff09d8b698bf4ed8084a7d24808a642defc4b729 | [
"MIT"
] | null | null | null | a8/a8_p10/a8_p10.c | henrisota/Programming-in-C-and-Cpp | ff09d8b698bf4ed8084a7d24808a642defc4b729 | [
"MIT"
] | 1 | 2021-01-21T19:54:12.000Z | 2021-01-21T19:54:12.000Z | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main () {
FILE *file;
char fileName[64], line[64];
char *tempUsername, *tempPassword, *username, *password;
char *usernames[100];
int i = 0, usernameCount = 0, position = 0, endPositions[100];
scanf("%s", fileName);
getchar();
file = fopen(fileName, "r");
if (file == NULL) { // Check if file was opened successfully
printf("File couldn't be opened!\n");
exit(1);
}
while (fgets(line, sizeof(line), file)) {
// Check if there is a newline character at the end
if (line[strlen(line) - 1] == '\n')
line[strlen(line) - 1] = '\0'; // Substitute for null-terminator
// Else leave it as it is (in case of last line)
// Save end position of line and add 1 to count newline character
position += (((int) strlen(line)) + 1); // + 1 counting newline
endPositions[i] = position;
// Add username to array usernames
if (i % 2 == 0) {
char *user;
user = (char *) malloc(sizeof(char) * strlen(line));
strcpy(user, line);
usernames[i / 2] = user;
usernameCount++; // Increment number of usernames
}
i++;
}
while(1) { // Infinite loop to get new input for username and password
tempUsername = (char *) malloc(sizeof(char) * 64);
tempPassword = (char *) malloc(sizeof(char) * 64);
// Check if malloc was successful
if (tempUsername == NULL || tempPassword == NULL)
exit(1);
scanf("%[^\n]%*c", tempUsername);
username = (char *) malloc(sizeof(char) * strlen(tempUsername));
if (username == NULL)
exit(1);
strcpy(username, tempUsername);
if (strcmp(username, "exit") == 0) {
printf("Exiting ...\n");
free(tempPassword);
free(tempUsername);
free(username);
return 0;
}
scanf("%[^\n]%*c", tempPassword);
password = (char *) malloc(sizeof(char) * strlen(tempPassword));
if (password == NULL) // Check if malloc was successful
exit(1);
strcpy(password, tempPassword);
free(tempUsername);
free(tempPassword);
// Loop until we find username in array or we surpass usernameCount
for (i = 0; i < usernameCount; i++) {
if (strcmp(username, usernames[i]) == 0) {
break;
}
}
// Check if we traversed the whole array of usernames
if (i == usernameCount) { // Username not found
printf("Access to user %s is denied.\n", username);
continue;
} else { // Username found
// Go to position with index 2*i based on username index i
fseek(file, endPositions[2*i], SEEK_SET);
fgets(line, sizeof(line), file); // Get password from file
// Same
if (line[strlen(line) - 1] == '\n')
line[strlen(line) - 1] = '\0';
// Check if inputted password and password in file match
if (strcmp(password, line) == 0)
printf("Access to user %s is granted.\n", username);
else printf("Access to user %s is denied.\n", username);
}
free(username);
free(password);
}
return 0;
} | 34.029703 | 76 | 0.530986 |
a0b52c72c4a2e274df5a158de003dde0438ab1ec | 381 | h | C | srcAmiga/modeler/arexx.h | privatosan/RayStorm | 17e27259a8a1d6b2fcfa16886c6e4cdd81be8cfa | [
"MIT"
] | 2 | 2016-04-03T23:57:54.000Z | 2019-12-05T17:50:37.000Z | srcAmiga/modeler/arexx.h | privatosan/RayStorm | 17e27259a8a1d6b2fcfa16886c6e4cdd81be8cfa | [
"MIT"
] | null | null | null | srcAmiga/modeler/arexx.h | privatosan/RayStorm | 17e27259a8a1d6b2fcfa16886c6e4cdd81be8cfa | [
"MIT"
] | 2 | 2015-06-20T19:22:47.000Z | 2021-11-15T15:22:14.000Z | /***************
* PROGRAM: Modeler
* NAME: arexx.h
* DESCRIPTION: definitions for arexx command class
* AUTHORS: Andreas Heumann
* HISTORY:
* DATE NAME COMMENT
* 16.01.97 ah initial release
***************/
#ifndef AREXX_H
#define AREXX_H
#ifndef MUIDEFS_H
#include "muidefs.h"
#endif
extern struct MUI_Command arexxcmds[];
#endif
| 18.142857 | 53 | 0.60105 |
6f5309f4c89f1b898be182cd076709b1daa71f64 | 165 | c | C | contracts/musl/upstream/src/multibyte/mbstowcs.c | cubetrain/CubeTrain | b930a3e88e941225c2c54219267f743c790e388f | [
"MIT"
] | null | null | null | contracts/musl/upstream/src/multibyte/mbstowcs.c | cubetrain/CubeTrain | b930a3e88e941225c2c54219267f743c790e388f | [
"MIT"
] | null | null | null | contracts/musl/upstream/src/multibyte/mbstowcs.c | cubetrain/CubeTrain | b930a3e88e941225c2c54219267f743c790e388f | [
"MIT"
] | 1 | 2019-09-27T10:22:23.000Z | 2019-09-27T10:22:23.000Z | #include <stdlib.h>
#include <wchar.h>
size_t mbstowcs(wchar_t *restrict ws, const char *restrict s, size_t wn)
{
return mbsrtowcs(ws, (void*)&s, wn, 0);
}
| 20.625 | 73 | 0.660606 |
c0c9959ceea2aed06c0aaa2fe367d0a237ba0729 | 2,244 | c | C | src/table.c | raitosyo/rteipc | a5c99219b5e11a486b449bc1ea07015e3541b62c | [
"MIT"
] | 3 | 2020-07-25T04:51:17.000Z | 2022-03-22T09:09:36.000Z | src/table.c | raitosyo/rteipc | a5c99219b5e11a486b449bc1ea07015e3541b62c | [
"MIT"
] | null | null | null | src/table.c | raitosyo/rteipc | a5c99219b5e11a486b449bc1ea07015e3541b62c | [
"MIT"
] | 1 | 2020-04-07T06:12:29.000Z | 2020-04-07T06:12:29.000Z | // Copyright (c) 2018 Ryosuke Saito All rights reserved.
// MIT licensed
#include <stdlib.h>
#include <string.h>
#include "table.h"
static inline void __set_desc_id(ev_uint64_t *desc, int id)
{
int index = id / DESC_BIT_WIDTH;
ev_uint64_t *bits = &desc[index];
*bits |= (1ull << (id % DESC_BIT_WIDTH));
}
static inline void __clear_desc_id(ev_uint64_t *desc, int id)
{
int index = id / DESC_BIT_WIDTH;
ev_uint64_t *bits = &desc[index];
*bits &= ~(1ull << (id % DESC_BIT_WIDTH));
}
static int __dtbl_next_id(const dtbl_t *table)
{
int width = DESC_BIT_WIDTH;
int start = table->next_entry % width;
int index = table->next_entry / width;
int max = table->max_entries;
ev_uint64_t val;
int i;
if (index >= max)
index = start = 0;
for (;;) {
if (index >= max)
break;
val = table->desc[index];
for (i = start; i < start + width; i++) {
if ((val >> (i % width)) & 1)
continue; // used
return (index * width) + (i % width);
}
index++;
}
return -1;
}
void *dtbl_get(dtbl_t *table, int id)
{
void *retval = NULL;
dtbl_entry_t *e;
node_t *n;
if (!table)
return NULL;
pthread_mutex_lock(&table->lock);
list_each(&table->entry_list, n, {
e = list_entry(n, dtbl_entry_t, node);
if (e->id == id) {
retval = e->value;
break;
}
})
pthread_mutex_unlock(&table->lock);
return retval;
}
int dtbl_set(dtbl_t *table, void *val)
{
dtbl_entry_t *entry;
size_t entry_size;
int id;
if (!table)
return -1;
pthread_mutex_lock(&table->lock);
if (!table->desc) {
entry_size = DESC_BIT_WIDTH * table->max_entries;
table->desc = malloc(entry_size);
if (!table->desc) {
id = -1;
goto out;
}
memset(table->desc, 0, entry_size);
}
id = __dtbl_next_id(table);
if (id < 0)
goto out;
entry = malloc(sizeof(*entry));
if (!entry)
goto out;
entry->id = id;
entry->value = val;
list_push(&table->entry_list, &entry->node);
__set_desc_id(table->desc, id);
table->next_entry = id + 1;
out:
pthread_mutex_unlock(&table->lock);
return id;
}
void dtbl_del(dtbl_t *table, int id)
{
if (table) {
pthread_mutex_lock(&table->lock);
if ((id / DESC_BIT_WIDTH) < table->max_entries)
__clear_desc_id(table->desc, id);
pthread_mutex_unlock(&table->lock);
}
}
| 17.952 | 61 | 0.643048 |
ae12567644d34c7753a34f4fb1307430b4f5e362 | 1,604 | h | C | src/wxTTM/Database/RkStore.h | ttm-tt/wxTTM | f9c75f05a564a0d82034412c1eb4c94d943e267f | [
"MIT"
] | null | null | null | src/wxTTM/Database/RkStore.h | ttm-tt/wxTTM | f9c75f05a564a0d82034412c1eb4c94d943e267f | [
"MIT"
] | null | null | null | src/wxTTM/Database/RkStore.h | ttm-tt/wxTTM | f9c75f05a564a0d82034412c1eb4c94d943e267f | [
"MIT"
] | null | null | null | /* Copyright (C) 2020 Christoph Theis */
// Ranking eines Teams
#ifndef RKSTORE_H
#define RKSTORE_H
#include "StoreObj.h"
struct TmRec;
struct NaRec;
struct CpRec;
struct NaListRec;
struct CpListRec;
struct RkRec
{
long tmID; // Foreign Key TmRec
long naID; // Foreign Key NaRec
short rkNatlRank; // Nationales Ranking
short rkIntlRank; // Internationales Ranking (?)
short rkDirectEntry; // Flag direct entry
RkRec() {Init();}
void Init() {memset(this, 0, sizeof(RkRec));}
};
class RkStore : public StoreObj, public RkRec
{
public:
static bool CreateTable();
static bool UpdateTable(long version);
static bool CreateConstraints();
static bool UpdateConstraints(long version);
public:
RkStore(const RkRec &, Connection * = 0);
RkStore(Connection * = 0);
~RkStore();
virtual void Init();
public:
bool Insert();
bool Insert(const TmRec &tm, const NaRec &na, short natlRank = 0, short intlRank = 0);
bool Remove(const TmRec &tm);
bool Remove(const CpRec &cp);
bool Remove(const CpRec &cp, const NaRec &na);
bool Remove(const CpListRec &cp, const NaListRec &na);
bool SelectByTm(const TmRec &);
bool SelectByRanking(const CpRec &, const NaRec &, int rank);
bool SelectByRanking(const TmRec &, const NaRec &, int rank);
private:
short GetNextNatlRank(const NaRec &, const TmRec &, short intlRank = 0);
bool ExistsNatlRank(const NaRec &, const TmRec &, short natlRank);
wxString SelectString() const;
bool BindRec();
};
#endif | 25.0625 | 91 | 0.657107 |
acc4de29c114e40b8c3db03df8a9482072479c8c | 4,976 | h | C | MFBPHTTP/src/Net/KLCSHttpClient.h | Walker2020/MFBPHTTP | 74b345d7d6207abc634f7bd65d523fb12f6636c6 | [
"MIT"
] | 1 | 2020-06-28T02:40:07.000Z | 2020-06-28T02:40:07.000Z | MFBPHTTP/src/Net/KLCSHttpClient.h | Walker2020/MFBP | 74b345d7d6207abc634f7bd65d523fb12f6636c6 | [
"MIT"
] | null | null | null | MFBPHTTP/src/Net/KLCSHttpClient.h | Walker2020/MFBP | 74b345d7d6207abc634f7bd65d523fb12f6636c6 | [
"MIT"
] | null | null | null | //
// KLCSHttpClient.h
// AFNetworking
//
// Created by DengJinHui on 2019/11/14.
//
#import <Foundation/Foundation.h>
#import "AFNetworking.h"
#import "KLCSJSONObject.h"
#import "KLCSJSONArray.h"
typedef void(^KLCSHttpSessionTaskFailure)(NSString *_Nonnull resultCode, NSString *_Nonnull resultMessage, NSError *_Nonnull error);
typedef void(^KLCSHttpSessionTaskSuccess)(id _Nonnull resultData);
typedef void(^KLCSHttpSessionTaskProgress)(NSProgress * _Nullable progress);
typedef void(^KLCSHttpCompletionHandler)(void);
typedef enum : NSUInteger {
KLCSHttpMethodGET,
KLCSHttpMethodPOST,
} KLCSHttpMethod;
@interface KLCSHttpClient : NSObject
@property(nonatomic, assign)BOOL isShowLoading;
@property(nonatomic, assign)BOOL isShowErroToast;
@property(nonatomic, copy) NSString * _Nullable loadingMaskText;
+(KLCSHttpClient * _Nonnull)instance;
-(void)POSTWithURLString:(NSString * _Nullable)URLString
parameters:(NSDictionary *_Nullable)parameters
success:(KLCSHttpSessionTaskSuccess _Nullable)success
failure:(KLCSHttpSessionTaskFailure _Nullable)failure;
-(void)POSTWithURLString:(NSString * _Nullable)URLString
parameters:(NSDictionary * _Nullable)parameters
isShowLoading:(BOOL)isShowLoading
success:(KLCSHttpSessionTaskSuccess _Nullable)success
failure:(KLCSHttpSessionTaskFailure _Nullable)failure;
-(void)POSTWithURLString:(NSString * _Nullable)URLString
parameters:(NSDictionary * _Nullable)parameters
isShowLoading:(BOOL)isShowLoading
isShowErrorMessage:(BOOL)isShowErrorMessage
success:(KLCSHttpSessionTaskSuccess _Nullable)success
failure:(KLCSHttpSessionTaskFailure _Nullable)failure;
-(void)GETWithURLString:(NSString * _Nullable)URLString
parameters:(NSDictionary * _Nullable)parameters
success:(KLCSHttpSessionTaskSuccess _Nullable)success
failure:(KLCSHttpSessionTaskFailure _Nullable)failure;
-(void)GETWithURLString:(NSString *_Nullable)URLString
parameters:(nullable NSDictionary *)parameters
isShowLoading:(BOOL)isShowLoading
success:(KLCSHttpSessionTaskSuccess _Nullable )success
failure:(KLCSHttpSessionTaskFailure _Nullable )failure;
-(void)GETWithURLString:(NSString *_Nullable)URLString
parameters:(nullable NSDictionary *)parameters
isShowLoading:(BOOL)isShowLoading
isShowErrorMessage:(BOOL)isShowErrorMessage
success:(KLCSHttpSessionTaskSuccess _Nullable )success
failure:(KLCSHttpSessionTaskFailure _Nullable )failure;
-(void)requestWithMethod:(NSString * _Nullable)method
URLString:(NSString * _Nullable)URLString
parameters:(NSDictionary * _Nullable)parameters
success:(KLCSHttpSessionTaskSuccess _Nullable)success
failure:(KLCSHttpSessionTaskFailure _Nullable)failure;
-(void)requestWithMethod:(NSString * _Nullable)method
URLString:(NSString * _Nullable)URLString
parameters:(NSDictionary * _Nullable)parameters
isShowLoading:(BOOL)isShowLoading
success:(KLCSHttpSessionTaskSuccess _Nullable)success
failure:(KLCSHttpSessionTaskFailure _Nullable)failure;
-(void)requestWithMethod:(NSString * _Nullable)method
URLString:(NSString * _Nullable)URLString
parameters:(NSDictionary * _Nullable)parameters
isShowLoading:(BOOL)isShowLoading
isShowErrorMessage:(BOOL)isShowErrorMessage
success:(KLCSHttpSessionTaskSuccess _Nullable)success
failure:(KLCSHttpSessionTaskFailure _Nullable)failure;
-(void)requestWithMethod:(NSString * _Nullable)method
URLString:(NSString * _Nullable)URLString
parameters:(NSDictionary * _Nullable)parameters
uploadProgress:(KLCSHttpSessionTaskProgress _Nullable)uploadProgress
downloadProgress:(KLCSHttpSessionTaskProgress _Nullable)downloadProgress
success:(KLCSHttpSessionTaskSuccess _Nullable)success
failure:(KLCSHttpSessionTaskFailure _Nullable)failure;
-(void)requestWithMethod:(NSString *_Nullable)method
URLString:(NSString *_Nullable)URLString
parameters:(NSDictionary *_Nullable)parameters
isShowLoading:(BOOL)isShowLoading
isShowErrorMessage:(BOOL)isShowErrorMessage
loadingMaskText:(NSString *_Nullable)loadingMaskText
timeoutInternal:(NSTimeInterval)timeoutInternal
uploadProgress:(KLCSHttpSessionTaskProgress _Nullable)uploadProgress
downloadProgress:(KLCSHttpSessionTaskProgress _Nullable)downloadProgress
success:(KLCSHttpSessionTaskSuccess _Nullable)success
failure:(KLCSHttpSessionTaskFailure _Nullable)failure;
@end
| 41.815126 | 132 | 0.725884 |
3a7eff6e8f5ca61cc5350c5fb4c6509420181f9e | 9,406 | h | C | include/YIMService.h | islandCw/IMSDK_iOS | 1e0a28c8d4885683ed4272c04fffa592913ef971 | [
"MIT"
] | null | null | null | include/YIMService.h | islandCw/IMSDK_iOS | 1e0a28c8d4885683ed4272c04fffa592913ef971 | [
"MIT"
] | null | null | null | include/YIMService.h | islandCw/IMSDK_iOS | 1e0a28c8d4885683ed4272c04fffa592913ef971 | [
"MIT"
] | null | null | null | //
// YIMService.m
// YoumeIMUILib
//
// Created by 余俊澎 on 16/8/11.
// Copyright © 2016年 余俊澎. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "YIMCallbackProtocol.h"
#define YOUME_IM_NEW_MESSSAGE_NOTIFI @"im.youme.YOUME_IM_NEW_MESSSAGE_NOTIFI"
#define YOUME_IM_AVATAR_CLICK_NOTIFI @"im.youme.YOUME_IM_AVATAR_CLICK_NOTIFI"
#define YOUME_IM_CLOSE_NOTIFI @"im.youme.YOUME_IM_CLOSE_NOTIFI"
#define YOUME_IM_SEND_MESSAGE_NOTIFI @"im.youme.YOUME_IM_SEND_MESSAGE_NOTIFI"
#define YOUME_IM_PHOTO_SIZE 80
@interface YIMService : NSObject
+(YIMService*)GetInstance;
+(NSString*) filterKeyWorks:(NSString*)originContent level:(int*) level;
//设置语言缓存目录
+(void) SetAudioCacheDir:(NSString*) path;
//设置服务器区域
+(void) SetServerZone:(YouMeIMServerZoneOC) zone;
-(void)SetDelegate:(id<YIMCallbackProtocol>) outDelegate;
//初始化
-(YIMErrorcodeOC)InitWithAppKey:(NSString *)strAppKey appSecurityKey:(NSString*)strAppSecurity;
-(YIMErrorcodeOC) Login:(NSString *)userName password:(NSString *)password token:(NSString*) token ;
-(YIMErrorcodeOC) JoinChatRoom:(NSString *)roomID;
-(YIMErrorcodeOC) LeaveChatRoom:(NSString *)roomID;
-(YIMErrorcodeOC) LeaveAllChatRooms;
-(YIMErrorcodeOC) GetRoomMemberCount:(NSString *)roomID;
//发送文本消息
-(YIMErrorcodeOC) SendTextMessage:(NSString *)receiverID chatType:(YIMChatTypeOC)chatType msgContent:(NSString *) msgContent attachParam:(NSString *)attachParam requestID:(unsigned long long *)requestID;
//发送语音消息(语音转文字)
-(YIMErrorcodeOC) StartRecordAudioMessage:(NSString *)receiverID chatType:(YIMChatTypeOC)chatType requestID:(unsigned long long *)requestID;
//发送语音消息(语音不转文字)
-(YIMErrorcodeOC) StartOnlyRecordAudioMessage:(NSString *)receiverID chatType:(YIMChatTypeOC)chatType requestID:(unsigned long long *)requestID;
//停止并发送语音
-(YIMErrorcodeOC) StopAndSendAudioMessage:(NSString *)attachMsg;
//取消语音
-(YIMErrorcodeOC) CancleAudioMessage;
//NSArray<NSString*>
-(YIMErrorcodeOC) MultiSendTextMessage:( NSArray * )receivers text:(NSString *) text;
//发送自定义消息
-(YIMErrorcodeOC) SendCustomMessage:(NSString*) receiverID chatType:(YIMChatTypeOC)chatType content:(NSData*)content requestID:(unsigned long long *)requestID;
//发送文件
-(YIMErrorcodeOC) SendFile:(NSString*) receiverID chatType:(YIMChatTypeOC)chatType filePath:(NSString*)filePath requestID:(unsigned long long *)requestID extraParam:(NSString*)extraParam fileType:(YIMFileTypeOC)fileType;
//extraParam:附加参数 格式为json {"nickname":"","server_area":"","location":"","score":"","level":"","vip_level":"","extra":""}
-(YIMErrorcodeOC) SendGift:(NSString*)anchorID channel:(NSString*)channel giftId:(int)giftId giftCount:(int)giftCount extraParam:(NSString*) extraParam requestID:(unsigned long long *)requestID ;
//查询消息记录(direction 查询方向 0:向前查找 1:向后查找)
-(YIMErrorcodeOC) QueryHistoryMessage:(NSString*) targetID chatType:(YIMChatTypeOC) chatType startMessageID:(unsigned long long)startMessageID count:(int)count direction:(int)direction;
/*清理消息记录
YIMChatType:私聊消息、房间消息
time:删除指定时间之前的消息*/
-(YIMErrorcodeOC) DeleteHistoryMessage:(YIMChatTypeOC)chatType time:(unsigned long long)time;
//删除指定messageID对应消息
-(YIMErrorcodeOC) DeleteHistoryMessageByID:(unsigned long long)messageID;
//删除指定用户的本地消息历史记录,保留指定的消息ID列表记录
- (YIMErrorcodeOC) DeleteSpecifiedHistoryMessage:(NSString*)targetID chatType:(YIMChatTypeOC)chatType excludeMesList:(NSMutableArray *)excludeMesList;
//查询房间历史消息(房间最近N条聊天记录)
-(YIMErrorcodeOC) QueryRoomHistoryMessageFromServer:(NSString*)roomID count:(int)count direction:(int)direction;
//开始语音(不通过游密发送该语音消息,由调用方发送,调用StopAudioSpeech完成语音及上传后会回调OnStopAudioSpeechStatus)
-(YIMErrorcodeOC) StartAudioSpeech:(unsigned long long *)requestID translate:(bool)translate;
//停止语音(不通过游密发送该语音消息,由调用方发送,完成语音及上传后会回调OnStopAudioSpeechStatus)
-(YIMErrorcodeOC) StopAudioSpeech;
//转换AMR格式到WAV格式
-(YIMErrorcodeOC) ConvertAMRToWav:(NSString*)amrFilePath wavFielPath:(NSString*)wavFielPath;
//是否自动下载语音消息(true: 自动下载 false: 不自动下载(默认)),下载的路径是默认路径,下载回调中可以得到
-(YIMErrorcodeOC) SetDownloadAudioMessageSwitch:(bool)download;
//是否自动接收消息(true:自动接收(默认) false:不自动接收消息,有新消息达到时,SDK会发出OnReceiveMessageNotify回调,调用方需要调用GetMessage获取新消息)
//targets:房间ID(NSArray<NSString*>)
-(YIMErrorcodeOC) SetReceiveMessageSwitch:( NSArray * )targets receive:(bool)receive;
//获取新消息(只有SetReceiveMessageSwitch设置为不自动接收消息,才需要在收到OnReceiveMessageNotify回调时调用该函数)
//targets:房间ID(NSArray<NSString*>)
-(YIMErrorcodeOC) GetNewMessage:( NSArray * )targets ;
//是否保存房间消息记录(默认不保存)
//targets:房间ID(NSArray<NSString*>)
-(YIMErrorcodeOC) SetRoomHistoryMessageSwitch:( NSArray * )targets save:(bool)save;
// 文本翻译
-(YIMErrorcodeOC) TranslateText:(unsigned int*) requestID text:(NSString*)text destLangCode:(LanguageCodeOC) destLangCode srcLangCode:(LanguageCodeOC) srcLangCode;
//屏蔽/解除屏蔽用户消息
-(YIMErrorcodeOC) BlockUser:(NSString*) userID block:(bool) block;
//解除所有已屏蔽用户
-(YIMErrorcodeOC) UnBlockAllUser;
//获取被屏蔽消息用户
-(YIMErrorcodeOC) GetBlockUsers;
//消息传输类型开关
-(YIMErrorcodeOC) SwitchMsgTransType:(YIMMsgTransTypeOC) transType;
//获取最近联系人(最大100条)
-(YIMErrorcodeOC) GetRecentContacts;
//设置用户信息
//格式为json {"nickname":"","server_area":"","location":"","level":"","vip_level":""} (以上五个必填,可以添加其他字段)
-(YIMErrorcodeOC) SetUserInfo:(NSString*) userInfo;
//查询用户信息
-(YIMErrorcodeOC) GetUserInfo:( NSString * )userID;
//查询用户在线状态
-(YIMErrorcodeOC) QueryUserStatus:( NSString * )userID;
//程序切到后台运行
-(void) OnPause:(bool)pauseReceiveMessage;
//程序切到前台运行
-(void) OnResume;
//设置播放语音音量(volume:0.0-1.0)
- (void) SetVolume:(float) volume;
//播放语音
- (YIMErrorcodeOC) StartPlayAudio:(NSString* ) path;
//停止语音播放
- (YIMErrorcodeOC) StopPlayAudio;
//查询播放状态
- (bool) IsPlaying;
//获取语音缓存目录
- (NSString*) GetAudioCachePath;
//清理语音缓存目录(注意清空语音缓存目录后历史记录中会无法读取到音频文件,调用清理历史记录接口也会自动删除对应的音频缓存文件)
- (bool) ClearAudioCachePath;
-(YIMErrorcodeOC) Logout;
//下载语音或者文件
-(YIMErrorcodeOC) DownloadAudio:(unsigned long long) ulSerial strSavePath:(NSString*)strSavePath;
-(YIMErrorcodeOC) DownloadFileByUrl:(NSString*) downloadURL strSavePath:(NSString*)strSavePath fileType:(YIMFileTypeOC)fileType;
// 获取当前地理位置
-(YIMErrorcodeOC) GetCurrentLocation;
// 获取附近的目标 count:获取数量(一次最大200) serverAreaID:区服 districtlevel:行政区划等级 resetStartDistance:是否重置查找起始距离
-(YIMErrorcodeOC) GetNearbyObjects:(int) count serverAreaID:(NSString*)serverAreaID districtlevel:(YouMeDistrictLevelOC)districtlevel resetStartDistance:(bool)resetStartDistance;
-(YIMErrorcodeOC) GetDistance:(NSString*)userID;
// 设置位置更新间隔(单位:分钟)
-(void) SetUpdateInterval:(unsigned int) interval;
// 获取麦克风状态
- (void) GetMicrophoneStatus;
// 查询公告
- (YIMErrorcodeOC) QueryNotice;
//设置语音识别语言
- (YIMErrorcodeOC) SetSpeechRecognizeLanguage:(SpeechLanguageOC) language;
//设置仅识别语音文字,不发送语音消息; false:识别语音文字并发送语音消息,true:仅识别语音文字
- (YIMErrorcodeOC) SetOnlyRecognizeSpeechText:(bool)recognition;
//举报
// source:举报来源 reason:举报原因 description:举报详细描写 extraParam:附加参数(JSON格式 {"nickname":"","server_area":"","level":"","vip_level":""})
- (YIMErrorcodeOC) Accusation:(NSString*)userID source:(YIMChatTypeOC)source reason:(int)reason description:(NSString*)description extraParam:(NSString*)extraParam;
- (YIMErrorcodeOC) GetForbiddenSpeakInfo;
- (YIMErrorcodeOC) SetDownloadDir:(NSString*) path;
- (YIMErrorcodeOC) SetMessageRead:(unsigned long long)msgID read:(bool)read;
//用户信息管理
// 设置用户信息 userInfo(昵称,性别,个性签名,国家,省份,城市,扩展信息)
- (YIMErrorcodeOC) SetUserProfileInfo:(IMUserSettingInfoOC*) userInfo;
// 查询用户信息 userID为“”时查询自己的信息
- (YIMErrorcodeOC) GetUserProfileInfo:(NSString*) userID;
- (UIImage *)ReSizeImage:(UIImage *)image toSize:(CGSize)resize;
// 设置用户头像 photoPath - 本地图片的绝对路径
- (YIMErrorcodeOC) SetUserProfilePhoto:(NSString*) photoPath;
// 切换用户在线状态 userStatus,0-在线 1-离线 2-隐身
- (YIMErrorcodeOC) SwitchUserStatus:(NSString*) userID userStatus:(YIMUserStatusOC) userStatus;
// 设置被添加权限 beFound,true-能被查找,false-不能被查找
// beAddPermission, 0-不允许被添加, 1-需要验证, 2-允许被添加,不需要验证
- (YIMErrorcodeOC) SetAddPermission:(bool) beFound beAddPermission:(IMUserBeAddPermissionOC) beAddPermission;
/************* 好友接口 *****************/
/*
* 功能:查找添加好友(获取用户简要信息)
* @param findType:查找类型 0:按ID查找 1:按昵称查找
* @param target:对应查找类型用户ID或昵称
* @return 错误码
*/
- (YIMErrorcodeOC) FindUser:(int) findType target:(NSString*) target;
/*
* 功能:添加好友
* @param userID:用户ID(NSArray<NSString*>)
* @param comments:备注或验证信息(长度最大128)
* @return 错误码
*/
- (YIMErrorcodeOC) RequestAddFriend:(NSArray *) users comments:(NSString*) comments;
/*
* 功能:处理被请求添加好友
* @param userID:用户ID
* @param dealResult:处理结果 0:同意 1:拒绝
* @return 错误码
*/
- (YIMErrorcodeOC) DealBeRequestAddFriend:(NSString*) userID dealResult:(int) dealResult reqID:(unsigned long long)reqID;
/*
* 功能:删除好友
* @param users:用户ID(NSArray<NSString*>)
* @param deleteType:删除类型 0:双向删除 1:单向删除(删除方在被删除方好友列表依然存在)
* @return 错误码
*/
- (YIMErrorcodeOC) DeleteFriend:(NSArray *) users deleteType:(int) deleteType;
/*
* 功能:拉黑好友
* @param type:0:拉黑 1:解除拉黑
* @param users:用户ID(NSArray<NSString*>)
* @return 错误码
*/
- (YIMErrorcodeOC) BlackFriend:(int) type users:(NSArray *) users;
/*
* 功能:查询我的好友
* @param type:0:正常好友 1:被拉黑好友
* @param startIndex:起始序号
* @param count:数量(一次最大100)
* @return 错误码
*/
- (YIMErrorcodeOC) QueryFriends:(int) type startIndex:(int) startIndex count:(int) count;
/*
* 功能:查询好友请求列表
* @param startIndex:起始序号
* @param count:数量(一次最大20)
* @return 错误码
*/
- (YIMErrorcodeOC) QueryFriendRequestList:(int) startIndex count:(int) count;
-(void)RebindIMCallback;
@end
| 35.764259 | 220 | 0.776738 |
1d5cf56099ef3dd907341b94808633d281f0e959 | 69,576 | c | C | legacy/src/ext_mpi_alltoall.c | rayastoyanova/ext_mpi_collectives | 9f9e48cf40238d3e91af6471c32f620630365b7d | [
"BSD-3-Clause"
] | 9 | 2018-10-03T10:06:29.000Z | 2022-03-04T16:19:03.000Z | legacy/src/ext_mpi_alltoall.c | rayastoyanova/ext_mpi_collectives | 9f9e48cf40238d3e91af6471c32f620630365b7d | [
"BSD-3-Clause"
] | null | null | null | legacy/src/ext_mpi_alltoall.c | rayastoyanova/ext_mpi_collectives | 9f9e48cf40238d3e91af6471c32f620630365b7d | [
"BSD-3-Clause"
] | 1 | 2021-11-24T12:21:09.000Z | 2021-11-24T12:21:09.000Z | #include "ext_mpi_alltoall.h"
#include "ext_mpi_alltoall_native.h"
#include <math.h>
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BREAK_SIZE 25000
#define MERGE_SIZE 250
typedef struct _FileData {
int nnodes;
int nports;
int parallel;
int msize;
double deltaT;
} FileData;
static FileData *file_input;
static int file_input_max, file_input_max_per_core;
static int is_initialised = 0;
int enforce_bruck = 0;
int copyin_method = 0;
int threshold_rabenseifner = 10000;
int *fixed_factors = NULL;
int *fixed_factors_limit = NULL;
int fixed_tile_size_row = 0;
int fixed_tile_size_column = 0;
static void read_env() {
int mpi_comm_rank, mpi_comm_size, var, i, j;
char *c;
MPI_Comm_rank(MPI_COMM_WORLD, &mpi_comm_rank);
MPI_Comm_size(MPI_COMM_WORLD, &mpi_comm_size);
if (mpi_comm_rank == 0) {
var = ((c = getenv("EXT_MPI_FIXED_TILE_SIZE_ROW")) != NULL);
if (var) {
sscanf(c, "%d", &fixed_tile_size_row);
printf("fixed tile size row %d\n", fixed_tile_size_row);
}
}
MPI_Bcast(&fixed_tile_size_row, 1, MPI_INT, 0, MPI_COMM_WORLD);
if (mpi_comm_rank == 0) {
var = ((c = getenv("EXT_MPI_FIXED_TILE_SIZE_COLUMN")) != NULL);
if (var) {
sscanf(c, "%d", &fixed_tile_size_column);
printf("fixed tile size column %d\n", fixed_tile_size_column);
}
}
MPI_Bcast(&fixed_tile_size_column, 1, MPI_INT, 0, MPI_COMM_WORLD);
if (mpi_comm_rank == 0) {
var = ((c = getenv("EXT_MPI_THRESHOLD_RABENSEIFNER")) != NULL);
if (var) {
sscanf(c, "%d", &threshold_rabenseifner);
printf("threshold Rabenseifer %d\n", threshold_rabenseifner);
}
}
MPI_Bcast(&threshold_rabenseifner, 1, MPI_INT, 0, MPI_COMM_WORLD);
if (mpi_comm_rank == 0) {
var = ((c = getenv("EXT_MPI_ENFORCE_BRUCK")) != NULL);
if (var) {
if ((c[0] != '0') && (c[0] != 'F')) {
enforce_bruck = 1;
printf("Bruck enforced\n");
}
}
}
MPI_Bcast(&enforce_bruck, 1, MPI_INT, 0, MPI_COMM_WORLD);
if (mpi_comm_rank == 0) {
var = ((c = getenv("EXT_MPI_COPYIN_METHOD")) != NULL);
if (var) {
if (c[0] == '1') {
copyin_method = 1;
printf("copy in short\n");
}
if (c[0] == '2') {
copyin_method = 2;
printf("copy in long\n");
}
}
}
MPI_Bcast(©in_method, 1, MPI_INT, 0, MPI_COMM_WORLD);
if (mpi_comm_rank == 0) {
var = ((c = getenv("EXT_MPI_FIXED_FACTORS")) != NULL);
}
MPI_Bcast(&var, 1, MPI_INT, 0, MPI_COMM_WORLD);
if (var && (fixed_factors != NULL)) {
free(fixed_factors);
}
if (var) {
i = 1;
j = 2;
while (i < mpi_comm_size) {
j++;
i *= 2;
}
fixed_factors = (int *)malloc(j * sizeof(int));
if (mpi_comm_rank == 0) {
i = 0;
j = 0;
while (c[i] != 0) {
sscanf(c, "%d", &fixed_factors[j]);
j++;
while ((c[i] != 0) && (c[i] != ',')) {
c++;
}
if (c[i] == ',') {
c++;
}
}
}
fixed_factors[j++] = 0;
MPI_Bcast(&j, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Bcast(fixed_factors, j, MPI_INT, 0, MPI_COMM_WORLD);
}
if (mpi_comm_rank == 0) {
var = ((c = getenv("EXT_MPI_FIXED_FACTORS_LIMIT")) != NULL);
}
MPI_Bcast(&var, 1, MPI_INT, 0, MPI_COMM_WORLD);
if (var && (fixed_factors_limit != NULL)) {
free(fixed_factors_limit);
}
if (var) {
i = 1;
j = 2;
while (i < mpi_comm_size) {
j++;
i *= 2;
}
fixed_factors_limit = (int *)malloc(j * sizeof(int));
if (mpi_comm_rank == 0) {
i = 0;
j = 0;
while (c[i] != 0) {
sscanf(c, "%d", &fixed_factors_limit[j]);
j++;
while ((c[i] != 0) && (c[i] != ',')) {
c++;
}
if (c[i] == ',') {
c++;
}
}
}
fixed_factors_limit[j++] = 0;
MPI_Bcast(&j, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Bcast(fixed_factors_limit, j, MPI_INT, 0, MPI_COMM_WORLD);
}
}
static void read_bench() {
FileData *file_input_raw;
char lstring[10000];
double distance;
int file_input_max_raw, file_input_max_per_core_raw;
int cores, i, j, mpi_comm_rank, mpi_comm_size, fallback;
file_input_max_raw = 0;
MPI_Comm_rank(MPI_COMM_WORLD, &mpi_comm_rank);
MPI_Comm_size(MPI_COMM_WORLD, &mpi_comm_size);
fallback = 0;
MPI_Bcast(&fallback, 1, MPI_INT, 0, MPI_COMM_WORLD);
if (!fallback) {
if (mpi_comm_rank == 0) {
#include "latency_bandwidth.tmp"
file_input_max_per_core_raw =
file_input_max_raw / file_input_raw[file_input_max_raw - 1].nports;
distance = file_input_raw[1].msize - file_input_raw[0].msize;
file_input_max_per_core = (file_input_raw[file_input_max_raw - 1].msize -
file_input_raw[0].msize) /
distance;
file_input_max = file_input_max_per_core *
file_input_raw[file_input_max_raw - 1].nports;
file_input = (FileData *)malloc(file_input_max * sizeof(*file_input));
for (cores = 1; cores <= file_input_raw[file_input_max_raw - 1].nports;
cores++) {
j = 0;
for (i = 0; i < file_input_max_per_core; i++) {
for (; file_input_raw[j].msize <
i * distance + file_input_raw[0].msize &&
j < file_input_max_per_core_raw;
j++) {
}
if (j == file_input_max_per_core_raw) {
file_input[i + file_input_max_per_core * (cores - 1)] =
file_input_raw[j + file_input_max_per_core_raw * (cores - 1)];
} else {
if (j == 0) {
file_input[i + file_input_max_per_core * (cores - 1)] =
file_input_raw[j + file_input_max_per_core_raw * (cores - 1)];
} else {
file_input[i + file_input_max_per_core * (cores - 1)].nnodes =
file_input_raw[j + file_input_max_per_core_raw * (cores - 1)]
.nnodes;
file_input[i + file_input_max_per_core * (cores - 1)].nports =
file_input_raw[j + file_input_max_per_core_raw * (cores - 1)]
.nports;
file_input[i + file_input_max_per_core * (cores - 1)].parallel =
file_input_raw[j + file_input_max_per_core_raw * (cores - 1)]
.parallel;
file_input[i + file_input_max_per_core * (cores - 1)].msize =
i * distance + file_input_raw[0].msize;
file_input[i + file_input_max_per_core * (cores - 1)].deltaT =
file_input_raw[j - 1 +
file_input_max_per_core_raw * (cores - 1)]
.deltaT +
(file_input[i + file_input_max_per_core * (cores - 1)].msize -
file_input_raw[j - 1 +
file_input_max_per_core_raw * (cores - 1)]
.msize) *
(file_input_raw[j +
file_input_max_per_core_raw * (cores - 1)]
.deltaT -
file_input_raw[j - 1 +
file_input_max_per_core_raw * (cores - 1)]
.deltaT) /
(file_input_raw[j +
file_input_max_per_core_raw * (cores - 1)]
.msize -
file_input_raw[j - 1 +
file_input_max_per_core_raw * (cores - 1)]
.msize);
}
}
}
}
free(file_input_raw);
for (i = 0; i < file_input_max / file_input_max_per_core; i++) {
for (j = file_input_max_per_core - 1 - 1; j >= 0; j--) {
if (file_input[j + i * file_input_max_per_core].deltaT >
file_input[(j + 1) + i * file_input_max_per_core].deltaT) {
file_input[j + i * file_input_max_per_core].deltaT =
file_input[(j + 1) + i * file_input_max_per_core].deltaT;
}
}
}
}
MPI_Bcast(&file_input_max, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Bcast(&file_input_max_per_core, 1, MPI_INT, 0, MPI_COMM_WORLD);
if (mpi_comm_rank != 0) {
file_input = (FileData *)malloc(file_input_max * sizeof(*file_input));
}
MPI_Bcast(file_input, file_input_max * sizeof(*file_input), MPI_CHAR, 0,
MPI_COMM_WORLD);
} else {
i = 1;
j = 2;
while (i < mpi_comm_size) {
j++;
i *= 2;
}
fixed_factors = (int *)malloc((j + 1) * sizeof(int));
for (i = 0; i < j; i++) {
fixed_factors[i] = 2;
}
fixed_factors[j] = -1;
}
}
static double cost_recursive(int p, double n, int fac, int port_max,
int *rarray) {
double T, T_min, ma, mb;
int r, i, j, k, tarray[p + 1];
T_min = 1e60;
if (port_max > file_input[file_input_max - 1].nports) {
port_max = file_input[file_input_max - 1].nports;
}
if (port_max > (p - 1) / fac + 1) {
port_max = (p - 1) / fac + 1;
}
if (port_max < 1) {
port_max = 1;
}
for (i = 1; i <= port_max; i++) {
r = i + 1;
ma = fac;
if (ma * r > p) {
ma = (p - ma) / (r - 1);
}
mb = n * ma;
mb /= file_input[(r - 1 - 1) * file_input_max_per_core].parallel;
j = floor(mb / (file_input[1].msize - file_input[0].msize)) - 1;
k = j + 1;
if (j < 0) {
T = file_input[0 + (r - 1 - 1) * file_input_max_per_core].deltaT;
} else {
if (k >= file_input_max_per_core) {
T = file_input[file_input_max_per_core - 1 +
(r - 1 - 1) * file_input_max_per_core]
.deltaT *
mb /
file_input[file_input_max_per_core - 1 +
(r - 1 - 1) * file_input_max_per_core]
.msize;
} else {
T = file_input[j + (r - 1 - 1) * file_input_max_per_core].deltaT +
(mb - file_input[j + (r - 1 - 1) * file_input_max_per_core].msize) *
(file_input[k + (r - 1 - 1) * file_input_max_per_core].deltaT -
file_input[j + (r - 1 - 1) * file_input_max_per_core].deltaT) /
(file_input[k + (r - 1 - 1) * file_input_max_per_core].msize -
file_input[j + (r - 1 - 1) * file_input_max_per_core].msize);
}
}
if (fac * r < p) {
T += cost_recursive(p, n, fac * r, port_max, tarray + 1);
} else {
tarray[1] = 0;
}
if (T < T_min) {
T_min = T;
tarray[0] = r;
j = 0;
while (tarray[j] > 0) {
rarray[j] = tarray[j];
j++;
}
rarray[j] = 0;
}
}
return (T_min);
}
static void cost_explicit(int p, double n, int port_max, int *rarray) {
double T, T_min, ma, mb;
int r, i, j, k, l, rr;
if (port_max > file_input[file_input_max - 1].nports) {
port_max = file_input[file_input_max - 1].nports;
}
if (port_max < 1) {
port_max = 1;
}
l = 0;
ma = 1;
rr = 1;
while (rr < p) {
T_min = 1e60;
for (i = 1; i <= port_max; i++) {
r = i + 1;
mb = n * rr;
mb /= file_input[(r - 1 - 1) * file_input_max_per_core].parallel;
j = floor(mb / (file_input[1].msize - file_input[0].msize)) - 1;
k = j + 1;
if (j < 0) {
T = file_input[0 + (r - 1 - 1) * file_input_max_per_core].deltaT;
} else {
if (k >= file_input_max_per_core) {
T = file_input[file_input_max_per_core - 1 +
(r - 1 - 1) * file_input_max_per_core]
.deltaT *
mb /
file_input[file_input_max_per_core - 1 +
(r - 1 - 1) * file_input_max_per_core]
.msize;
} else {
T = file_input[j + (r - 1 - 1) * file_input_max_per_core].deltaT +
(mb -
file_input[j + (r - 1 - 1) * file_input_max_per_core].msize) *
(file_input[k + (r - 1 - 1) * file_input_max_per_core]
.deltaT -
file_input[j + (r - 1 - 1) * file_input_max_per_core]
.deltaT) /
(file_input[k + (r - 1 - 1) * file_input_max_per_core].msize -
file_input[j + (r - 1 - 1) * file_input_max_per_core].msize);
}
T /= r;
}
if (T < T_min) {
T_min = T;
rarray[l] = r;
}
}
rr *= rarray[l];
l++;
}
}
struct prime_factors {
int prime;
int count;
};
static void prime_rost(int max_number, int *primes) {
int i, j;
for (i = 0; i < max_number; i++) {
primes[i] = 1;
}
for (i = 2; i < max_number; i++) {
if (primes[i]) {
for (j = 2; i * j < max_number; j++) {
primes[i * j] = 0;
}
}
}
}
static int prime_factor_decomposition(int number,
struct prime_factors *factors) {
int primes[number + 2], max_factor, i, j;
for (i = 0; i < number + 1; i++) {
factors[i].count = factors[i].prime = 0;
}
prime_rost(number + 1, primes);
max_factor = 0;
for (i = 2; i < number + 1; i++) {
if (primes[i]) {
factors[max_factor++].prime = i;
}
}
for (i = 0; i < max_factor; i++) {
j = number;
while (j % factors[i].prime == 0) {
j /= factors[i].prime;
factors[i].count++;
}
}
return (max_factor);
}
static void communication_factors_sub(int number, int max_factor, int mmm,
int *factors, int *max_factors) {
struct prime_factors primes[number];
int max_primes, i, j, k, l, m, n, o;
max_primes = prime_factor_decomposition(number, primes);
j = 0;
for (i = max_primes - 1; i >= 0; i--) {
while (primes[i].count > 0) {
primes[i].count--;
if (primes[i].prime > max_factor) {
k = ceil(log(primes[i].prime) / log(max_factor));
l = exp(log(primes[i].prime) / k) + 1;
for (m = 0; m < k; m++) {
factors[j] = l;
max_factors[j++] = primes[i].prime;
}
if (mmm) {
m = 1;
o = 1;
while (m) {
m = 0;
for (n = i; n >= 0; n--) {
if ((primes[n].count > 0) &&
(primes[n].prime * pow(primes[i].prime, k) <=
pow(max_factor, k))) {
o *= primes[n].prime;
primes[n].count--;
m = 1;
n = -1;
}
}
}
l = ceil(pow(pow(l, k) * o, 1. / k));
for (m = 0; m < k; m++) {
factors[j - m] = l;
}
}
} else {
factors[j] = primes[i].prime;
m = 1;
while (m) {
m = 0;
for (l = i; l >= 0; l--) {
if ((primes[l].count > 0) &&
(factors[j] * primes[l].prime <= max_factor)) {
factors[j] *= primes[l].prime;
primes[l].count--;
m = 1;
l = -1;
}
}
}
max_factors[j] = factors[j];
j++;
}
}
}
factors[j] = max_factors[j] = 0;
}
static void communication_factors(int number, int max_factor, int *factors,
int *max_factors) {
int a, b, as, bs;
if (number == 1) {
factors[0] = 1;
} else {
communication_factors_sub(number, max_factor, 0, factors, max_factors);
a = as = 0;
while (factors[a] > 0) {
a++;
as += factors[a];
}
communication_factors_sub(number, max_factor, 1, factors, max_factors);
b = bs = 0;
while (factors[b] > 0) {
b++;
bs += factors[b];
}
if ((a < b) || ((a == b) && (as < bs))) {
communication_factors_sub(number, max_factor, 0, factors, max_factors);
}
}
}
int get_num_cores_per_node(MPI_Comm comm) {
int my_mpi_rank, num_cores, num_cores_min, num_cores_max;
MPI_Comm comm_node;
MPI_Info info;
MPI_Comm_rank(comm, &my_mpi_rank);
MPI_Info_create(&info);
MPI_Comm_split_type(comm, MPI_COMM_TYPE_SHARED, my_mpi_rank, info,
&comm_node);
MPI_Info_free(&info);
MPI_Comm_size(comm_node, &num_cores);
MPI_Comm_free(&comm_node);
MPI_Allreduce(&num_cores, &num_cores_min, 1, MPI_INT, MPI_MIN, comm);
MPI_Allreduce(&num_cores, &num_cores_max, 1, MPI_INT, MPI_MAX, comm);
if (num_cores_min == num_cores_max) {
return (num_cores);
} else {
return (-1);
}
}
int break_tiles(int message_size, int *tmsize, int *my_cores_per_node_row,
int *my_cores_per_node_column) {
int i;
(*tmsize) *= (*my_cores_per_node_row) * (*my_cores_per_node_row) *
(*my_cores_per_node_column);
if ((*my_cores_per_node_column) == 1) {
i = 2;
while ((*tmsize > message_size) && (i <= *my_cores_per_node_row)) {
if ((*my_cores_per_node_row) % i == 0) {
(*my_cores_per_node_row) /= i;
(*tmsize) /= (i * i);
} else {
i++;
}
}
}
if (*my_cores_per_node_row < 1) {
*my_cores_per_node_row = 1;
}
return (1);
return (*tmsize <= message_size);
}
int EXT_MPI_Init() {
read_bench();
read_env();
is_initialised = 1;
return (0);
}
int EXT_MPI_Initialized(int *flag) {
*flag = is_initialised;
return (0);
}
int EXT_MPI_Finalize() { return (0); }
int EXT_MPI_Alltoall_init_general(void *sendbuf, int sendcount,
MPI_Datatype sendtype, void *recvbuf,
int recvcount, MPI_Datatype recvtype,
MPI_Comm comm_row, int my_cores_per_node_row,
MPI_Comm comm_column,
int my_cores_per_node_column, int *handle) {
int my_mpi_size_row, num_ports, type_size, tmsize, chunks_throttle;
MPI_Comm_size(comm_row, &my_mpi_size_row);
MPI_Type_size(sendtype, &type_size);
tmsize = type_size * sendcount;
if (tmsize < 1) {
tmsize = 1;
}
tmsize *=
my_cores_per_node_row * my_cores_per_node_row * my_cores_per_node_column;
num_ports = my_mpi_size_row / my_cores_per_node_row - 1;
if ((tmsize < MERGE_SIZE) &&
(num_ports >= my_cores_per_node_row * my_cores_per_node_column)) {
while ((tmsize < MERGE_SIZE) &&
(num_ports >= my_cores_per_node_row * my_cores_per_node_column)) {
tmsize *= 2;
num_ports = (num_ports - 1) / 4 + 1;
}
if (num_ports < my_cores_per_node_row * my_cores_per_node_column) {
num_ports = my_cores_per_node_row * my_cores_per_node_column;
}
chunks_throttle =
(num_ports / (my_cores_per_node_row * my_cores_per_node_column)) / 3 +
1;
*handle = EXT_MPI_Alltoall_init_native(
sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm_row,
my_cores_per_node_row, comm_column, my_cores_per_node_column, num_ports,
my_cores_per_node_row * my_cores_per_node_column, chunks_throttle);
return (0);
}
tmsize = type_size * sendcount;
if (break_tiles(BREAK_SIZE, &tmsize, &my_cores_per_node_row,
&my_cores_per_node_column)) {
num_ports = my_mpi_size_row / my_cores_per_node_row - 1;
chunks_throttle =
(num_ports / (my_cores_per_node_row * my_cores_per_node_column)) / 3 +
1;
*handle = EXT_MPI_Alltoall_init_native(
sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm_row,
my_cores_per_node_row, comm_column, my_cores_per_node_column, num_ports,
my_cores_per_node_row * my_cores_per_node_column, chunks_throttle);
} else {
*handle = -1;
}
return (0);
}
int EXT_MPI_Alltoallv_init_general(void *sendbuf, int *sendcounts, int *sdispls,
MPI_Datatype sendtype, void *recvbuf,
int *recvcounts, int *rdispls,
MPI_Datatype recvtype, MPI_Comm comm_row,
int my_cores_per_node_row,
MPI_Comm comm_column,
int my_cores_per_node_column, int *handle) {
int my_mpi_size_row, chunks_throttle, element_max_size, type_size, tmsize, i,
j;
#ifdef DEBUG
int world_rank, sum_sendcounts, sum_recvcounts, k, new_counts_displs;
void *recvbuf_ref;
#endif
MPI_Comm_size(comm_row, &my_mpi_size_row);
element_max_size = 0;
for (i = 0; i < my_mpi_size_row; i++) {
if (sendcounts[i] > element_max_size) {
element_max_size = sendcounts[i];
}
}
MPI_Type_size(sendtype, &type_size);
tmsize = type_size * element_max_size;
MPI_Allreduce(MPI_IN_PLACE, &tmsize, 1, MPI_INT, MPI_MAX, comm_row);
if (comm_column != MPI_COMM_NULL) {
MPI_Allreduce(MPI_IN_PLACE, &tmsize, 1, MPI_INT, MPI_MAX, comm_column);
}
i = my_cores_per_node_row;
j = my_cores_per_node_column;
if (break_tiles(BREAK_SIZE, &tmsize, &my_cores_per_node_row,
&my_cores_per_node_column)) {
chunks_throttle = ((my_mpi_size_row / my_cores_per_node_row - 1) /
(my_cores_per_node_row * my_cores_per_node_column)) /
3 +
1;
chunks_throttle = 2;
if ((fixed_tile_size_row > 0) && (i % fixed_tile_size_row == 0)) {
my_cores_per_node_row = fixed_tile_size_row;
}
if ((fixed_tile_size_column > 0) && (j % fixed_tile_size_column == 0)) {
my_cores_per_node_column = fixed_tile_size_column;
}
*handle = EXT_MPI_Alltoallv_init_native(
sendbuf, sendcounts, sdispls, sendtype, recvbuf, recvcounts, rdispls,
recvtype, comm_row, my_cores_per_node_row, comm_column,
my_cores_per_node_column,
my_cores_per_node_row * my_cores_per_node_column, chunks_throttle);
} else {
*handle = -1;
}
#ifdef DEBUG
new_counts_displs = (sdispls == NULL);
if (new_counts_displs) {
sdispls = (int *)malloc(my_mpi_size_row * sizeof(int));
recvcounts = (int *)malloc(my_mpi_size_row * sizeof(int));
rdispls = (int *)malloc(my_mpi_size_row * sizeof(int));
MPI_Alltoall(sendcounts, 1, MPI_INT, recvcounts, 1, MPI_INT, comm_row);
sdispls[0] = 0;
rdispls[0] = 0;
for (i = 0; i < my_mpi_size_row - 1; i++) {
sdispls[i + 1] = sdispls[i] + sendcounts[i];
rdispls[i + 1] = rdispls[i] + recvcounts[i];
}
}
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
sum_sendcounts = 0;
sum_recvcounts = 0;
for (i = 0; i < my_mpi_size_row; i++) {
sum_sendcounts += sendcounts[i];
sum_recvcounts += recvcounts[i];
}
recvbuf_ref = (void *)malloc(sum_recvcounts * type_size);
k = 0;
for (j = 0; j < my_mpi_size_row; j++) {
for (i = 0; i < (int)((sendcounts[j] * type_size) / sizeof(long int));
i++) {
((long int *)sendbuf)[(sdispls[j] * type_size) / sizeof(long int) + i] =
world_rank * ((long int)sum_sendcounts * type_size) /
sizeof(long int) +
k;
k++;
}
}
MPI_Alltoallv(sendbuf, sendcounts, sdispls, sendtype, recvbuf_ref, recvcounts,
rdispls, recvtype, comm_row);
EXT_MPI_Exec_native(*handle);
k = 0;
for (j = 0; j < my_mpi_size_row; j++) {
for (i = 0; i < (int)((recvcounts[j] * type_size) / sizeof(long int));
i++) {
if (((long int *)
recvbuf)[(rdispls[j] * type_size) / sizeof(long int) + i] !=
((long int *)
recvbuf_ref)[(rdispls[j] * type_size) / sizeof(long int) + i]) {
k = 1;
}
}
}
if (k) {
printf("logical error in EXT_MPI_Alltoallv %d\n", world_rank);
exit(1);
}
free(recvbuf_ref);
if (new_counts_displs) {
free(rdispls);
free(recvcounts);
free(sdispls);
}
#endif
return (0);
}
int EXT_MPI_Ialltoall_init_general(void *sendbuf, int sendcount,
MPI_Datatype sendtype, void *recvbuf,
int recvcount, MPI_Datatype recvtype,
MPI_Comm comm_row, int my_cores_per_node_row,
MPI_Comm comm_column,
int my_cores_per_node_column,
int *handle_begin, int *handle_wait) {
int type_size, tmsize;
MPI_Type_size(sendtype, &type_size);
tmsize = type_size * sendcount;
if (break_tiles(BREAK_SIZE, &tmsize, &my_cores_per_node_row,
&my_cores_per_node_column)) {
EXT_MPI_Ialltoall_init_native(
sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm_row,
my_cores_per_node_row, comm_column, my_cores_per_node_column,
my_cores_per_node_row * my_cores_per_node_column, handle_begin,
handle_wait);
} else {
*handle_begin = *handle_wait = -1;
}
return (0);
}
int EXT_MPI_Ialltoallv_init_general(
void *sendbuf, int *sendcounts, int *sdispls, MPI_Datatype sendtype,
void *recvbuf, int *recvcounts, int *rdispls, MPI_Datatype recvtype,
MPI_Comm comm_row, int my_cores_per_node_row, MPI_Comm comm_column,
int my_cores_per_node_column, int *handle_begin, int *handle_wait) {
int my_mpi_size_row, element_max_size, type_size, tmsize, i;
MPI_Comm_size(comm_row, &my_mpi_size_row);
element_max_size = 0;
for (i = 0; i < my_mpi_size_row; i++) {
if (sendcounts[i] > element_max_size) {
element_max_size = sendcounts[i];
}
}
MPI_Type_size(sendtype, &type_size);
tmsize = type_size * element_max_size;
MPI_Allreduce(MPI_IN_PLACE, &tmsize, 1, MPI_INT, MPI_MAX, comm_row);
if (comm_column != MPI_COMM_NULL) {
MPI_Allreduce(MPI_IN_PLACE, &tmsize, 1, MPI_INT, MPI_MAX, comm_column);
}
if (break_tiles(BREAK_SIZE, &tmsize, &my_cores_per_node_row,
&my_cores_per_node_column)) {
EXT_MPI_Ialltoallv_init_native(
sendbuf, sendcounts, sdispls, sendtype, recvbuf, recvcounts, rdispls,
recvtype, comm_row, my_cores_per_node_row, comm_column,
my_cores_per_node_column,
my_cores_per_node_row * my_cores_per_node_column, handle_begin,
handle_wait);
} else {
*handle_begin = *handle_wait = -1;
}
return (0);
}
int EXT_MPI_Alltoall_init(void *sendbuf, int sendcount, MPI_Datatype sendtype,
void *recvbuf, int recvcount, MPI_Datatype recvtype,
MPI_Comm comm, int *handle) {
int num_core_per_node = get_num_cores_per_node(comm);
if (num_core_per_node > 0) {
return (EXT_MPI_Alltoall_init_general(
sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm,
num_core_per_node, MPI_COMM_NULL, 1, handle));
} else {
*handle = -1;
return (0);
}
}
int EXT_MPI_Alltoallv_init(void *sendbuf, int *sendcounts, int *sdispls,
MPI_Datatype sendtype, void *recvbuf,
int *recvcounts, int *rdispls, MPI_Datatype recvtype,
MPI_Comm comm, int *handle) {
int num_core_per_node = get_num_cores_per_node(comm);
if (num_core_per_node > 0) {
return (EXT_MPI_Alltoallv_init_general(
sendbuf, sendcounts, sdispls, sendtype, recvbuf, recvcounts, rdispls,
recvtype, comm, num_core_per_node, MPI_COMM_NULL, 1, handle));
} else {
*handle = -1;
return (0);
}
}
int EXT_MPI_Ialltoall_init(void *sendbuf, int sendcount, MPI_Datatype sendtype,
void *recvbuf, int recvcount, MPI_Datatype recvtype,
MPI_Comm comm, int *handle_begin, int *handle_wait) {
int num_core_per_node = get_num_cores_per_node(comm);
if (num_core_per_node > 0) {
return (EXT_MPI_Ialltoall_init_general(
sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm,
num_core_per_node, MPI_COMM_NULL, 1, handle_begin, handle_wait));
} else {
*handle_begin = *handle_wait = -1;
return (0);
}
}
int EXT_MPI_Ialltoallv_init(void *sendbuf, int *sendcounts, int *sdispls,
MPI_Datatype sendtype, void *recvbuf,
int *recvcounts, int *rdispls,
MPI_Datatype recvtype, MPI_Comm comm,
int *handle_begin, int *handle_wait) {
int num_core_per_node = get_num_cores_per_node(comm);
if (num_core_per_node > 0) {
return (EXT_MPI_Ialltoallv_init_general(
sendbuf, sendcounts, sdispls, sendtype, recvbuf, recvcounts, rdispls,
recvtype, comm, num_core_per_node, MPI_COMM_NULL, 1, handle_begin,
handle_wait));
} else {
*handle_begin = *handle_wait = -1;
return (0);
}
}
int EXT_MPI_Scatter_init_general(void *sendbuf, int sendcount,
MPI_Datatype sendtype, void *recvbuf,
int recvcount, MPI_Datatype recvtype, int root,
MPI_Comm comm_row, int my_cores_per_node_row,
MPI_Comm comm_column,
int my_cores_per_node_column, int *handle) {
int *sendcounts, *sdispls, *recvcounts, *rdispls;
int mpi_comm_rank, mpi_comm_size;
int returnvalue, i;
MPI_Comm_rank(comm_row, &mpi_comm_rank);
MPI_Comm_size(comm_row, &mpi_comm_size);
sendcounts = (int *)malloc(mpi_comm_size * sizeof(int));
sdispls = (int *)malloc(mpi_comm_size * sizeof(int));
recvcounts = (int *)malloc(mpi_comm_size * sizeof(int));
rdispls = (int *)malloc(mpi_comm_size * sizeof(int));
if (mpi_comm_rank == root) {
for (i = 0; i < mpi_comm_size; i++) {
sendcounts[i] = sendcount;
}
} else {
for (i = 0; i < mpi_comm_size; i++) {
sendcounts[i] = 0;
}
}
for (i = 0; i < mpi_comm_size; i++) {
recvcounts[i] = 0;
}
recvcounts[root] = recvcount;
sdispls[0] = rdispls[0] = 0;
for (i = 0; i < mpi_comm_size - 1; i++) {
sdispls[i + 1] = sdispls[i] + sendcounts[i];
rdispls[i + 1] = rdispls[i] + recvcounts[i];
}
returnvalue = EXT_MPI_Alltoallv_init_general(
sendbuf, sendcounts, sdispls, sendtype, recvbuf, recvcounts, rdispls,
recvtype, comm_row, my_cores_per_node_row, comm_column,
my_cores_per_node_column, handle);
free(rdispls);
free(recvcounts);
free(sdispls);
free(sendcounts);
return (returnvalue);
}
int EXT_MPI_Gather_init_general(void *sendbuf, int sendcount,
MPI_Datatype sendtype, void *recvbuf,
int recvcount, MPI_Datatype recvtype, int root,
MPI_Comm comm_row, int my_cores_per_node_row,
MPI_Comm comm_column,
int my_cores_per_node_column, int *handle) {
int *sendcounts, *sdispls, *recvcounts, *rdispls;
int mpi_comm_rank, mpi_comm_size;
int returnvalue, i;
MPI_Comm_rank(comm_row, &mpi_comm_rank);
MPI_Comm_size(comm_row, &mpi_comm_size);
sendcounts = (int *)malloc(mpi_comm_size * sizeof(int));
sdispls = (int *)malloc(mpi_comm_size * sizeof(int));
recvcounts = (int *)malloc(mpi_comm_size * sizeof(int));
rdispls = (int *)malloc(mpi_comm_size * sizeof(int));
if (mpi_comm_rank == root) {
for (i = 0; i < mpi_comm_size; i++) {
recvcounts[i] = recvcount;
}
} else {
for (i = 0; i < mpi_comm_size; i++) {
recvcounts[i] = 0;
}
}
for (i = 0; i < mpi_comm_size; i++) {
sendcounts[i] = 0;
}
sendcounts[root] = sendcount;
sdispls[0] = rdispls[0] = 0;
for (i = 0; i < mpi_comm_size - 1; i++) {
sdispls[i + 1] = sdispls[i] + sendcounts[i];
rdispls[i + 1] = rdispls[i] + recvcounts[i];
}
returnvalue = EXT_MPI_Alltoallv_init_general(
sendbuf, sendcounts, sdispls, sendtype, recvbuf, recvcounts, rdispls,
recvtype, comm_row, my_cores_per_node_row, comm_column,
my_cores_per_node_column, handle);
free(rdispls);
free(recvcounts);
free(sdispls);
free(sendcounts);
return (returnvalue);
}
int EXT_MPI_Scatter_init(void *sendbuf, int sendcount, MPI_Datatype sendtype,
void *recvbuf, int recvcount, MPI_Datatype recvtype,
int root, MPI_Comm comm, int *handle) {
int num_core_per_node = get_num_cores_per_node(comm);
if (num_core_per_node > 0) {
return (EXT_MPI_Scatter_init_general(
sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm,
num_core_per_node, MPI_COMM_NULL, 1, handle));
} else {
*handle = -1;
return (0);
}
}
int EXT_MPI_Gather_init(void *sendbuf, int sendcount, MPI_Datatype sendtype,
void *recvbuf, int recvcount, MPI_Datatype recvtype,
int root, MPI_Comm comm, int *handle) {
int num_core_per_node = get_num_cores_per_node(comm);
if (num_core_per_node > 0) {
return (EXT_MPI_Gather_init_general(
sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm,
num_core_per_node, MPI_COMM_NULL, 1, handle));
} else {
*handle = -1;
return (0);
}
}
static int EXT_MPI_Allgatherv_init_general_ext(
void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf,
int *recvcounts, int *displs, MPI_Datatype recvtype, MPI_Comm comm_row,
int my_cores_per_node_row, MPI_Comm comm_column,
int my_cores_per_node_column, int *handle, int allreduce, int recvcount) {
int comm_size_row, *num_ports, *num_parallel, type_size, scount, i;
#ifdef DEBUG
void *recvbuf_ref;
int world_rank, comm_rank_row, max_sendcount, max_displs, j, k;
#endif
#ifdef VERBOSE
int world_rankv;
#endif
MPI_Comm_size(comm_row, &comm_size_row);
MPI_Type_size(sendtype, &type_size);
num_ports = (int *)malloc((comm_size_row + 1) * sizeof(int));
num_parallel = (int *)malloc((comm_size_row + 1) * sizeof(int));
MPI_Allreduce(&sendcount, &scount, 1, MPI_INT, MPI_MAX, comm_row);
if (comm_column != MPI_COMM_NULL) {
MPI_Allreduce(MPI_IN_PLACE, &scount, 1, MPI_INT, MPI_SUM, comm_column);
}
if (scount * type_size <= 25000000) {
if (fixed_factors == NULL) {
cost_recursive(comm_size_row / my_cores_per_node_row, scount * type_size,
1, my_cores_per_node_row * my_cores_per_node_column,
num_ports);
} else {
i = -1;
do {
i++;
num_ports[i] = fixed_factors[i];
} while (fixed_factors[i] > 0);
}
i = 0;
while (num_ports[i] != 0) {
num_ports[i]--;
i++;
}
#ifdef VERBOSE
MPI_Comm_rank(MPI_COMM_WORLD, &world_rankv);
if (world_rankv == 0) {
printf("# allgatherv parameters %d %d %d %d ports ",
comm_size_row / my_cores_per_node_row, sendcount * type_size, 1,
my_cores_per_node_row * my_cores_per_node_column);
i = 0;
while (num_ports[i] > 0) {
printf("%d ", num_ports[i]);
i++;
}
printf("\n");
}
#endif
if (my_cores_per_node_row * my_cores_per_node_column > 1) {
for (i = 0; i < comm_size_row / my_cores_per_node_row + 1; i++) {
// num_parallel[i] =
// (my_cores_per_node_row*my_cores_per_node_column)/(num_ports[i]+1);
num_parallel[i] = 1;
}
if (recvcount < 0) {
*handle = EXT_MPI_Allgatherv_init_native(
sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype,
comm_row, my_cores_per_node_row, comm_column,
my_cores_per_node_column, num_ports, num_parallel,
my_cores_per_node_row * my_cores_per_node_column, allreduce,
enforce_bruck, -1);
} else {
*handle = EXT_MPI_Allgatherv_init_native(
sendbuf, sendcount, sendtype, recvbuf, NULL, displs, recvtype,
comm_row, my_cores_per_node_row, comm_column,
my_cores_per_node_column, num_ports, num_parallel,
my_cores_per_node_row * my_cores_per_node_column, allreduce,
enforce_bruck, recvcount);
}
} else {
for (i = 0; i < comm_size_row / my_cores_per_node_row + 1; i++) {
num_ports[i] = (comm_size_row / my_cores_per_node_row) / 2 - 1;
num_ports[i] = 1;
num_parallel[i] = 1;
}
if (recvcount < 0) {
*handle = EXT_MPI_Allgatherv_init_native(
sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype,
comm_row, 1, MPI_COMM_NULL, 1, num_ports, num_parallel, 1,
allreduce, enforce_bruck, -1);
} else {
*handle = EXT_MPI_Allgatherv_init_native(
sendbuf, sendcount, sendtype, recvbuf, NULL, displs, recvtype,
comm_row, 1, MPI_COMM_NULL, 1, num_ports, num_parallel, 1,
allreduce, enforce_bruck, recvcount);
}
}
} else {
for (i = 0; i < comm_size_row + 1; i++) {
num_ports[i] = comm_size_row - 1;
num_ports[i] = 3;
}
for (i = 0; i < comm_size_row / my_cores_per_node_row + 1; i++) {
// num_parallel[i] =
// (my_cores_per_node_row*my_cores_per_node_column)/(num_ports[i]+1);
num_parallel[i] = 1;
}
if (recvcount < 0) {
*handle = EXT_MPI_Allgatherv_init_native(
sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype,
comm_row, 1, MPI_COMM_NULL, 1, num_ports, num_parallel, 1, allreduce,
enforce_bruck, -1);
} else {
*handle = EXT_MPI_Allgatherv_init_native(
sendbuf, sendcount, sendtype, recvbuf, NULL, displs, recvtype,
comm_row, 1, MPI_COMM_NULL, 1, num_ports, num_parallel, 1, allreduce,
enforce_bruck, recvcount);
}
}
free(num_parallel);
free(num_ports);
#ifdef DEBUG
if (!allreduce) {
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
MPI_Comm_rank(comm_row, &comm_rank_row);
if (recvcount < 0) {
max_sendcount = recvcounts[0];
max_displs = 0;
for (i = 0; i < comm_size_row; i++) {
if (recvcounts[i] > max_sendcount)
max_sendcount = recvcounts[i];
if (displs[i] > max_displs)
max_displs = displs[i];
}
j = max_displs + max_sendcount;
} else {
max_sendcount = recvcount;
j = recvcount * comm_size_row;
}
recvbuf_ref = (void *)malloc(j * type_size);
for (i = 0; i < (int)((sendcount * type_size) / sizeof(long int)); i++) {
((long int *)sendbuf)[i] = world_rank * max_sendcount + i;
}
if (recvcount < 0) {
MPI_Allgatherv(sendbuf, sendcount, sendtype, recvbuf_ref, recvcounts,
displs, recvtype, comm_row);
} else {
MPI_Allgather(sendbuf, sendcount, sendtype, recvbuf_ref, recvcount,
recvtype, comm_row);
}
EXT_MPI_Exec_native(*handle);
k = 0;
if (recvcount < 0) {
for (j = 0; j < comm_size_row; j++) {
for (i = 0; i < (int)((recvcounts[j] * type_size) / sizeof(long int));
i++) {
if (((long int *)
recvbuf)[(displs[j] * type_size) / sizeof(long int) + i] !=
((long int *)
recvbuf_ref)[(displs[j] * type_size) / sizeof(long int) +
i]) {
k = 1;
}
}
}
} else {
for (j = 0; j < comm_size_row; j++) {
for (i = 0; i < (int)((recvcount * type_size) / sizeof(long int));
i++) {
if (((long int *)
recvbuf)[(j * recvcount * type_size) / sizeof(long int) +
i] !=
((long int *)
recvbuf_ref)[(j * recvcount * type_size) / sizeof(long int) +
i]) {
k = 1;
}
}
}
}
if (k) {
printf("logical error in EXT_MPI_Allgatherv %d\n", world_rank);
exit(1);
}
free(recvbuf_ref);
}
#endif
return (0);
}
static int EXT_MPI_Reduce_scatter_init_general_ext(
void *sendbuf, void *recvbuf, int *recvcounts, MPI_Datatype datatype,
MPI_Op op, MPI_Comm comm_row, int my_cores_per_node_row,
MPI_Comm comm_column, int my_cores_per_node_column, int *handle,
int allreduce, int recvcount) {
int comm_size_row, *num_ports, *num_parallel, type_size, rcount, i, j;
#ifdef DEBUG
void *recvbuf_ref;
int world_rank, comm_rank_row, k;
if ((op != MPI_SUM) || (datatype != MPI_LONG)) {
if (recvcount < 0) {
EXT_MPI_Reduce_scatter_init_general(
sendbuf, recvbuf, recvcounts, MPI_LONG, MPI_SUM, comm_row,
my_cores_per_node_row, comm_column, my_cores_per_node_column, handle);
} else {
EXT_MPI_Reduce_scatter_block_init_general(
sendbuf, recvbuf, recvcount, MPI_LONG, MPI_SUM, comm_row,
my_cores_per_node_row, comm_column, my_cores_per_node_column, handle);
}
EXT_MPI_Done_native(*handle);
}
#endif
#ifdef VERBOSE
int world_rankv;
#endif
MPI_Comm_size(comm_row, &comm_size_row);
MPI_Type_size(datatype, &type_size);
num_ports = (int *)malloc((comm_size_row + 1) * sizeof(int));
num_parallel = (int *)malloc((comm_size_row + 1) * sizeof(int));
if (recvcount < 0) {
rcount = 0;
for (i = 0; i < comm_size_row; i++) {
if (recvcounts[i] > rcount) {
rcount = recvcounts[i];
}
}
if (comm_column != MPI_COMM_NULL) {
MPI_Allreduce(MPI_IN_PLACE, &rcount, 1, MPI_INT, MPI_SUM, comm_column);
}
} else {
rcount = recvcount * my_cores_per_node_column;
}
if (rcount * type_size <= 25000000) {
if (fixed_factors == NULL) {
cost_recursive(comm_size_row / my_cores_per_node_row, rcount * type_size,
1, my_cores_per_node_row * my_cores_per_node_column,
num_ports);
} else {
i = -1;
do {
i++;
num_ports[i] = fixed_factors[i];
} while (fixed_factors[i] > 0);
}
i = 0;
while (num_ports[i] != 0) {
num_ports[i]--;
i++;
}
#ifdef VERBOSE
MPI_Comm_rank(MPI_COMM_WORLD, &world_rankv);
if (world_rankv == 0) {
i = recvcount;
if (i < 0) {
i = recvcounts[0];
}
printf("# reduce_scatter parameters %d %d %d %d ports ",
comm_size_row / my_cores_per_node_row, i * type_size, 1,
my_cores_per_node_row * my_cores_per_node_column);
i = 0;
while (num_ports[i] > 0) {
printf("%d ", num_ports[i]);
i++;
}
printf("\n");
}
#endif
if (my_cores_per_node_row * my_cores_per_node_column > 1) {
for (i = 0; i < comm_size_row / my_cores_per_node_row + 1; i++) {
// num_parallel[i] =
// (my_cores_per_node_row*my_cores_per_node_column)/(num_ports[i]+1);
num_parallel[i] = 1;
}
*handle = EXT_MPI_Reduce_scatter_init_native(
sendbuf, recvbuf, recvcounts, datatype, op, comm_row,
my_cores_per_node_row, comm_column, my_cores_per_node_column,
num_ports, num_parallel,
my_cores_per_node_row * my_cores_per_node_column, copyin_method,
allreduce, enforce_bruck, recvcount);
} else {
for (i = 0; i < comm_size_row / my_cores_per_node_row + 1; i++) {
num_ports[i] = (comm_size_row / my_cores_per_node_row) / 2 - 1;
num_ports[i] = 1;
num_parallel[i] = 1;
}
*handle = EXT_MPI_Reduce_scatter_init_native(
sendbuf, recvbuf, recvcounts, datatype, op, comm_row, 1,
MPI_COMM_NULL, 1, num_ports, num_parallel, 1, copyin_method,
allreduce, enforce_bruck, recvcount);
}
} else {
for (i = 0; i < comm_size_row + 1; i++) {
num_ports[i] = comm_size_row - 1;
num_ports[i] = 3;
}
for (i = 0; i < comm_size_row / my_cores_per_node_row + 1; i++) {
// num_parallel[i] =
// (my_cores_per_node_row*my_cores_per_node_column)/(num_ports[i]+1);
num_parallel[i] = 1;
}
*handle = EXT_MPI_Reduce_scatter_init_native(
sendbuf, recvbuf, recvcounts, datatype, op, comm_row, 1, MPI_COMM_NULL,
1, num_ports, num_parallel, 1, copyin_method, allreduce, enforce_bruck,
recvcount);
}
free(num_parallel);
free(num_ports);
#ifdef DEBUG
if (!allreduce) {
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
MPI_Comm_rank(comm_row, &comm_rank_row);
if ((op == MPI_SUM) && (datatype == MPI_LONG)) {
if (recvcount < 0) {
j = 0;
for (i = 0; i < comm_size_row; i++) {
j += recvcounts[i];
}
recvbuf_ref =
(long int *)malloc(recvcounts[comm_rank_row] * sizeof(long int));
} else {
j = recvcount * comm_size_row;
recvbuf_ref = (long int *)malloc(recvcount * sizeof(long int));
}
for (i = 0; i < j; i++) {
((long int *)sendbuf)[i] = world_rank * j + i;
}
if (recvcount < 0) {
MPI_Reduce_scatter(sendbuf, recvbuf_ref, recvcounts, MPI_LONG, MPI_SUM,
comm_row);
} else {
MPI_Reduce_scatter_block(sendbuf, recvbuf_ref, recvcount, MPI_LONG,
MPI_SUM, comm_row);
}
EXT_MPI_Exec_native(*handle);
if (recvcount < 0) {
k = recvcounts[comm_rank_row];
} else {
k = recvcount;
}
j = 0;
for (i = 0; i < k; i++) {
if (((long int *)recvbuf)[i] != ((long int *)recvbuf_ref)[i]) {
j = 1;
}
}
if (j) {
printf("logical error in EXT_MPI_Reduce_scatter %d\n", world_rank);
exit(1);
}
free(recvbuf_ref);
}
}
#endif
return (0);
}
int EXT_MPI_Allgatherv_init_general(void *sendbuf, int sendcount,
MPI_Datatype sendtype, void *recvbuf,
int *recvcounts, int *displs,
MPI_Datatype recvtype, MPI_Comm comm_row,
int my_cores_per_node_row,
MPI_Comm comm_column,
int my_cores_per_node_column, int *handle) {
return (EXT_MPI_Allgatherv_init_general_ext(
sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype,
comm_row, my_cores_per_node_row, comm_column, my_cores_per_node_column,
handle, 0, -1));
}
int EXT_MPI_Allgather_init_general(void *sendbuf, int sendcount,
MPI_Datatype sendtype, void *recvbuf,
int recvcount, MPI_Datatype recvtype,
MPI_Comm comm_row, int my_cores_per_node_row,
MPI_Comm comm_column,
int my_cores_per_node_column, int *handle) {
return (EXT_MPI_Allgatherv_init_general_ext(
sendbuf, sendcount, sendtype, recvbuf, NULL, NULL, recvtype, comm_row,
my_cores_per_node_row, comm_column, my_cores_per_node_column, handle, 0,
recvcount));
}
int EXT_MPI_Reduce_scatter_init_general(
void *sendbuf, void *recvbuf, int *recvcounts, MPI_Datatype datatype,
MPI_Op op, MPI_Comm comm_row, int my_cores_per_node_row,
MPI_Comm comm_column, int my_cores_per_node_column, int *handle) {
return (EXT_MPI_Reduce_scatter_init_general_ext(
sendbuf, recvbuf, recvcounts, datatype, op, comm_row,
my_cores_per_node_row, comm_column, my_cores_per_node_column, handle, 0,
-1));
}
int EXT_MPI_Reduce_scatter_block_init_general(
void *sendbuf, void *recvbuf, int recvcount, MPI_Datatype datatype,
MPI_Op op, MPI_Comm comm_row, int my_cores_per_node_row,
MPI_Comm comm_column, int my_cores_per_node_column, int *handle) {
return (EXT_MPI_Reduce_scatter_init_general_ext(
sendbuf, recvbuf, NULL, datatype, op, comm_row, my_cores_per_node_row,
comm_column, my_cores_per_node_column, handle, 0, recvcount));
}
int EXT_MPI_Allreduce_init_general(void *sendbuf, void *recvbuf, int count,
MPI_Datatype datatype, MPI_Op op,
MPI_Comm comm_row, int my_cores_per_node_row,
MPI_Comm comm_column,
int my_cores_per_node_column, int *handle) {
int comm_size_row, comm_rank_row, i, j;
int *recvcounts, *displs, message_size;
int *num_ports, *num_ports_limit;
int handle1, handle2;
#ifdef VERBOSE
int world_rank;
#endif
#ifdef DEBUG
int world_rankd;
void *recvbuf_ref;
if ((op != MPI_SUM) || (datatype != MPI_LONG)) {
EXT_MPI_Allreduce_init_general(sendbuf, recvbuf, count, MPI_LONG, MPI_SUM,
comm_row, my_cores_per_node_row, comm_column,
my_cores_per_node_column, handle);
EXT_MPI_Done_native(*handle);
}
#endif
MPI_Comm_size(comm_row, &comm_size_row);
MPI_Comm_rank(comm_row, &comm_rank_row);
MPI_Type_size(datatype, &message_size);
message_size *= count;
if (comm_column != MPI_COMM_NULL) {
MPI_Allreduce(MPI_IN_PLACE, &message_size, 1, MPI_INT, MPI_SUM,
comm_column);
}
if (message_size <= threshold_rabenseifner) {
num_ports = (int *)malloc(comm_size_row * sizeof(int));
num_ports_limit = (int *)malloc(comm_size_row * sizeof(int));
for (i = 0; i < comm_size_row; i++) {
num_ports[i] = comm_size_row / my_cores_per_node_row - 1;
num_ports_limit[i] = comm_size_row / my_cores_per_node_row - 1;
}
for (i = 0; i < comm_size_row; i++) {
num_ports[i] = num_ports_limit[i] = 0;
}
if ((fixed_factors == NULL) || (fixed_factors_limit == NULL)) {
communication_factors(comm_size_row / my_cores_per_node_row,
my_cores_per_node_row * my_cores_per_node_column +
1,
num_ports, num_ports_limit);
} else {
if (fixed_factors != NULL) {
i = -1;
do {
i++;
num_ports[i] = fixed_factors[i];
} while (fixed_factors[i] > 0);
}
if (fixed_factors_limit != NULL) {
i = -1;
do {
i++;
num_ports_limit[i] = fixed_factors_limit[i];
} while (fixed_factors_limit[i] > 0);
}
}
i = 0;
while (num_ports[i] != 0) {
num_ports[i]--;
i++;
}
i = 0;
while (num_ports_limit[i] != 0) {
num_ports_limit[i]--;
i++;
}
#ifdef VERBOSE
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
if (world_rank == 0) {
printf("# allreduce parameters %d %d %d %d ports ",
comm_size_row / my_cores_per_node_row, count * message_size, 1,
my_cores_per_node_row * my_cores_per_node_column);
i = 0;
while (num_ports[i] > 0) {
printf("%d ", num_ports[i]);
i++;
}
printf("ports_limit ");
i = 0;
while (num_ports_limit[i] > 0) {
printf("%d ", num_ports_limit[i]);
i++;
}
printf("\n");
}
#endif
*handle = EXT_MPI_Allreduce_init_native(
sendbuf, recvbuf, count, datatype, op, comm_row, my_cores_per_node_row,
comm_column, my_cores_per_node_column, num_ports, num_ports_limit,
my_cores_per_node_row * my_cores_per_node_column, copyin_method);
free(num_ports_limit);
free(num_ports);
} else {
recvcounts = (int *)malloc(comm_size_row * sizeof(int));
displs = (int *)malloc(comm_size_row * sizeof(int));
for (i = 0; i < comm_size_row; i++) {
recvcounts[i] = count / comm_size_row;
if (i < count % comm_size_row) {
recvcounts[i]++;
}
}
EXT_MPI_Reduce_scatter_init_general_ext(
sendbuf, recvbuf, recvcounts, datatype, op, comm_row,
my_cores_per_node_row, comm_column, my_cores_per_node_column, &handle1,
1, -1);
displs[0] = 0;
for (i = 0; i < comm_size_row - 1; i++) {
displs[i + 1] = displs[i] + recvcounts[i];
}
EXT_MPI_Allgatherv_init_general_ext(
recvbuf, recvcounts[comm_rank_row], datatype, recvbuf, recvcounts,
displs, datatype, comm_row, my_cores_per_node_row, comm_column,
my_cores_per_node_column, &handle2, 1, -1);
free(displs);
free(recvcounts);
*handle = EXT_MPI_Merge_collectives_native(handle1, handle2);
}
#ifdef DEBUG
MPI_Comm_rank(MPI_COMM_WORLD, &world_rankd);
if ((op == MPI_SUM) && (datatype == MPI_LONG)) {
recvbuf_ref = (long int *)malloc(count * sizeof(long int));
for (i = 0; i < count; i++) {
((long int *)sendbuf)[i] = world_rankd * count + i;
}
MPI_Allreduce(sendbuf, recvbuf_ref, count, MPI_LONG, MPI_SUM, comm_row);
EXT_MPI_Exec_native(*handle);
j = 0;
for (i = 0; i < count; i++) {
if (((long int *)recvbuf)[i] != ((long int *)recvbuf_ref)[i]) {
j = 1;
}
}
if (j) {
printf("logical error in EXT_MPI_Allreduce %d\n", world_rankd);
exit(1);
}
free(recvbuf_ref);
}
#endif
return (0);
}
int EXT_MPI_Bcast_init_general(void *sendbuf, int count, MPI_Datatype datatype,
int root, MPI_Comm comm_row,
int my_cores_per_node_row, MPI_Comm comm_column,
int my_cores_per_node_column, int *handle) {
int *recvcounts, *displs;
int comm_row_size, comm_row_rank, i;
int iret;
MPI_Comm_size(comm_row, &comm_row_size);
MPI_Comm_rank(comm_row, &comm_row_rank);
recvcounts = (int *)malloc(comm_row_size * sizeof(int));
for (i = 0; i < comm_row_size; i++) {
recvcounts[i] = 0;
}
recvcounts[root] = count;
displs = (int *)malloc(comm_row_size * sizeof(int));
displs[0] = 0;
for (i = 0; i < comm_row_size - 1; i++) {
displs[i + 1] = displs[i] + recvcounts[i];
}
count = recvcounts[comm_row_rank];
iret = EXT_MPI_Allgatherv_init_general(
sendbuf, count, datatype, sendbuf, recvcounts, displs, datatype, comm_row,
my_cores_per_node_row, comm_column, my_cores_per_node_column, handle);
free(displs);
free(recvcounts);
return (iret);
}
int EXT_MPI_Reduce_init_general(void *sendbuf, void *recvbuf, int count,
MPI_Datatype datatype, MPI_Op op, int root,
MPI_Comm comm_row, int my_cores_per_node_row,
MPI_Comm comm_column,
int my_cores_per_node_column, int *handle) {
int *recvcounts;
int comm_row_size, i;
int iret;
MPI_Comm_size(comm_row, &comm_row_size);
recvcounts = (int *)malloc(comm_row_size * sizeof(int));
for (i = 0; i < comm_row_size; i++) {
recvcounts[i] = 0;
}
recvcounts[root] = count;
iret = EXT_MPI_Reduce_scatter_init_general(
sendbuf, recvbuf, recvcounts, datatype, op, comm_row,
my_cores_per_node_row, comm_column, my_cores_per_node_column, handle);
free(recvcounts);
return (iret);
}
int EXT_MPI_Allgatherv_init(void *sendbuf, int sendcount, MPI_Datatype sendtype,
void *recvbuf, int *recvcounts, int *displs,
MPI_Datatype recvtype, MPI_Comm comm, int *handle) {
int num_core_per_node = get_num_cores_per_node(comm);
if (num_core_per_node > 0) {
return (EXT_MPI_Allgatherv_init_general(
sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype,
comm, num_core_per_node, MPI_COMM_NULL, 1, handle));
} else {
*handle = -1;
return (0);
}
}
int EXT_MPI_Allgather_init(void *sendbuf, int sendcount, MPI_Datatype sendtype,
void *recvbuf, int recvcount, MPI_Datatype recvtype,
MPI_Comm comm, int *handle) {
int num_core_per_node = get_num_cores_per_node(comm);
if (num_core_per_node > 0) {
return (EXT_MPI_Allgather_init_general(
sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm,
num_core_per_node, MPI_COMM_NULL, 1, handle));
} else {
*handle = -1;
return (0);
}
}
int EXT_MPI_Reduce_scatter_init(void *sendbuf, void *recvbuf, int *recvcounts,
MPI_Datatype datatype, MPI_Op op, MPI_Comm comm,
int *handle) {
int num_core_per_node = get_num_cores_per_node(comm);
if (num_core_per_node > 0) {
return (EXT_MPI_Reduce_scatter_init_general(
sendbuf, recvbuf, recvcounts, datatype, op, comm, num_core_per_node,
MPI_COMM_NULL, 1, handle));
} else {
*handle = -1;
return (0);
}
}
int EXT_MPI_Reduce_scatter_block_init(void *sendbuf, void *recvbuf,
int recvcount, MPI_Datatype datatype,
MPI_Op op, MPI_Comm comm, int *handle) {
int num_core_per_node = get_num_cores_per_node(comm);
if (num_core_per_node > 0) {
return (EXT_MPI_Reduce_scatter_block_init_general(
sendbuf, recvbuf, recvcount, datatype, op, comm, num_core_per_node,
MPI_COMM_NULL, 1, handle));
} else {
*handle = -1;
return (0);
}
}
int EXT_MPI_Allreduce_init(void *sendbuf, void *recvbuf, int count,
MPI_Datatype datatype, MPI_Op op, MPI_Comm comm,
int *handle) {
int num_core_per_node = get_num_cores_per_node(comm);
if (num_core_per_node > 0) {
return (EXT_MPI_Allreduce_init_general(sendbuf, recvbuf, count, datatype,
op, comm, num_core_per_node,
MPI_COMM_NULL, 1, handle));
} else {
*handle = -1;
return (0);
}
}
int EXT_MPI_Bcast_init(void *sendbuf, int count, MPI_Datatype datatype,
int root, MPI_Comm comm, int *handle) {
int num_core_per_node = get_num_cores_per_node(comm);
if (num_core_per_node > 0) {
return (EXT_MPI_Bcast_init_general(sendbuf, count, datatype, root, comm,
num_core_per_node, MPI_COMM_NULL, 1,
handle));
} else {
*handle = -1;
return (0);
}
}
int EXT_MPI_Reduce_init(void *sendbuf, void *recvbuf, int count,
MPI_Datatype datatype, MPI_Op op, int root,
MPI_Comm comm, int *handle) {
int num_core_per_node = get_num_cores_per_node(comm);
if (num_core_per_node > 0) {
return (EXT_MPI_Reduce_init_general(sendbuf, recvbuf, count, datatype, op,
root, comm, num_core_per_node,
MPI_COMM_NULL, 1, handle));
} else {
*handle = -1;
return (0);
}
}
int EXT_MPI_Exec(int handle) {
if (handle >= 0) {
return (EXT_MPI_Exec_native(handle));
} else {
return (0);
}
}
int EXT_MPI_Done(int handle) {
if (handle >= 0) {
return (EXT_MPI_Done_native(handle));
} else {
return (0);
}
}
int EXT_MPI_Init_general(MPI_Comm comm_row, int my_cores_per_node_row,
MPI_Comm comm_column, int my_cores_per_node_column,
int *handle) {
*handle = EXT_MPI_Init_general_native(comm_row, my_cores_per_node_row,
comm_column, my_cores_per_node_column);
return (0);
}
int EXT_MPI_Done_general(int handle) {
return (EXT_MPI_Done_general_native(handle));
}
int EXT_MPI_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
void *recvbuf, int *recvcounts, int *displs,
MPI_Datatype recvtype, int handle) {
int my_cores_per_node_row, my_cores_per_node_column, my_mpi_size_row,
my_mpi_rank_row;
int num_ports[10000], num_parallel[10000], i, data_size, j;
EXT_MPI_Get_size_rank_native(handle, &my_cores_per_node_row,
&my_cores_per_node_column, &my_mpi_size_row,
&my_mpi_rank_row);
if (my_mpi_size_row / my_cores_per_node_row > 10000) {
printf("maximum 10000 nodes\n");
exit(1);
}
MPI_Type_size(recvtype, &data_size);
j = 0;
for (i = 0; i < my_mpi_size_row; i++) {
if (recvcounts[i] > j) {
j = recvcounts[i];
}
}
data_size *= j;
for (i = 0; i < my_mpi_size_row / my_cores_per_node_row; i++) {
num_ports[i] = my_cores_per_node_row * my_cores_per_node_column;
num_parallel[i] = 1;
}
if (fixed_factors == NULL) {
cost_explicit(my_mpi_size_row / my_cores_per_node_row, data_size,
my_cores_per_node_row * my_cores_per_node_column, num_ports);
} else {
i = -1;
do {
i++;
num_ports[i] = fixed_factors[i];
} while (fixed_factors[i] > 0);
}
return (EXT_MPI_Allgatherv_native(sendbuf, sendcount, sendtype, recvbuf,
recvcounts, displs, recvtype, num_ports,
num_parallel, handle));
}
int EXT_MPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
void *recvbuf, int recvcount, MPI_Datatype recvtype,
int handle) {
int my_cores_per_node_row, my_cores_per_node_column, my_mpi_size_row,
my_mpi_rank_row;
int num_ports[10000], num_parallel[10000], i, data_size;
EXT_MPI_Get_size_rank_native(handle, &my_cores_per_node_row,
&my_cores_per_node_column, &my_mpi_size_row,
&my_mpi_rank_row);
if (my_mpi_size_row / my_cores_per_node_row > 10000) {
printf("maximum 10000 nodes\n");
exit(1);
}
MPI_Type_size(recvtype, &data_size);
data_size *= sendcount;
for (i = 0; i < my_mpi_size_row / my_cores_per_node_row; i++) {
num_ports[i] = my_cores_per_node_row * my_cores_per_node_column;
num_parallel[i] = 1;
}
if (fixed_factors == NULL) {
cost_explicit(my_mpi_size_row / my_cores_per_node_row, data_size,
my_cores_per_node_row * my_cores_per_node_column, num_ports);
} else {
i = -1;
do {
i++;
num_ports[i] = fixed_factors[i];
} while (fixed_factors[i] > 0);
}
return (EXT_MPI_Allgather_native(sendbuf, sendcount, sendtype, recvbuf,
recvcount, recvtype, num_ports, num_parallel,
handle));
}
int EXT_MPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts,
MPI_Datatype datatype, MPI_Op op, int handle) {
int my_cores_per_node_row, my_cores_per_node_column, my_mpi_size_row,
my_mpi_rank_row;
int num_ports[10000], num_parallel[10000], i, data_size, j;
EXT_MPI_Get_size_rank_native(handle, &my_cores_per_node_row,
&my_cores_per_node_column, &my_mpi_size_row,
&my_mpi_rank_row);
if (my_mpi_size_row / my_cores_per_node_row > 10000) {
printf("maximum 10000 nodes\n");
exit(1);
}
MPI_Type_size(datatype, &data_size);
j = 0;
for (i = 0; i < my_mpi_size_row; i++) {
if (recvcounts[i] > j) {
j = recvcounts[i];
}
}
data_size *= j;
for (i = 0; i < my_mpi_size_row / my_cores_per_node_row; i++) {
num_ports[i] = my_cores_per_node_row * my_cores_per_node_column;
num_parallel[i] = 1;
}
if (fixed_factors == NULL) {
cost_explicit(my_mpi_size_row / my_cores_per_node_row, data_size,
my_cores_per_node_row * my_cores_per_node_column, num_ports);
} else {
i = -1;
do {
i++;
num_ports[i] = fixed_factors[i];
} while (fixed_factors[i] > 0);
}
return (EXT_MPI_Reduce_scatter_native(sendbuf, recvbuf, recvcounts, datatype,
op, num_ports, num_parallel,
copyin_method, handle));
}
int EXT_MPI_Reduce_scatter_block(void *sendbuf, void *recvbuf, int recvcount,
MPI_Datatype datatype, MPI_Op op, int handle) {
int my_cores_per_node_row, my_cores_per_node_column, my_mpi_size_row,
my_mpi_rank_row;
int num_ports[10000], num_parallel[10000], i, data_size;
EXT_MPI_Get_size_rank_native(handle, &my_cores_per_node_row,
&my_cores_per_node_column, &my_mpi_size_row,
&my_mpi_rank_row);
if (my_mpi_size_row / my_cores_per_node_row > 10000) {
printf("maximum 10000 nodes\n");
exit(1);
}
MPI_Type_size(datatype, &data_size);
data_size *= recvcount;
for (i = 0; i < my_mpi_size_row / my_cores_per_node_row; i++) {
num_ports[i] = my_cores_per_node_row * my_cores_per_node_column;
num_parallel[i] = 1;
}
if (fixed_factors == NULL) {
cost_explicit(my_mpi_size_row / my_cores_per_node_row, data_size,
my_cores_per_node_row * my_cores_per_node_column, num_ports);
} else {
i = -1;
do {
i++;
num_ports[i] = fixed_factors[i];
} while (fixed_factors[i] > 0);
}
return (EXT_MPI_Reduce_scatter_block_native(
sendbuf, recvbuf, recvcount, datatype, op, num_ports, num_parallel,
copyin_method, handle));
}
int EXT_MPI_Allreduce(void *sendbuf, void *recvbuf, int count,
MPI_Datatype datatype, MPI_Op op, int handle) {
int my_cores_per_node_row, my_cores_per_node_column, my_mpi_size_row,
my_mpi_rank_row;
int num_ports[10000], num_ports_limit[10000], num_parallel[10000], i,
data_size, j;
int *recvcounts, *displs, retval;
EXT_MPI_Get_size_rank_native(handle, &my_cores_per_node_row,
&my_cores_per_node_column, &my_mpi_size_row,
&my_mpi_rank_row);
if (my_mpi_size_row / my_cores_per_node_row > 10000) {
printf("maximum 10000 nodes\n");
exit(1);
}
MPI_Type_size(datatype, &data_size);
data_size *= count;
if (data_size <= threshold_rabenseifner) {
for (i = 0; i < my_mpi_size_row / my_cores_per_node_row; i++) {
num_ports[i] = num_ports_limit[i] = 0;
}
if (fixed_factors == NULL) {
communication_factors(my_mpi_size_row / my_cores_per_node_row,
my_cores_per_node_row * my_cores_per_node_column +
1,
num_ports, num_ports_limit);
} else {
i = -1;
do {
i++;
num_ports[i] = fixed_factors[i];
num_ports_limit[i] = fixed_factors_limit[i];
} while (fixed_factors[i] > 0);
}
j = -1;
for (i = 0; i < my_mpi_size_row; i++) {
if (num_ports[i] > 0) {
num_ports[i]--;
num_ports_limit[i]--;
}
}
return (EXT_MPI_Allreduce_native(sendbuf, recvbuf, count, datatype, op,
num_ports, num_ports_limit, num_parallel,
copyin_method, handle));
} else {
recvcounts = (int *)malloc(my_mpi_size_row * sizeof(int));
displs = (int *)malloc(my_mpi_size_row * sizeof(int));
for (i = 0; i < my_mpi_size_row; i++) {
recvcounts[i] = count / my_mpi_size_row;
if (i < count % my_mpi_size_row) {
recvcounts[i]++;
}
}
retval = EXT_MPI_Reduce_scatter(sendbuf, recvbuf, recvcounts, datatype, op,
handle);
if (retval != 0) {
return (retval);
}
displs[0] = 0;
for (i = 0; i < my_mpi_size_row - 1; i++) {
displs[i + 1] = displs[i] + recvcounts[i];
}
retval = EXT_MPI_Allgatherv(recvbuf, recvcounts[my_mpi_rank_row], datatype,
recvbuf, recvcounts, displs, datatype, handle);
free(displs);
free(recvcounts);
return (retval);
}
}
int EXT_MPI_Allocate(MPI_Comm comm_row, int my_cores_per_node_row,
MPI_Comm comm_column, int my_cores_per_node_column,
int sharedmem_size, int locmem_size_) {
return (EXT_MPI_Allocate_native(comm_row, my_cores_per_node_row, comm_column,
my_cores_per_node_column, sharedmem_size,
locmem_size_));
}
int EXT_MPI_Dry_allreduce(int mpi_size, int count, int *handle) {
int *num_ports, *num_ports_limit, *recvcounts;
int handle1, handle2, i, j;
if (count * sizeof(long int) <= threshold_rabenseifner) {
num_ports = (int *)malloc(mpi_size * sizeof(int));
num_ports_limit = (int *)malloc(mpi_size * sizeof(int));
if (fixed_factors == NULL) {
communication_factors(mpi_size, 1 + 1, num_ports, num_ports_limit);
} else {
i = -1;
do {
i++;
num_ports[i] = fixed_factors[i];
num_ports_limit[i] = fixed_factors_limit[i];
} while (fixed_factors[i] > 0);
}
for (i = 0; i < mpi_size; i++) {
if (num_ports[i] > 0) {
num_ports[i]--;
num_ports_limit[i]--;
}
}
#ifdef VERBOSE
printf("# allreduce parameters %d %d %d %d ports ", mpi_size,
(int)(count * sizeof(long int)), 1, 1);
i = 0;
while (num_ports[i] > 0) {
printf("%d ", num_ports[i]);
i++;
}
printf("ports_limit ");
i = 0;
while (num_ports_limit[i] > 0) {
printf("%d ", num_ports_limit[i]);
i++;
}
printf("\n");
#endif
*handle = EXT_MPI_Dry_allreduce_native(mpi_size, count, num_ports,
num_ports_limit);
free(num_ports_limit);
free(num_ports);
} else {
num_ports = (int *)malloc(mpi_size * sizeof(int));
recvcounts = (int *)malloc(mpi_size * sizeof(int));
for (i = 0; i < mpi_size; i++) {
recvcounts[i] = count / mpi_size;
if (i < count % mpi_size) {
recvcounts[i]++;
}
num_ports[i] = 1;
}
handle1 =
EXT_MPI_Dry_reduce_scatter_native(mpi_size, recvcounts, num_ports);
handle2 = EXT_MPI_Dry_allgatherv_native(mpi_size, recvcounts, num_ports);
free(recvcounts);
free(num_ports);
*handle = EXT_MPI_Merge_collectives_native(handle1, handle2);
}
return (0);
}
| 35.60696 | 82 | 0.587315 |
594533e3a5cf9806923ac5dd2d56f2f9c5b6951e | 2,176 | h | C | ctags/main/trace.h | wonwooddo/vim_setup | 7555031a846ceb2986f491fd1738a5b5263af2f1 | [
"MIT"
] | null | null | null | ctags/main/trace.h | wonwooddo/vim_setup | 7555031a846ceb2986f491fd1738a5b5263af2f1 | [
"MIT"
] | null | null | null | ctags/main/trace.h | wonwooddo/vim_setup | 7555031a846ceb2986f491fd1738a5b5263af2f1 | [
"MIT"
] | null | null | null | #ifndef ctags_trace_h_
#define ctags_trace_h_
/*
* Copyright (c) 2016, Szymon Tomasz Stefanek
*
* This source code is released for free distribution under the terms of the
* GNU General Public License version 2 or (at your option) any later version.
*
* Tracing facility.
*/
#include "general.h"
#include "debug.h"
//
// Master tracing switch.
//
// Uncomment this to enable extensive debugging to stderr in code.
// Use only for development as tracing reduces performance.
//
// "./configure --enable-debugging" defines DEBUG.
//
#ifdef DEBUG
//#define TRACING_ENABLED 1
#endif
//
// Currently this kind of debugging is supported only on gcc (because of
// variadic macros and __PRETTY_FUNC__).
//
#if defined (__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 4))
#ifdef TRACING_ENABLED
#define DO_TRACING
#endif
#else
#ifdef TRACING_ENABLED
#error "Tracing is not supported on this compiler (yet)"
#endif
#endif
#ifdef DO_TRACING
void traceEnter(const char * szFunction,const char * szFormat,...);
void traceLeave(const char * szFunction,const char * szFormat,...);
void tracePrint(const char * szFunction,const char * szFormat,...);
#define TRACE_ENTER() traceEnter(__PRETTY_FUNCTION__,"")
#define TRACE_LEAVE() traceLeave(__PRETTY_FUNCTION__,"")
#define TRACE_ENTER_TEXT(_szFormat,...) \
traceEnter(__PRETTY_FUNCTION__,_szFormat,## __VA_ARGS__)
#define TRACE_LEAVE_TEXT(_szFormat,...) \
traceLeave(__PRETTY_FUNCTION__,_szFormat,## __VA_ARGS__)
#define TRACE_PRINT(_szFormat,...) \
tracePrint(__PRETTY_FUNCTION__,_szFormat,## __VA_ARGS__)
#define TRACE_ASSERT(_condition,_szFormat,...) \
do { \
if(!(_condition)) \
{ \
tracePrint(__PRETTY_FUNCTION__,_szFormat,## __VA_ARGS__); \
Assert(false); \
} \
} while(0)
#else //!DO_TRACING
#define TRACE_ENTER() do { } while(0)
#define TRACE_LEAVE() do { } while(0)
#define TRACE_ENTER_TEXT(_szFormat,...) do { } while(0)
#define TRACE_LEAVE_TEXT(_szFormat,...) do { } while(0)
#define TRACE_PRINT(_szFormat,...) do { } while(0)
#define TRACE_ASSERT(_condition,_szFormat,...) do { } while(0)
#endif //!DO_TRACING
#endif //!ctags_trace_h_
| 25.6 | 82 | 0.713235 |
3d5e049ff5e42c6373525989fd931237b25dbe73 | 1,577 | c | C | Parte 2/Ex_004.c | whoisgvb/works_C | eab1f39e165f9bb504f03d90323010927ea47b03 | [
"Apache-2.0"
] | 1 | 2021-06-25T01:21:19.000Z | 2021-06-25T01:21:19.000Z | Parte 2/Ex_004.c | whoisgvb/Works_C | eab1f39e165f9bb504f03d90323010927ea47b03 | [
"Apache-2.0"
] | null | null | null | Parte 2/Ex_004.c | whoisgvb/Works_C | eab1f39e165f9bb504f03d90323010927ea47b03 | [
"Apache-2.0"
] | null | null | null | /*4. Faça um procedimento que receba o vetor de registro definido no exercício anterior (30), por parâmetro, e retorna também por parâmetro: a média de salário entre os habitantes, a menor e a maior idade do grupo e a quantidade de mulheres com 3 filhos que recebe até R$500,00.*/
#include <stdio.h>
#include <stdlib.h>
#define N 2
int main()
{
int i, idade[N], sexo[N], salario[N], nFilhos[N], media, maior, menor, qtdMulheres;
for(i=0; i<N; i++)
{
printf("\nHabitante [%d], qual a sua idade?\n", i+1);
scanf("%d", &idade[i]);
if(i==0){
maior=idade[i];menor=idade[i];}
if(idade[i]>maior){
maior=idade[i];
}
else{
if(idade[i]<menor){
menor=idade[i];
}
}
printf("\nHabitante [%d], Informe o seu sexo:\n");
printf("[%d] feminino\n", 1);
printf("[%d] masculino\n", 2);
printf("[%d] android\n", 3);
printf("[%d] outros\n", 4);
scanf("%d", &sexo[i]);
printf("\nHabitante [%d], Qual o seu salário?\n");
scanf("%d", &salario[i]);
printf("\nHabitante [%d], Quantos filhos você tem?\n");
scanf("%d", &nFilhos[i]);
if(sexo[i] == 2 && nFilhos[i] <= 3 && salario[i] < 500){
qtdMulheres+=1;
}
media = salario[i]/500;
printf("\nA média de salários é: \n", media);
printf("\nA maior idade é: \n", maior);
printf("\nA menor idade é: \n", menor);
printf("\nA quantidade de mulheres com 3 filhos que recebe até R$500,00 é: \n", qtdMulheres);
}
for(i=0; i<N; i++)
{
printf("\nhabitante [%i] tem %d anos, é do sexo %d, recebe R$%d e tem %d filhos",i+1, idade[i], sexo[i], salario[i], nFilhos[i]);
}
return 0;
}
| 28.160714 | 280 | 0.607483 |
3806fc67c585c21b7c2cbd800105b5d72196efa7 | 269 | c | C | regression/contracts/history-constant/main.c | Kafva/cbmc | 8c1ab89ed09e646602c970b14bcc989dc57359f3 | [
"BSD-4-Clause"
] | null | null | null | regression/contracts/history-constant/main.c | Kafva/cbmc | 8c1ab89ed09e646602c970b14bcc989dc57359f3 | [
"BSD-4-Clause"
] | null | null | null | regression/contracts/history-constant/main.c | Kafva/cbmc | 8c1ab89ed09e646602c970b14bcc989dc57359f3 | [
"BSD-4-Clause"
] | null | null | null | #include <stdio.h>
int foo(int l) __CPROVER_requires(-10 <= l && l <= 10) __CPROVER_ensures(
__CPROVER_return_value == __CPROVER_old(l) + __CPROVER_old(10))
{
return l + 10;
}
int main()
{
int l;
__CPROVER_assume(-10 <= l && l <= 10);
foo(l);
return 0;
}
| 16.8125 | 73 | 0.624535 |
a863d673c4178760ba2c20b49fc14e9f01486833 | 752 | h | C | kernel/shared/hal/hal_frame.h | betopp/pathetix | a18a1211f6f3ca3c9ebd0e3de6784ae0591d1265 | [
"MIT"
] | null | null | null | kernel/shared/hal/hal_frame.h | betopp/pathetix | a18a1211f6f3ca3c9ebd0e3de6784ae0591d1265 | [
"MIT"
] | null | null | null | kernel/shared/hal/hal_frame.h | betopp/pathetix | a18a1211f6f3ca3c9ebd0e3de6784ae0591d1265 | [
"MIT"
] | null | null | null | //hal_frame.h
//Allocating and freeing physical frames
//Bryan E. Topp <betopp@betopp.com> 2021
#ifndef HAL_FRAME_H
#define HAL_FRAME_H
#include <stdint.h>
#include <sys/types.h>
//Identifies a physical frame.
typedef uint64_t hal_frame_id_t;
#define HAL_FRAME_ID_INVALID ((hal_frame_id_t)0)
//Returns the size of physical frames.
size_t hal_frame_size(void);
//Frees the given frame back to the frame allocator.
void hal_frame_free(hal_frame_id_t paddr);
//Allocates a frame from the frame allocator.
hal_frame_id_t hal_frame_alloc(void);
//Returns how many free frames are currently available.
size_t hal_frame_count(void);
//Copies a physical frame of memory
void hal_frame_copy(hal_frame_id_t dst, hal_frame_id_t src);
#endif //HAL_FRAME_H
| 25.066667 | 60 | 0.795213 |
b876a3869424788b6f23aae65a82fcfe061c31f7 | 313 | h | C | mame/src/lib/formats/vg5k_cas.h | clobber/MAME-OS-X | ca11d0e946636bda042b6db55c82113e5722fc08 | [
"MIT"
] | 15 | 2015-03-03T23:15:57.000Z | 2021-11-12T07:09:24.000Z | mame/src/lib/formats/vg5k_cas.h | clobber/MAME-OS-X | ca11d0e946636bda042b6db55c82113e5722fc08 | [
"MIT"
] | null | null | null | mame/src/lib/formats/vg5k_cas.h | clobber/MAME-OS-X | ca11d0e946636bda042b6db55c82113e5722fc08 | [
"MIT"
] | 8 | 2015-07-07T16:40:44.000Z | 2020-08-18T06:57:29.000Z | /*********************************************************************
vg5k_cas.h
*********************************************************************/
#ifndef VG5K_CAS_H
#define VG5K_CAS_H
#include "cassimg.h"
CASSETTE_FORMATLIST_EXTERN(vg5k_cassette_formats);
#endif /* VG5K_CAS_H */
| 19.5625 | 71 | 0.376997 |
071f5153a901cb361c549af6ddf1bdce6e670029 | 471 | c | C | 0x05-pointers_arrays_strings/100-atoi.c | jfbm74/holbertonschool-low_level_programming | 9cedaff870af333af5df085cdd776d43f48634d2 | [
"MIT"
] | null | null | null | 0x05-pointers_arrays_strings/100-atoi.c | jfbm74/holbertonschool-low_level_programming | 9cedaff870af333af5df085cdd776d43f48634d2 | [
"MIT"
] | null | null | null | 0x05-pointers_arrays_strings/100-atoi.c | jfbm74/holbertonschool-low_level_programming | 9cedaff870af333af5df085cdd776d43f48634d2 | [
"MIT"
] | null | null | null | /**
* _atoi - function that convert a string to an integer.
* @s: given string
* Return: integer
*/
int _atoi(char *s)
{
int i;
int x;
int sign;
int j;
i = j = x = 0;
sign = 1;
while (s[i] != '\0')
{
if (s[i] == '-')
{
sign = sign * -1;
}
else if (s[i] >= '0' && s[i] <= '9')
{
while (s[i] >= '0' && s[i] <= '9')
{
x = ((x * 10) + s[i] - 48);
i++;
}
x = sign * x;
return (x);
}
i++;
}
x = sign * x;
return (x);
}
| 13.083333 | 56 | 0.399151 |
8e42946e1785f0b9d714af20003249b701ba5083 | 594 | h | C | src/ciCMS/cfg/components/TexDraw.h | markkorput/ciCMS | a0ec32761ce712e78e31fe15e64ee9bd79c9bd51 | [
"MIT"
] | null | null | null | src/ciCMS/cfg/components/TexDraw.h | markkorput/ciCMS | a0ec32761ce712e78e31fe15e64ee9bd79c9bd51 | [
"MIT"
] | null | null | null | src/ciCMS/cfg/components/TexDraw.h | markkorput/ciCMS | a0ec32761ce712e78e31fe15e64ee9bd79c9bd51 | [
"MIT"
] | null | null | null | #pragma once
#include "cinder/gl/gl.h"
#include "ciCMS/cfg/Cfg.h"
namespace cms { namespace cfg { namespace components {
class TexDraw {
public:
void cfg(cms::cfg::Cfg& cfg);
private:
void draw();
private: //attrs
bool verbose = false;
bool bFillViewport = false;
// std::vector<ci::signals::Connection> connections;
ci::gl::TextureRef mTex = nullptr;
std::shared_ptr<ci::Rectf> rectRef = nullptr;
std::shared_ptr<ci::Area> fitCenteredAreaRef = nullptr;
std::shared_ptr<ci::Area> fillCenteredAreaRef = nullptr;
};
}}}
| 22.846154 | 62 | 0.638047 |
9079e0ef3fd33b228e5c7cadc34a9556a38ccbae | 3,001 | h | C | app/src/main/cpp/sensors/sensor_event_producer.h | horstle/wearmouse | f85cbf3d99a8cce9e9df9a896a9bf2efaaa3c9b2 | [
"Apache-2.0"
] | 1 | 2021-02-16T07:10:26.000Z | 2021-02-16T07:10:26.000Z | app/src/main/cpp/sensors/sensor_event_producer.h | horstle/wearmouse | f85cbf3d99a8cce9e9df9a896a9bf2efaaa3c9b2 | [
"Apache-2.0"
] | null | null | null | app/src/main/cpp/sensors/sensor_event_producer.h | horstle/wearmouse | f85cbf3d99a8cce9e9df9a896a9bf2efaaa3c9b2 | [
"Apache-2.0"
] | null | null | null | /*
* Copyright 2019 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef CARDBOARD_SDK_SENSORS_SENSOR_EVENT_PRODUCER_H_
#define CARDBOARD_SDK_SENSORS_SENSOR_EVENT_PRODUCER_H_
#include <functional>
#include <memory>
#include "sensors/sensor_thread_callbacks.h"
namespace cardboard {
// Stream publisher that reads sensor data from the device sensors.
// Sensor polling starts as soon as a subscriber is connected.
//
// For the system to be able to poll from a sensor one needs to connect a
// subscriber. You can stop and restart polling at anytime after you connected a
// subscriber.
template <typename DataType>
class SensorEventProducer {
public:
// Constructs a sensor publisher based on the sensor_name that is passed in.
// It will fall back to the default sensor if the specified sensor cannot be
// found.
SensorEventProducer(const int sampling_period_us,
SensorThreadCallbacks* callbacks);
~SensorEventProducer();
// Registers callback and starts polling from DeviceSensor if it is not
// running yet. This is a no-op if the sensor is not supported by the
// platform.
void StartSensorPolling(
const std::function<void(DataType)>* on_event_callback);
// This stops DeviceSensor sensor polling if it is currently
// running. This method blocks until the sensor capture thread is finished.
void StopSensorPolling();
private:
// Internal function to start sensor polling with the assumption that the lock
// has already been obtained. Not implemented for iOS.
void StartSensorPollingLocked();
// Internal function to stop sensor polling with the assumption that the lock
// has already been obtained. Not implemented for iOS.
void StopSensorPollingLocked();
// Worker method that polls for sensor data and executes OnSensor. This may
// bind to a thread or be used as a callback for a task loop depending on the
// implementation.
void WorkFn();
// The implementation of device sensors differs between iOS and Android.
struct EventProducer;
std::unique_ptr<EventProducer> event_producer_;
int sampling_period_us_;
SensorThreadCallbacks* thread_callbacks_;
// Maximum waiting time for sensor events.
static const int kMaxWaitMilliseconds = 100;
// Callbacks to call when OnEvent() is called.
const std::function<void(DataType)>* on_event_callback_;
};
} // namespace cardboard
#endif // CARDBOARD_SDK_SENSORS_SENSOR_EVENT_PRODUCER_H_
| 36.156627 | 80 | 0.75908 |
e6d0bdd16f216521111ae0498084d1efe4ff9201 | 1,951 | h | C | src/backend/quad/ast2quad/ivlist.h | zhongxinghong/sysyc | b3cde82c985dc40c2e564e82e4c41db76a992eb8 | [
"MIT"
] | 2 | 2021-11-16T09:46:20.000Z | 2022-03-24T11:49:34.000Z | src/backend/quad/ast2quad/ivlist.h | zhongxinghong/sysyc | b3cde82c985dc40c2e564e82e4c41db76a992eb8 | [
"MIT"
] | null | null | null | src/backend/quad/ast2quad/ivlist.h | zhongxinghong/sysyc | b3cde82c985dc40c2e564e82e4c41db76a992eb8 | [
"MIT"
] | 2 | 2022-02-23T06:34:52.000Z | 2022-03-13T04:05:40.000Z | //------------------------------------------------------------------------------
// A SysY Compiler for PKU Compiling Principles Practice Course (2021 Spring)
//------------------------------------------------------------------------------
// Project: sysyc
// File: ivlist.h
// Created Date: 2021-05-22
// Author: Zhong Xinghong (1700012608)
// Email: zxh2017@pku.edu.cn
//------------------------------------------------------------------------------
// Copyright (c) 2021 Zhong Xinghong
//------------------------------------------------------------------------------
#ifndef __SYSYC_BACKEND_QUAD_AST2QUAD_IVLIST_H__
#define __SYSYC_BACKEND_QUAD_AST2QUAD_IVLIST_H__
#include <stack>
#include <exception>
#include "middle/ast/node.h"
#include "middle/ast/generator.h"
namespace sysyc
{
namespace backend
{
namespace quad
{
namespace __impl
{
class quadgen_ivlist_iterator
{
public:
class exception : public std::exception
{
public:
exception(const std::string &errmsg) : errmsg(errmsg) {}
virtual const char *what() const noexcept override { return errmsg.c_str(); }
private:
std::string errmsg;
};
public:
quadgen_ivlist_iterator(const middle::ast::ASTNode *ast,
const std::vector<std::size_t> &dim_list,
middle::ast::IASTGenerator *generator);
bool next();
std::size_t get_ix() const { return pos - 1; }
private:
struct cursor_s
{
const std::vector<middle::ast::ASTNode *> &list;
std::size_t dim;
std::size_t pos;
std::size_t start_pos;
const middle::ast::ASTNode *ast() const { return list[pos]; }
};
middle::ast::IASTGenerator *generator;
bool const_;
std::vector<std::size_t> dim_list;
std::vector<std::size_t> dim_size;
std::stack<cursor_s> st;
std::size_t pos;
};
} // namespace __impl
} // namespace quad
} // namespace backend
} // namespace sysyc
#endif // __SYSYC_BACKEND_QUAD_AST2QUAD_IVLIST_H__
| 24.3875 | 81 | 0.572014 |
0aa5477b7a51789b9d8b9a1470a371aafd9b39e1 | 118 | h | C | Pod/Classes/boogaloo/UIFont+Boogaloo.h | parakeety/GoogleFontsiOS | 46a0d144b32b14f06f3605568ab210ad390c8e96 | [
"MIT"
] | 10 | 2015-08-07T19:43:38.000Z | 2019-03-06T10:40:11.000Z | Pod/Classes/boogaloo/UIFont+Boogaloo.h | Maxatma/GoogleFontsiOS | 46a0d144b32b14f06f3605568ab210ad390c8e96 | [
"MIT"
] | 3 | 2016-03-01T10:29:45.000Z | 2017-03-30T12:23:06.000Z | Pod/Classes/boogaloo/UIFont+Boogaloo.h | Maxatma/GoogleFontsiOS | 46a0d144b32b14f06f3605568ab210ad390c8e96 | [
"MIT"
] | 4 | 2016-02-10T12:34:29.000Z | 2020-04-08T07:18:23.000Z | #import <UIKit/UIKit.h>
@interface UIFont (Boogaloo)
+ (instancetype)boogalooRegularFontOfSize:(CGFloat)size;
@end
| 14.75 | 56 | 0.771186 |
f8aeb74c62bc304f070107a30ddc029bdc01be81 | 1,068 | c | C | libft/ft_strcpy.c | tiboitel/FTP | 4de46c720d1accc67518f954ced3cc3491048432 | [
"MIT"
] | null | null | null | libft/ft_strcpy.c | tiboitel/FTP | 4de46c720d1accc67518f954ced3cc3491048432 | [
"MIT"
] | null | null | null | libft/ft_strcpy.c | tiboitel/FTP | 4de46c720d1accc67518f954ced3cc3491048432 | [
"MIT"
] | null | null | null | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tiboitel <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/11/03 18:35:04 by tiboitel #+# #+# */
/* Updated: 2014/11/04 17:48:47 by tiboitel ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
char *ft_strcpy(char *dest, const char *src)
{
int i;
i = 0;
while (src[i] != '\0')
{
dest[i] = src[i];
i++;
}
dest[i] = '\0';
return (dest);
}
| 38.142857 | 80 | 0.170412 |
f8e04afa7e79154e3de566127c458c5135410526 | 35,057 | c | C | lugre/baselib/openal-soft-1.8.466/Alc/alsa.c | ghoulsblade/vegaogre | 2ece3b799f9bd667f081d47c1a0f3ef5e78d3e0f | [
"MIT"
] | 1 | 2020-10-18T14:33:05.000Z | 2020-10-18T14:33:05.000Z | lugre/baselib/openal-soft-1.8.466/Alc/alsa.c | ghoulsblade/vegaogre | 2ece3b799f9bd667f081d47c1a0f3ef5e78d3e0f | [
"MIT"
] | null | null | null | lugre/baselib/openal-soft-1.8.466/Alc/alsa.c | ghoulsblade/vegaogre | 2ece3b799f9bd667f081d47c1a0f3ef5e78d3e0f | [
"MIT"
] | null | null | null | /**
* OpenAL cross platform audio library
* Copyright (C) 1999-2007 by authors.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
* Or go to http://www.gnu.org/copyleft/lgpl.html
*/
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <memory.h>
#ifdef HAVE_DLFCN_H
#include <dlfcn.h>
#endif
#include "alMain.h"
#include "AL/al.h"
#include "AL/alc.h"
#include <alsa/asoundlib.h>
typedef struct {
snd_pcm_t *pcmHandle;
snd_pcm_format_t format;
ALvoid *buffer;
ALsizei size;
RingBuffer *ring;
int doCapture;
volatile int killNow;
ALvoid *thread;
} alsa_data;
typedef struct {
ALCchar *name;
int card, dev;
} DevMap;
static void *alsa_handle;
#define MAKE_FUNC(f) static typeof(f) * p##f
MAKE_FUNC(snd_strerror);
MAKE_FUNC(snd_pcm_open);
MAKE_FUNC(snd_pcm_close);
MAKE_FUNC(snd_pcm_nonblock);
MAKE_FUNC(snd_pcm_frames_to_bytes);
MAKE_FUNC(snd_pcm_hw_params_malloc);
MAKE_FUNC(snd_pcm_hw_params_free);
MAKE_FUNC(snd_pcm_hw_params_any);
MAKE_FUNC(snd_pcm_hw_params_set_access);
MAKE_FUNC(snd_pcm_hw_params_set_format);
MAKE_FUNC(snd_pcm_hw_params_set_channels);
MAKE_FUNC(snd_pcm_hw_params_set_periods_near);
MAKE_FUNC(snd_pcm_hw_params_set_rate_near);
MAKE_FUNC(snd_pcm_hw_params_set_rate);
MAKE_FUNC(snd_pcm_hw_params_set_buffer_size_near);
MAKE_FUNC(snd_pcm_hw_params_set_buffer_size_min);
MAKE_FUNC(snd_pcm_hw_params_get_buffer_size);
MAKE_FUNC(snd_pcm_hw_params_get_period_size);
MAKE_FUNC(snd_pcm_hw_params_get_access);
MAKE_FUNC(snd_pcm_hw_params);
MAKE_FUNC(snd_pcm_sw_params_malloc);
MAKE_FUNC(snd_pcm_sw_params_current);
MAKE_FUNC(snd_pcm_sw_params_set_avail_min);
MAKE_FUNC(snd_pcm_sw_params);
MAKE_FUNC(snd_pcm_sw_params_free);
MAKE_FUNC(snd_pcm_prepare);
MAKE_FUNC(snd_pcm_start);
MAKE_FUNC(snd_pcm_resume);
MAKE_FUNC(snd_pcm_wait);
MAKE_FUNC(snd_pcm_state);
MAKE_FUNC(snd_pcm_avail_update);
MAKE_FUNC(snd_pcm_areas_silence);
MAKE_FUNC(snd_pcm_mmap_begin);
MAKE_FUNC(snd_pcm_mmap_commit);
MAKE_FUNC(snd_pcm_readi);
MAKE_FUNC(snd_pcm_writei);
MAKE_FUNC(snd_pcm_drain);
MAKE_FUNC(snd_pcm_info_malloc);
MAKE_FUNC(snd_pcm_info_free);
MAKE_FUNC(snd_pcm_info_set_device);
MAKE_FUNC(snd_pcm_info_set_subdevice);
MAKE_FUNC(snd_pcm_info_set_stream);
MAKE_FUNC(snd_pcm_info_get_name);
MAKE_FUNC(snd_ctl_pcm_next_device);
MAKE_FUNC(snd_ctl_pcm_info);
MAKE_FUNC(snd_ctl_open);
MAKE_FUNC(snd_ctl_close);
MAKE_FUNC(snd_ctl_card_info_malloc);
MAKE_FUNC(snd_ctl_card_info_free);
MAKE_FUNC(snd_ctl_card_info);
MAKE_FUNC(snd_ctl_card_info_get_name);
MAKE_FUNC(snd_card_next);
#undef MAKE_FUNC
#define MAX_ALL_DEVICES 32
static ALCchar *alsaDevice;
static DevMap allDevNameMap[MAX_ALL_DEVICES];
static DevMap allCaptureDevNameMap[MAX_ALL_DEVICES];
static int xrun_recovery(snd_pcm_t *handle, int err)
{
if (err == -EPIPE)
{ /* under-run */
err = psnd_pcm_prepare(handle);
if (err < 0)
AL_PRINT("prepare failed: %s\n", psnd_strerror(err));
}
else if (err == -ESTRPIPE)
{
while ((err = psnd_pcm_resume(handle)) == -EAGAIN)
Sleep(1); /* wait until the suspend flag is released */
if (err < 0)
{
err = psnd_pcm_prepare(handle);
if (err < 0)
AL_PRINT("prepare failed: %s\n", psnd_strerror(err));
}
}
return err;
}
static ALuint ALSAProc(ALvoid *ptr)
{
ALCdevice *pDevice = (ALCdevice*)ptr;
alsa_data *data = (alsa_data*)pDevice->ExtraData;
const snd_pcm_channel_area_t *areas = NULL;
snd_pcm_sframes_t avail, commitres;
snd_pcm_uframes_t offset, frames;
char *WritePtr;
int WriteCnt;
int err;
while(!data->killNow)
{
snd_pcm_state_t state = psnd_pcm_state(data->pcmHandle);
if(state == SND_PCM_STATE_XRUN)
{
err = xrun_recovery(data->pcmHandle, -EPIPE);
if (err < 0)
{
AL_PRINT("XRUN recovery failed: %s\n", psnd_strerror(err));
break;
}
}
else if (state == SND_PCM_STATE_SUSPENDED)
{
err = xrun_recovery(data->pcmHandle, -ESTRPIPE);
if (err < 0)
{
AL_PRINT("SUSPEND recovery failed: %s\n", psnd_strerror(err));
break;
}
}
avail = psnd_pcm_avail_update(data->pcmHandle);
if(avail < 0)
{
err = xrun_recovery(data->pcmHandle, avail);
if (err < 0)
{
AL_PRINT("available update failed: %s\n", psnd_strerror(err));
break;
}
}
// make sure there's frames to process
if(avail >= 0 && avail < (snd_pcm_sframes_t)pDevice->UpdateSize)
{
if(state != SND_PCM_STATE_RUNNING)
{
err = psnd_pcm_start(data->pcmHandle);
if(err < 0)
err = xrun_recovery(data->pcmHandle, err);
if(err < 0)
{
AL_PRINT("start failed: %s\n", psnd_strerror(err));
break;
}
}
else if(psnd_pcm_wait(data->pcmHandle, 1000) == 0)
AL_PRINT("Wait timeout... buffer size too low?\n");
continue;
}
avail = pDevice->UpdateSize;
// it is possible that contiguous areas are smaller, thus we use a loop
while (avail > 0)
{
frames = avail;
SuspendContext(NULL);
err = psnd_pcm_mmap_begin(data->pcmHandle, &areas, &offset, &frames);
if (err < 0)
{
err = xrun_recovery(data->pcmHandle, err);
if (err < 0)
AL_PRINT("mmap begin error: %s\n", psnd_strerror(err));
ProcessContext(NULL);
break;
}
WritePtr = (char*)areas->addr + (offset * areas->step / 8);
WriteCnt = psnd_pcm_frames_to_bytes(data->pcmHandle, frames);
aluMixData(pDevice->Context, WritePtr, WriteCnt, pDevice->Format);
commitres = psnd_pcm_mmap_commit(data->pcmHandle, offset, frames);
if (commitres < 0 || (commitres-frames) != 0)
{
AL_PRINT("mmap commit error: %s\n",
psnd_strerror(commitres >= 0 ? -EPIPE : commitres));
ProcessContext(NULL);
break;
}
ProcessContext(NULL);
avail -= frames;
}
}
return 0;
}
static ALuint ALSANoMMapProc(ALvoid *ptr)
{
ALCdevice *pDevice = (ALCdevice*)ptr;
alsa_data *data = (alsa_data*)pDevice->ExtraData;
snd_pcm_sframes_t avail;
char *WritePtr;
while(!data->killNow)
{
SuspendContext(NULL);
aluMixData(pDevice->Context, data->buffer, data->size, pDevice->Format);
ProcessContext(NULL);
WritePtr = data->buffer;
avail = (snd_pcm_uframes_t)data->size / psnd_pcm_frames_to_bytes(data->pcmHandle, 1);
while(avail > 0)
{
int ret = psnd_pcm_writei(data->pcmHandle, WritePtr, avail);
switch (ret)
{
case -EAGAIN:
continue;
case -ESTRPIPE:
while((ret=psnd_pcm_resume(data->pcmHandle)) == -EAGAIN)
Sleep(1);
break;
case -EPIPE:
break;
default:
if (ret >= 0)
{
WritePtr += psnd_pcm_frames_to_bytes(data->pcmHandle, ret);
avail -= ret;
}
break;
}
if (ret < 0)
{
ret = psnd_pcm_prepare(data->pcmHandle);
if(ret < 0)
break;
}
}
}
return 0;
}
static ALuint ALSANoMMapCaptureProc(ALvoid *ptr)
{
ALCdevice *pDevice = (ALCdevice*)ptr;
alsa_data *data = (alsa_data*)pDevice->ExtraData;
snd_pcm_sframes_t avail;
while(!data->killNow)
{
avail = (snd_pcm_uframes_t)data->size / psnd_pcm_frames_to_bytes(data->pcmHandle, 1);
avail = psnd_pcm_readi(data->pcmHandle, data->buffer, avail);
switch(avail)
{
case -EAGAIN:
continue;
case -ESTRPIPE:
while((avail=psnd_pcm_resume(data->pcmHandle)) == -EAGAIN)
Sleep(1);
break;
case -EPIPE:
break;
default:
if (avail >= 0 && data->doCapture)
WriteRingBuffer(data->ring, data->buffer, avail);
break;
}
if(avail < 0)
{
avail = psnd_pcm_prepare(data->pcmHandle);
if(avail < 0)
AL_PRINT("prepare error: %s\n", psnd_strerror(avail));
}
}
return 0;
}
static ALCboolean alsa_open_playback(ALCdevice *device, const ALCchar *deviceName)
{
snd_pcm_uframes_t bufferSizeInFrames;
snd_pcm_sw_params_t *sp = NULL;
snd_pcm_hw_params_t *p = NULL;
snd_pcm_access_t access;
unsigned int periods;
unsigned int rate;
alsa_data *data;
char driver[64];
const char *str;
int allowmmap;
char *err;
int i;
if(!alsa_handle)
return ALC_FALSE;
strncpy(driver, GetConfigValue("alsa", "device", "default"), sizeof(driver)-1);
driver[sizeof(driver)-1] = 0;
if(deviceName)
{
size_t idx;
for(idx = 0;idx < MAX_ALL_DEVICES;idx++)
{
if(allDevNameMap[idx].name &&
strcmp(deviceName, allDevNameMap[idx].name) == 0)
{
device->szDeviceName = allDevNameMap[idx].name;
if(idx > 0)
sprintf(driver, "hw:%d,%d", allDevNameMap[idx].card, allDevNameMap[idx].dev);
goto open_alsa;
}
}
if(strcmp(deviceName, alsaDevice) == 0)
{
device->szDeviceName = alsaDevice;
goto open_alsa;
}
return ALC_FALSE;
}
else
device->szDeviceName = alsaDevice;
open_alsa:
data = (alsa_data*)calloc(1, sizeof(alsa_data));
i = psnd_pcm_open(&data->pcmHandle, driver, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
if(i < 0)
{
Sleep(200);
i = psnd_pcm_open(&data->pcmHandle, driver, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
}
if(i >= 0)
{
i = psnd_pcm_nonblock(data->pcmHandle, 0);
if(i < 0)
psnd_pcm_close(data->pcmHandle);
}
if(i < 0)
{
free(data);
AL_PRINT("Could not open playback device '%s': %s\n", driver, psnd_strerror(i));
return ALC_FALSE;
}
switch(aluBytesFromFormat(device->Format))
{
case 1:
data->format = SND_PCM_FORMAT_U8;
break;
case 2:
data->format = SND_PCM_FORMAT_S16;
break;
default:
data->format = SND_PCM_FORMAT_UNKNOWN;
AL_PRINT("Unknown format?! %x\n", device->Format);
}
periods = GetConfigValueInt("alsa", "periods", 0);
bufferSizeInFrames = device->UpdateSize;
rate = device->Frequency;
str = GetConfigValue("alsa", "mmap", "true");
allowmmap = (strcasecmp(str, "true") == 0 ||
strcasecmp(str, "yes") == 0 ||
strcasecmp(str, "on") == 0 ||
atoi(str) != 0);
err = NULL;
psnd_pcm_hw_params_malloc(&p);
if((i=psnd_pcm_hw_params_any(data->pcmHandle, p)) < 0)
err = "any";
/* set interleaved access */
if(err == NULL && (!allowmmap || (i=psnd_pcm_hw_params_set_access(data->pcmHandle, p, SND_PCM_ACCESS_MMAP_INTERLEAVED)) < 0))
{
if((i=psnd_pcm_hw_params_set_access(data->pcmHandle, p, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
err = "set access";
}
/* set format (implicitly sets sample bits) */
if(err == NULL && (i=psnd_pcm_hw_params_set_format(data->pcmHandle, p, data->format)) < 0)
err = "set format";
/* set channels (implicitly sets frame bits) */
if(err == NULL && (i=psnd_pcm_hw_params_set_channels(data->pcmHandle, p, aluChannelsFromFormat(device->Format))) < 0)
err = "set channels";
/* set periods (implicitly constrains period/buffer parameters) */
if(err == NULL && periods && (i=psnd_pcm_hw_params_set_periods_near(data->pcmHandle, p, &periods, NULL)) < 0)
err = "set periods near";
/* set rate (implicitly constrains period/buffer parameters) */
if(err == NULL && (i=psnd_pcm_hw_params_set_rate_near(data->pcmHandle, p, &rate, NULL)) < 0)
err = "set rate near";
/* set buffer size in frame units (implicitly sets period size/bytes/time and buffer time/bytes) */
if(err == NULL && (i=psnd_pcm_hw_params_set_buffer_size_near(data->pcmHandle, p, &bufferSizeInFrames)) < 0)
err = "set buffer size near";
/* install and prepare hardware configuration */
if(err == NULL && (i=psnd_pcm_hw_params(data->pcmHandle, p)) < 0)
err = "set params";
if(err == NULL && (i=psnd_pcm_hw_params_get_access(p, &access)) < 0)
err = "get access";
if(err == NULL && (i=psnd_pcm_hw_params_get_period_size(p, &bufferSizeInFrames, NULL)) < 0)
err = "get period size";
if(err != NULL)
{
AL_PRINT("%s failed: %s\n", err, psnd_strerror(i));
psnd_pcm_hw_params_free(p);
psnd_pcm_close(data->pcmHandle);
free(data);
return ALC_FALSE;
}
psnd_pcm_hw_params_free(p);
err = NULL;
psnd_pcm_sw_params_malloc(&sp);
if((i=psnd_pcm_sw_params_current(data->pcmHandle, sp)) != 0)
err = "sw current";
if(err == NULL && (i=psnd_pcm_sw_params_set_avail_min(data->pcmHandle, sp, bufferSizeInFrames)) != 0)
err = "sw set avail min";
if(err == NULL && (i=psnd_pcm_sw_params(data->pcmHandle, sp)) != 0)
err = "sw set params";
if(err != NULL)
{
AL_PRINT("%s failed: %s\n", err, psnd_strerror(i));
psnd_pcm_sw_params_free(sp);
psnd_pcm_close(data->pcmHandle);
free(data);
return ALC_FALSE;
}
psnd_pcm_sw_params_free(sp);
data->size = psnd_pcm_frames_to_bytes(data->pcmHandle, bufferSizeInFrames);
if(access == SND_PCM_ACCESS_RW_INTERLEAVED)
{
data->buffer = malloc(data->size);
if(!data->buffer)
{
AL_PRINT("buffer malloc failed\n");
psnd_pcm_close(data->pcmHandle);
free(data);
return ALC_FALSE;
}
}
else
{
i = psnd_pcm_prepare(data->pcmHandle);
if(i < 0)
{
AL_PRINT("prepare error: %s\n", psnd_strerror(i));
psnd_pcm_close(data->pcmHandle);
free(data->buffer);
free(data);
return ALC_FALSE;
}
}
device->ExtraData = data;
if(access == SND_PCM_ACCESS_RW_INTERLEAVED)
data->thread = StartThread(ALSANoMMapProc, device);
else
data->thread = StartThread(ALSAProc, device);
if(data->thread == NULL)
{
AL_PRINT("Could not create playback thread\n");
psnd_pcm_close(data->pcmHandle);
device->ExtraData = NULL;
free(data->buffer);
free(data);
return ALC_FALSE;
}
device->UpdateSize = bufferSizeInFrames;
device->Frequency = rate;
return ALC_TRUE;
}
static void alsa_close_playback(ALCdevice *device)
{
alsa_data *data = (alsa_data*)device->ExtraData;
data->killNow = 1;
StopThread(data->thread);
psnd_pcm_close(data->pcmHandle);
free(data->buffer);
free(data);
device->ExtraData = NULL;
}
static ALCboolean alsa_open_capture(ALCdevice *pDevice, const ALCchar *deviceName, ALCuint frequency, ALCenum format, ALCsizei SampleSize)
{
snd_pcm_format_t alsaFormat;
snd_pcm_hw_params_t *p;
snd_pcm_uframes_t bufferSizeInFrames;
snd_pcm_access_t access;
const char *str;
alsa_data *data;
char driver[64];
int allowmmap;
char *err;
int i;
if(!alsa_handle)
return ALC_FALSE;
strncpy(driver, GetConfigValue("alsa", "capture", "default"), sizeof(driver)-1);
driver[sizeof(driver)-1] = 0;
if(deviceName)
{
size_t idx;
for(idx = 0;idx < MAX_ALL_DEVICES;idx++)
{
if(allCaptureDevNameMap[idx].name &&
strcmp(deviceName, allCaptureDevNameMap[idx].name) == 0)
{
pDevice->szDeviceName = allCaptureDevNameMap[idx].name;
if(idx > 0)
sprintf(driver, "plughw:%d,%d", allCaptureDevNameMap[idx].card, allCaptureDevNameMap[idx].dev);
goto open_alsa;
}
}
return ALC_FALSE;
}
else
pDevice->szDeviceName = allCaptureDevNameMap[0].name;
open_alsa:
data = (alsa_data*)calloc(1, sizeof(alsa_data));
i = psnd_pcm_open(&data->pcmHandle, driver, SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK);
if(i < 0)
{
Sleep(200);
i = psnd_pcm_open(&data->pcmHandle, driver, SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK);
}
if(i >= 0)
{
i = psnd_pcm_nonblock(data->pcmHandle, 0);
if(i < 0)
psnd_pcm_close(data->pcmHandle);
}
if(i < 0)
{
free(data);
AL_PRINT("Could not open capture device '%s': %s\n", driver, psnd_strerror(i));
return ALC_FALSE;
}
switch(aluBytesFromFormat(format))
{
case 1:
alsaFormat = SND_PCM_FORMAT_U8;
break;
case 2:
alsaFormat = SND_PCM_FORMAT_S16;
break;
default:
alsaFormat = SND_PCM_FORMAT_UNKNOWN;
AL_PRINT("Unknown format?! %x\n", format);
}
str = GetConfigValue("alsa", "mmap", "true");
allowmmap = (strcasecmp(str, "true") == 0 ||
strcasecmp(str, "yes") == 0 ||
strcasecmp(str, "on") == 0 ||
atoi(str) != 0);
err = NULL;
bufferSizeInFrames = SampleSize;
psnd_pcm_hw_params_malloc(&p);
if(!allowmmap)
err = "no mmap";
if((i=psnd_pcm_hw_params_any(data->pcmHandle, p)) < 0)
err = "any";
/* set interleaved access */
if(err == NULL && (i=psnd_pcm_hw_params_set_access(data->pcmHandle, p, SND_PCM_ACCESS_MMAP_INTERLEAVED)) < 0)
{
err = "set access";
allowmmap = 0;
}
/* set format (implicitly sets sample bits) */
if(err == NULL && (i=psnd_pcm_hw_params_set_format(data->pcmHandle, p, data->format)) < 0)
err = "set format";
/* set channels (implicitly sets frame bits) */
if(err == NULL && (i=psnd_pcm_hw_params_set_channels(data->pcmHandle, p, aluChannelsFromFormat(pDevice->Format))) < 0)
err = "set channels";
/* set rate (implicitly constrains period/buffer parameters) */
if(err == NULL && (i=psnd_pcm_hw_params_set_rate(data->pcmHandle, p, frequency, 0)) < 0)
err = "set rate near";
/* set buffer size in frame units (implicitly sets period size/bytes/time and buffer time/bytes) */
if(err == NULL && (i=psnd_pcm_hw_params_set_buffer_size_min(data->pcmHandle, p, &bufferSizeInFrames)) < 0)
{
err = "set buffer size min";
allowmmap = 0;
}
/* install and prepare hardware configuration */
if(err == NULL && (i=psnd_pcm_hw_params(data->pcmHandle, p)) < 0)
err = "set params";
if(!allowmmap)
{
err = NULL;
if((i=psnd_pcm_hw_params_any(data->pcmHandle, p)) < 0)
err = "any";
/* set interleaved access */
if(err == NULL && (i=psnd_pcm_hw_params_set_access(data->pcmHandle, p, SND_PCM_ACCESS_MMAP_INTERLEAVED)) < 0)
err = "set access";
/* set format (implicitly sets sample bits) */
if(err == NULL && (i=psnd_pcm_hw_params_set_format(data->pcmHandle, p, data->format)) < 0)
err = "set format";
/* set channels (implicitly sets frame bits) */
if(err == NULL && (i=psnd_pcm_hw_params_set_channels(data->pcmHandle, p, aluChannelsFromFormat(pDevice->Format))) < 0)
err = "set channels";
/* set rate (implicitly constrains period/buffer parameters) */
if(err == NULL && (i=psnd_pcm_hw_params_set_rate(data->pcmHandle, p, frequency, 0)) < 0)
err = "set rate near";
/* set buffer size in frame units (implicitly sets period size/bytes/time and buffer time/bytes) */
if(err == NULL && (i=psnd_pcm_hw_params_set_buffer_size_near(data->pcmHandle, p, &bufferSizeInFrames)) < 0)
err = "set buffer size near";
/* install and prepare hardware configuration */
if(err == NULL && (i=psnd_pcm_hw_params(data->pcmHandle, p)) < 0)
err = "set params";
}
if(err != NULL)
{
AL_PRINT("%s failed: %s\n", err, psnd_strerror(i));
psnd_pcm_hw_params_free(p);
psnd_pcm_close(data->pcmHandle);
free(data);
return ALC_FALSE;
}
if((i=psnd_pcm_hw_params_get_access(p, &access)) < 0)
{
AL_PRINT("get_access failed: %s\n", psnd_strerror(i));
psnd_pcm_hw_params_free(p);
psnd_pcm_close(data->pcmHandle);
free(data);
return ALC_FALSE;
}
if((i=psnd_pcm_hw_params_get_period_size(p, &bufferSizeInFrames, NULL)) < 0)
{
AL_PRINT("get size failed: %s\n", psnd_strerror(i));
psnd_pcm_hw_params_free(p);
psnd_pcm_close(data->pcmHandle);
free(data);
return ALC_FALSE;
}
psnd_pcm_hw_params_free(p);
if(access == SND_PCM_ACCESS_RW_INTERLEAVED)
{
ALuint frameSize = aluChannelsFromFormat(pDevice->Format);
frameSize *= aluBytesFromFormat(pDevice->Format);
data->ring = CreateRingBuffer(frameSize, SampleSize);
if(!data->ring)
{
AL_PRINT("ring buffer create failed\n");
psnd_pcm_close(data->pcmHandle);
free(data);
return ALC_FALSE;
}
data->size = psnd_pcm_frames_to_bytes(data->pcmHandle, bufferSizeInFrames);
data->buffer = malloc(data->size);
if(!data->buffer)
{
AL_PRINT("buffer malloc failed\n");
psnd_pcm_close(data->pcmHandle);
DestroyRingBuffer(data->ring);
free(data);
return ALC_FALSE;
}
pDevice->ExtraData = data;
data->thread = StartThread(ALSANoMMapCaptureProc, pDevice);
if(data->thread == NULL)
{
AL_PRINT("Could not create capture thread\n");
pDevice->ExtraData = NULL;
psnd_pcm_close(data->pcmHandle);
DestroyRingBuffer(data->ring);
free(data->buffer);
free(data);
return ALC_FALSE;
}
}
else
{
i = psnd_pcm_prepare(data->pcmHandle);
if(i < 0)
{
AL_PRINT("prepare error: %s\n", psnd_strerror(i));
psnd_pcm_close(data->pcmHandle);
free(data);
return ALC_FALSE;
}
pDevice->ExtraData = data;
}
return ALC_TRUE;
}
static void alsa_close_capture(ALCdevice *pDevice)
{
alsa_data *data = (alsa_data*)pDevice->ExtraData;
if(data->thread)
{
data->killNow = 1;
StopThread(data->thread);
DestroyRingBuffer(data->ring);
}
psnd_pcm_close(data->pcmHandle);
free(data);
pDevice->ExtraData = NULL;
}
static void alsa_start_capture(ALCdevice *pDevice)
{
alsa_data *data = (alsa_data*)pDevice->ExtraData;
data->doCapture = 1;
if(!data->thread)
{
psnd_pcm_prepare(data->pcmHandle);
psnd_pcm_start(data->pcmHandle);
}
}
static void alsa_stop_capture(ALCdevice *pDevice)
{
alsa_data *data = (alsa_data*)pDevice->ExtraData;
data->doCapture = 0;
if(!data->thread)
psnd_pcm_drain(data->pcmHandle);
}
static void alsa_capture_samples(ALCdevice *pDevice, ALCvoid *pBuffer, ALCuint lSamples)
{
alsa_data *data = (alsa_data*)pDevice->ExtraData;
const snd_pcm_channel_area_t *areas = NULL;
snd_pcm_sframes_t frames, commitres;
snd_pcm_uframes_t size, offset;
snd_pcm_state_t state;
int err;
if(data->thread)
{
if(lSamples <= (ALCuint)RingBufferSize(data->ring))
ReadRingBuffer(data->ring, pBuffer, lSamples);
else
SetALCError(ALC_INVALID_VALUE);
return;
}
state = psnd_pcm_state(data->pcmHandle);
if(state == SND_PCM_STATE_XRUN)
{
err = xrun_recovery(data->pcmHandle, -EPIPE);
if(err < 0)
{
AL_PRINT("XRUN recovery failed: %s\n", psnd_strerror(err));
return;
}
}
frames = psnd_pcm_avail_update(data->pcmHandle);
if(frames < 0)
{
err = xrun_recovery(data->pcmHandle, frames);
if (err < 0)
AL_PRINT("available update failed: %s\n", psnd_strerror(err));
else
frames = psnd_pcm_avail_update(data->pcmHandle);
}
if (frames < (snd_pcm_sframes_t)lSamples)
{
SetALCError(ALC_INVALID_VALUE);
return;
}
// it is possible that contiguous areas are smaller, thus we use a loop
while (lSamples > 0)
{
char *Pointer;
int Count;
size = lSamples;
err = psnd_pcm_mmap_begin(data->pcmHandle, &areas, &offset, &size);
if (err < 0)
{
err = xrun_recovery(data->pcmHandle, err);
if (err < 0)
{
AL_PRINT("mmap begin error: %s\n", psnd_strerror(err));
break;
}
continue;
}
Pointer = (char*)areas->addr + (offset * areas->step / 8);
Count = psnd_pcm_frames_to_bytes(data->pcmHandle, size);
memcpy(pBuffer, Pointer, Count);
pBuffer = (char*)pBuffer + Count;
commitres = psnd_pcm_mmap_commit(data->pcmHandle, offset, size);
if (commitres < 0 || (commitres-size) != 0)
{
AL_PRINT("mmap commit error: %s\n",
psnd_strerror(commitres >= 0 ? -EPIPE : commitres));
break;
}
lSamples -= size;
}
}
static ALCuint alsa_available_samples(ALCdevice *pDevice)
{
alsa_data *data = (alsa_data*)pDevice->ExtraData;
snd_pcm_sframes_t frames;
snd_pcm_state_t state;
int err;
if(data->thread)
return RingBufferSize(data->ring);
state = psnd_pcm_state(data->pcmHandle);
if(state == SND_PCM_STATE_XRUN)
{
err = xrun_recovery(data->pcmHandle, -EPIPE);
if(err >= 0)
{
if(data->doCapture)
err = psnd_pcm_start(data->pcmHandle);
}
if (err < 0)
{
AL_PRINT("XRUN recovery failed: %s\n", psnd_strerror(err));
return 0;
}
}
frames = psnd_pcm_avail_update(data->pcmHandle);
if(frames < 0)
{
err = xrun_recovery(data->pcmHandle, frames);
if (err < 0)
AL_PRINT("available update failed: %s\n", psnd_strerror(err));
else
frames = psnd_pcm_avail_update(data->pcmHandle);
}
return max(frames, 0);
}
BackendFuncs alsa_funcs = {
alsa_open_playback,
alsa_close_playback,
alsa_open_capture,
alsa_close_capture,
alsa_start_capture,
alsa_stop_capture,
alsa_capture_samples,
alsa_available_samples
};
void alc_alsa_init(BackendFuncs *func_list)
{
snd_ctl_t *handle;
int card, err, dev, idx = 1;
snd_ctl_card_info_t *info;
snd_pcm_info_t *pcminfo;
snd_pcm_stream_t stream = SND_PCM_STREAM_PLAYBACK;
char name[128];
char *str;
*func_list = alsa_funcs;
#ifdef HAVE_DLFCN_H
alsa_handle = dlopen("libasound.so.2", RTLD_NOW);
if(!alsa_handle)
return;
dlerror();
#define LOAD_FUNC(f) do { \
p##f = (typeof(f)*)dlsym(alsa_handle, #f); \
if((str=dlerror()) != NULL) \
{ \
dlclose(alsa_handle); \
alsa_handle = NULL; \
AL_PRINT("Could not load %s from libasound.so.2: %s\n", #f, str); \
return; \
} \
} while(0)
#else
str = NULL;
alsa_handle = (void*)0xDEADBEEF;
#define LOAD_FUNC(f) p##f = f
#endif
LOAD_FUNC(snd_strerror);
LOAD_FUNC(snd_pcm_open);
LOAD_FUNC(snd_pcm_close);
LOAD_FUNC(snd_pcm_nonblock);
LOAD_FUNC(snd_pcm_frames_to_bytes);
LOAD_FUNC(snd_pcm_hw_params_malloc);
LOAD_FUNC(snd_pcm_hw_params_free);
LOAD_FUNC(snd_pcm_hw_params_any);
LOAD_FUNC(snd_pcm_hw_params_set_access);
LOAD_FUNC(snd_pcm_hw_params_set_format);
LOAD_FUNC(snd_pcm_hw_params_set_channels);
LOAD_FUNC(snd_pcm_hw_params_set_periods_near);
LOAD_FUNC(snd_pcm_hw_params_set_rate_near);
LOAD_FUNC(snd_pcm_hw_params_set_rate);
LOAD_FUNC(snd_pcm_hw_params_set_buffer_size_near);
LOAD_FUNC(snd_pcm_hw_params_set_buffer_size_min);
LOAD_FUNC(snd_pcm_hw_params_get_buffer_size);
LOAD_FUNC(snd_pcm_hw_params_get_period_size);
LOAD_FUNC(snd_pcm_hw_params_get_access);
LOAD_FUNC(snd_pcm_hw_params);
LOAD_FUNC(snd_pcm_sw_params_malloc);
LOAD_FUNC(snd_pcm_sw_params_current);
LOAD_FUNC(snd_pcm_sw_params_set_avail_min);
LOAD_FUNC(snd_pcm_sw_params);
LOAD_FUNC(snd_pcm_sw_params_free);
LOAD_FUNC(snd_pcm_prepare);
LOAD_FUNC(snd_pcm_start);
LOAD_FUNC(snd_pcm_resume);
LOAD_FUNC(snd_pcm_wait);
LOAD_FUNC(snd_pcm_state);
LOAD_FUNC(snd_pcm_avail_update);
LOAD_FUNC(snd_pcm_areas_silence);
LOAD_FUNC(snd_pcm_mmap_begin);
LOAD_FUNC(snd_pcm_mmap_commit);
LOAD_FUNC(snd_pcm_readi);
LOAD_FUNC(snd_pcm_writei);
LOAD_FUNC(snd_pcm_drain);
LOAD_FUNC(snd_pcm_info_malloc);
LOAD_FUNC(snd_pcm_info_free);
LOAD_FUNC(snd_pcm_info_set_device);
LOAD_FUNC(snd_pcm_info_set_subdevice);
LOAD_FUNC(snd_pcm_info_set_stream);
LOAD_FUNC(snd_pcm_info_get_name);
LOAD_FUNC(snd_ctl_pcm_next_device);
LOAD_FUNC(snd_ctl_pcm_info);
LOAD_FUNC(snd_ctl_open);
LOAD_FUNC(snd_ctl_close);
LOAD_FUNC(snd_ctl_card_info_malloc);
LOAD_FUNC(snd_ctl_card_info_free);
LOAD_FUNC(snd_ctl_card_info);
LOAD_FUNC(snd_ctl_card_info_get_name);
LOAD_FUNC(snd_card_next);
#undef LOAD_FUNC
psnd_ctl_card_info_malloc(&info);
psnd_pcm_info_malloc(&pcminfo);
card = -1;
if(psnd_card_next(&card) < 0 || card < 0)
AL_PRINT("no playback cards found...\n");
alsaDevice = AppendDeviceList("ALSA Software");
allDevNameMap[0].name = AppendAllDeviceList("ALSA Software on default");
while (card >= 0) {
sprintf(name, "hw:%d", card);
if ((err = psnd_ctl_open(&handle, name, 0)) < 0) {
AL_PRINT("control open (%i): %s\n", card, psnd_strerror(err));
goto next_card;
}
if ((err = psnd_ctl_card_info(handle, info)) < 0) {
AL_PRINT("control hardware info (%i): %s\n", card, psnd_strerror(err));
psnd_ctl_close(handle);
goto next_card;
}
dev = -1;
while (idx < MAX_ALL_DEVICES) {
const char *cname, *dname;
if (psnd_ctl_pcm_next_device(handle, &dev)<0)
AL_PRINT("snd_ctl_pcm_next_device failed\n");
if (dev < 0)
break;
psnd_pcm_info_set_device(pcminfo, dev);
psnd_pcm_info_set_subdevice(pcminfo, 0);
psnd_pcm_info_set_stream(pcminfo, stream);
if ((err = psnd_ctl_pcm_info(handle, pcminfo)) < 0) {
if (err != -ENOENT)
AL_PRINT("control digital audio info (%i): %s\n", card, psnd_strerror(err));
continue;
}
cname = psnd_ctl_card_info_get_name(info);
dname = psnd_pcm_info_get_name(pcminfo);
snprintf(name, sizeof(name), "ALSA Software on %s [%s] (hw:%d,%d)",
cname, dname, card, dev);
allDevNameMap[idx].name = AppendAllDeviceList(name);
allDevNameMap[idx].card = card;
allDevNameMap[idx].dev = dev;
idx++;
}
psnd_ctl_close(handle);
next_card:
if(psnd_card_next(&card) < 0) {
AL_PRINT("snd_card_next failed\n");
break;
}
}
stream = SND_PCM_STREAM_CAPTURE;
card = -1;
if(psnd_card_next(&card) < 0 || card < 0) {
AL_PRINT("no capture cards found...\n");
psnd_pcm_info_free(pcminfo);
psnd_ctl_card_info_free(info);
return;
}
allCaptureDevNameMap[0].name = AppendCaptureDeviceList("ALSA Capture on default");
idx = 1;
while (card >= 0) {
sprintf(name, "hw:%d", card);
handle = NULL;
if ((err = psnd_ctl_open(&handle, name, 0)) < 0) {
AL_PRINT("control open (%i): %s\n", card, psnd_strerror(err));
}
if (err >= 0 && (err = psnd_ctl_card_info(handle, info)) < 0) {
AL_PRINT("control hardware info (%i): %s\n", card, psnd_strerror(err));
}
else if (err >= 0)
{
dev = -1;
while (idx < MAX_ALL_DEVICES) {
const char *cname, *dname;
if (psnd_ctl_pcm_next_device(handle, &dev)<0)
AL_PRINT("snd_ctl_pcm_next_device failed\n");
if (dev < 0)
break;
psnd_pcm_info_set_device(pcminfo, dev);
psnd_pcm_info_set_subdevice(pcminfo, 0);
psnd_pcm_info_set_stream(pcminfo, stream);
if ((err = psnd_ctl_pcm_info(handle, pcminfo)) < 0) {
if (err != -ENOENT)
AL_PRINT("control digital audio info (%i): %s\n", card, psnd_strerror(err));
continue;
}
cname = psnd_ctl_card_info_get_name(info);
dname = psnd_pcm_info_get_name(pcminfo);
snprintf(name, sizeof(name), "ALSA Capture on %s [%s] (hw:%d,%d)",
cname, dname, card, dev);
allCaptureDevNameMap[idx].name = AppendCaptureDeviceList(name);
allCaptureDevNameMap[idx].card = card;
allCaptureDevNameMap[idx].dev = dev;
idx++;
}
}
if(handle) psnd_ctl_close(handle);
if(psnd_card_next(&card) < 0) {
AL_PRINT("snd_card_next failed\n");
break;
}
}
psnd_pcm_info_free(pcminfo);
psnd_ctl_card_info_free(info);
}
| 31.051373 | 138 | 0.601335 |
50ee0eb7281eb6e541cd6f5eb4db95c491e28b34 | 355,437 | c | C | sdk-6.5.16/src/bcm/esw/cosq.c | copslock/broadcom_cpri | 8e2767676e26faae270cf485591902a4c50cf0c5 | [
"Spencer-94"
] | null | null | null | sdk-6.5.16/src/bcm/esw/cosq.c | copslock/broadcom_cpri | 8e2767676e26faae270cf485591902a4c50cf0c5 | [
"Spencer-94"
] | null | null | null | sdk-6.5.16/src/bcm/esw/cosq.c | copslock/broadcom_cpri | 8e2767676e26faae270cf485591902a4c50cf0c5 | [
"Spencer-94"
] | null | null | null | /*
*
* This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
*
* Copyright 2007-2019 Broadcom Inc. All rights reserved.
*
* COS Queue Management
* Purpose: API to set different cosq, priorities, and scheduler registers.
*/
#include <sal/core/libc.h>
#include <soc/drv.h>
#include <soc/mem.h>
#include <soc/debug.h>
#if defined(BCM_TOMAHAWK3_SUPPORT)
#include <soc/format.h>
#include <soc/mcm/formatacc.h>
#endif
#include <bcm/error.h>
#include <bcm/cosq.h>
#include <bcm_int/esw/mbcm.h>
#include <bcm_int/esw/cosq.h>
#include <bcm_int/esw/tas.h>
#include <bcm_int/esw/firebolt.h>
#include <bcm_int/esw/scorpion.h>
#include <bcm_int/esw/triumph.h>
#include <bcm_int/esw/triumph2.h>
#include <bcm_int/esw/trident.h>
#include <bcm_int/esw/hurricane.h>
#include <bcm_int/esw/katana.h>
#include <bcm_int/esw/katana2.h>
#include <bcm_int/esw/apache.h>
#include <bcm_int/esw/monterey.h>
#include <bcm_int/esw/triumph3.h>
#include <bcm_int/esw/trident2.h>
#include <bcm_int/esw/trident2plus.h>
#include <bcm_int/esw/greyhound.h>
#include <bcm_int/esw/tomahawk.h>
#include <bcm_int/esw/trident3.h>
#include <bcm_int/esw/greyhound2.h>
#include <bcm_int/esw/tomahawk2.h>
#include <bcm_int/esw/helix5.h>
#include <bcm_int/esw/tomahawk3.h>
#include <soc/monterey.h>
#include <bcm_int/esw_dispatch.h>
#include <bcm_int/esw/stat.h>
#include <bcm_int/esw/pfc_deadlock.h>
#include <bcm_int/bst.h>
#if defined(INCLUDE_TCB) && defined (BCM_TCB_SUPPORT)
#include <bcm_int/esw/tcb.h>
#endif
#ifdef BCM_WARM_BOOT_SUPPORT
#include <bcm_int/esw/switch.h>
#endif /* BCM_WARM_BOOT_SUPPORT */
#define BCM_COSQ_QUEUE_VALID(unit, numq) \
((numq) >= 0 && (numq) < NUM_COS(unit))
sal_mutex_t cosq_sync_lock[SOC_MAX_NUM_DEVICES];
/* Cosq Event Handler */
typedef struct cosq_event_handler_s {
struct cosq_event_handler_s *next;
bcm_cosq_event_types_t event_types;
SHR_BITDCL pbmp[_SHR_BITDCLSIZE(SOC_MAX_NUM_PORTS)];
SHR_BITDCL qbmp[_SHR_BITDCLSIZE(BCM_COS_COUNT)];
bcm_cosq_event_cb cb;
void *user_data;
} cosq_event_handler_t;
STATIC cosq_event_handler_t *cosq_event_handler_list[SOC_MAX_NUM_DEVICES] = {NULL};
STATIC int cosq_event_handler_count[SOC_MAX_NUM_DEVICES][bcmCosqEventCount] = {{0}};
STATIC sal_mutex_t cosq_event_lock[SOC_MAX_NUM_DEVICES] = {NULL};
STATIC int bcmi_esw_cosq_event_deinit(int unit);
STATIC int bcmi_esw_cosq_event_init(int unit);
static uint8 cosq_event_initialized = 0;
#define COSQ_EVENT_LOCK(unit) \
do { \
if (cosq_event_lock[unit]) { \
sal_mutex_take(cosq_event_lock[unit], \
sal_mutex_FOREVER); \
} \
} while (0)
#define COSQ_EVENT_UNLOCK(unit) \
do { \
if (cosq_event_lock[unit]) { \
sal_mutex_give(cosq_event_lock[unit]); \
} \
} while (0)
#ifdef BCM_WARM_BOOT_SUPPORT
/*
* Function:
* _bcm_esw_cosq_sync
* Purpose:
* Record COSq module persisitent info for Level 2 Warm Boot.
* Parameters:
* unit - StrataSwitch unit number.
* Returns:
* BCM_E_XXX
*/
int
_bcm_esw_cosq_sync(int unit)
{
#ifdef BCM_TAS_SUPPORT
if (soc_feature(unit, soc_feature_tas)) {
BCM_IF_ERROR_RETURN(bcmi_esw_tas_sync(unit));
}
#endif
return mbcm_driver[unit]->mbcm_cosq_sync(unit);
}
#endif /* BCM_WARM_BOOT_SUPPORT */
/*
* Function:
* _bcm_esw_cosq_config_property_get
* Purpose:
* Get number COSQ from SOC property.
* Parameters:
* unit - Unit number.
* Returns:
* Number COSQ from SOC property.
*/
int
_bcm_esw_cosq_config_property_get(int unit)
{
int num_cos;
#if defined (BCM_HAWKEYE_SUPPORT)
if (SOC_IS_HAWKEYE(unit)) {
/* Use 2 as the default number of COS queue for HAWKEYE,
if bcm_num_cos is not set in config.bcm */
num_cos = soc_property_get(unit, spn_BCM_NUM_COS, 2);
} else
#endif /* BCM_HAWKEYE_SUPPORT */
#if defined (BCM_HURRICANE_SUPPORT)
if (SOC_IS_HURRICANEX(unit) || SOC_IS_GREYHOUND(unit) ||
SOC_IS_GREYHOUND2(unit)) {
if (soc_feature(unit, soc_feature_wh2)) {
/* Default 4 COSQ if config file not assigned */
num_cos = soc_property_get(unit, spn_BCM_NUM_COS, BCM_COS_DEFAULT);
} else {
/* Use 8 as the default number of COS queue for HURRICANE,
if bcm_num_cos is not set in config.bcm */
num_cos = soc_property_get(unit, spn_BCM_NUM_COS, BCM_COS_COUNT);
}
} else
#endif /* BCM_HURRICANE_SUPPORT */
{
num_cos = soc_property_get(unit, spn_BCM_NUM_COS, BCM_COS_DEFAULT);
}
if (num_cos < 1) {
num_cos = 1;
} else if (num_cos > NUM_COS(unit)) {
num_cos = NUM_COS(unit);
}
return num_cos;
}
#ifdef BCM_TRIUMPH_SUPPORT
#define _BCM_CPU_COS_MAPS_RSVD 9
#define _BCM_INT_PRI_8_15_MASK 0x8
#define _BCM_INT_PRI_0_7_MASK 0xf
#endif /* BCM_TRIUMPH_SUPPORT */
/*
* Function:
* _bcm_esw_cpu_cosq_mapping_default_set
* Purpose:
* Map 16 internal priorities to CPU COS queues using CPU_COS_MAPm
* Default cpu_cos_maps should have lower priorities than user created maps
* Parameters:
* unit - Unit number.
* numq - number of COS queues (1-8).
* Returns:
* BCM_E_XXX
*/
int
_bcm_esw_cpu_cosq_mapping_default_set(int unit, int numq)
{
#ifdef BCM_TRIUMPH_SUPPORT
int cos=0, prio, ratio, remain, index;
cpu_cos_map_entry_t cpu_cos_map_entry;
#if defined(BCM_TOMAHAWK3_SUPPORT)
uint32 tcam_entry[SOC_MAX_MEM_WORDS];
uint32 data_entry[SOC_MAX_MEM_WORDS];
uint32 action_set[4];
/* initialize the variables */
sal_memset(action_set,0x0,(sizeof(uint32))*4);
sal_memset(&tcam_entry, 0, sizeof(tcam_entry));
sal_memset(&data_entry, 0, sizeof(data_entry));
#endif
ratio = 8 / numq;
remain = 8 % numq;
/* Nothing to do on devices with no CPU_COS_MAP memory */
if (!SOC_MEM_IS_VALID(unit, CPU_COS_MAPm)) {
return BCM_E_NONE;
}
/* Map internal priorities 0 ~ 7 to appropriate CPU CoS queue */
sal_memset(&cpu_cos_map_entry, 0, sizeof(cpu_cos_map_entry_t));
#if defined(BCM_TOMAHAWK3_SUPPORT)
if (SOC_IS_TOMAHAWK3(unit)) {
soc_format_field32_set(unit, CPU_COS_MAP_TCAM_FORMATfmt, tcam_entry, VALIDf, 1);
} else
#endif
#if defined(BCM_TOMAHAWK2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
if (SOC_IS_TOMAHAWK2(unit) || SOC_IS_TRIDENT3X(unit)) {
soc_mem_field32_set(unit, CPU_COS_MAPm, &cpu_cos_map_entry, VALIDf, 3);
} else
#endif
{
soc_mem_field32_set(unit, CPU_COS_MAPm, &cpu_cos_map_entry, VALIDf, 1);
}
#if defined(BCM_TOMAHAWK3_SUPPORT)
if (SOC_IS_TOMAHAWK3(unit)) {
action_set[0] = _BCM_INT_PRI_0_7_MASK;
soc_format_field_set(unit, CPU_COS_MAP_TCAM_FORMATfmt, tcam_entry, MASKf, action_set);
} else
#endif
{
soc_mem_field32_set(unit, CPU_COS_MAPm, &cpu_cos_map_entry,
INT_PRI_MASKf, _BCM_INT_PRI_0_7_MASK);
}
index = (soc_mem_index_count(unit, CPU_COS_MAPm) - _BCM_CPU_COS_MAPS_RSVD);
for (prio = BCM_PRIO_MIN; prio <= BCM_PRIO_MAX; prio++, index++) {
#if defined(BCM_TOMAHAWK3_SUPPORT)
if (SOC_IS_TOMAHAWK3(unit)) {
action_set[0] = prio;
soc_format_field_set(unit, CPU_COS_MAP_TCAM_FORMATfmt, tcam_entry, KEYf, action_set);
soc_format_field32_set(unit, CPU_COS_MAP_DATA_FORMATfmt, data_entry, COSf, cos);
SOC_IF_ERROR_RETURN(WRITE_CPU_COS_MAPm(unit, MEM_BLOCK_ALL, index,
tcam_entry));
SOC_IF_ERROR_RETURN(WRITE_CPU_COS_MAP_DATA_ONLYm(unit, MEM_BLOCK_ALL, index,
data_entry));
} else
#endif
{
soc_mem_field32_set(unit, CPU_COS_MAPm, &cpu_cos_map_entry,
INT_PRI_KEYf, prio);
soc_mem_field32_set(unit, CPU_COS_MAPm, &cpu_cos_map_entry, COSf, cos);
SOC_IF_ERROR_RETURN(WRITE_CPU_COS_MAPm(unit, MEM_BLOCK_ALL, index,
&cpu_cos_map_entry));
}
if ((prio + 1) == (((cos + 1) * ratio) + ((remain < (numq - cos)) ?
0 : (remain - (numq - cos) + 1)))) {
cos++;
}
}
/* Map internal priorities 8 ~ 15 to (numq - 1) CPU CoS queue */
#if defined(BCM_TOMAHAWK3_SUPPORT)
if (SOC_IS_TOMAHAWK3(unit)) {
action_set[0] = _BCM_INT_PRI_8_15_MASK;
soc_format_field_set(unit, CPU_COS_MAP_TCAM_FORMATfmt, tcam_entry, MASKf, action_set);
action_set[0] = 0x8;
soc_format_field_set(unit, CPU_COS_MAP_TCAM_FORMATfmt, tcam_entry, KEYf, action_set);
soc_format_field32_set(unit, CPU_COS_MAP_DATA_FORMATfmt, data_entry, COSf, numq-1);
SOC_IF_ERROR_RETURN(WRITE_CPU_COS_MAPm(unit, MEM_BLOCK_ALL, index,
tcam_entry));
SOC_IF_ERROR_RETURN(WRITE_CPU_COS_MAP_DATA_ONLYm(unit, MEM_BLOCK_ALL, index,
data_entry));
} else
#endif
{
soc_mem_field32_set(unit, CPU_COS_MAPm, &cpu_cos_map_entry,
INT_PRI_KEYf, 0x8);
soc_mem_field32_set(unit, CPU_COS_MAPm, &cpu_cos_map_entry,
INT_PRI_MASKf, _BCM_INT_PRI_8_15_MASK);
soc_mem_field32_set(unit, CPU_COS_MAPm, &cpu_cos_map_entry, COSf, numq - 1);
SOC_IF_ERROR_RETURN(WRITE_CPU_COS_MAPm(unit, MEM_BLOCK_ALL, index,
&cpu_cos_map_entry));
}
#endif /* BCM_TRIUMPH_SUPPORT */
return BCM_E_NONE;
}
/*
* Function:
* bcm_esw_cosq_init
* Purpose:
* Initialize (clear) all COS schedule/mapping state.
* Parameters:
* unit - StrataSwitch unit number.
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_init(int unit)
{
if (SOC_IS_SHADOW(unit)) {
return BCM_E_UNAVAIL;
}
#ifdef BCM_TAS_SUPPORT
if (soc_feature(unit, soc_feature_tas)) {
BCM_IF_ERROR_RETURN(bcmi_esw_tas_init(unit));
}
#endif
BCM_IF_ERROR_RETURN(bcmi_esw_cosq_event_init(unit));
return mbcm_driver[unit]->mbcm_cosq_init(unit);
}
/*
* Function:
* bcm_esw_cosq_detach
* Purpose:
* Discard all COS schedule/mapping state.
* Parameters:
* unit - StrataSwitch unit number.
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_detach(int unit)
{
#ifdef BCM_TAS_SUPPORT
if (soc_feature(unit, soc_feature_tas)) {
BCM_IF_ERROR_RETURN(bcmi_esw_tas_deinit(unit));
}
#endif
BCM_IF_ERROR_RETURN(bcmi_esw_cosq_event_deinit(unit));
return (mbcm_driver[unit]->mbcm_cosq_detach(unit, 0));
}
int bcm_esw_cosq_deinit(int unit)
{
#ifdef BCM_TAS_SUPPORT
if (soc_feature(unit, soc_feature_tas)) {
BCM_IF_ERROR_RETURN(bcmi_esw_tas_deinit(unit));
}
#endif
BCM_IF_ERROR_RETURN(bcmi_esw_cosq_event_deinit(unit));
return (mbcm_driver[unit]->mbcm_cosq_detach(unit, 1));
}
/*
* Function:
* bcm_esw_cosq_config_set
* Purpose:
* Set the number of COS queues
* Parameters:
* unit - StrataSwitch unit number.
* numq - number of COS queues (1, 2, or 4).
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_config_set(int unit, bcm_cos_queue_t numq)
{
if (!SOC_IS_TOMAHAWKX(unit) && (!SOC_IS_TRIDENT3X(unit)) &&(!SOC_IS_MONTEREY(unit))
&& (numq > 8)) {
return BCM_E_PARAM;
}
return mbcm_driver[unit]->mbcm_cosq_config_set(unit, numq);
}
/*
* Function:
* bcm_esw_cosq_config_get
* Purpose:
* Get the number of cos queues
* Parameters:
* unit - StrataSwitch unit number.
* numq - (Output) number of cosq
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_config_get(int unit, bcm_cos_queue_t *numq)
{
return (mbcm_driver[unit]->mbcm_cosq_config_get(unit, numq));
}
/*
* Function:
* bcm_esw_cosq_mapping_set
* Purpose:
* Set which cosq a given priority should fall into
* Parameters:
* unit - StrataSwitch unit number.
* priority - Priority value to map
* cosq - COS queue to map to
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_mapping_set(int unit, bcm_cos_t priority, bcm_cos_queue_t cosq)
{
if (!BCM_COSQ_QUEUE_VALID(unit, cosq)) {
return (BCM_E_PARAM);
}
return (mbcm_driver[unit]->mbcm_cosq_mapping_set(unit, -1,
priority, cosq));
}
int
bcm_esw_cosq_port_mapping_set(int unit, bcm_port_t port,
bcm_cos_t priority, bcm_cos_queue_t cosq)
{
if (!soc_feature(unit, soc_feature_ets)) {
if (!BCM_COSQ_QUEUE_VALID(unit, cosq)) {
return (BCM_E_PARAM);
}
if (BCM_GPORT_IS_SET(port) && !SOC_IS_KATANAX(unit)) {
BCM_IF_ERROR_RETURN(bcm_esw_port_local_get(unit, port, &port));
}
}
return (mbcm_driver[unit]->mbcm_cosq_mapping_set(unit, port,
priority, cosq));
}
/*
* Function:
* bcm_esw_cosq_port_mapping_multi_set
* Purpose:
* mapping multiple priorities to their respective cos in one call
* Parameters:
* unit - StrataSwitch unit number.
* port - Ingress Port
* count - Number of entries to be configured
* priority_array - Priority array to map
* cosq_array - COS queue array to map to
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_port_mapping_multi_set(int unit, bcm_port_t port, int count,
bcm_cos_t *priority_array,bcm_cos_queue_t *cosq_array)
{
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
if (!soc_feature(unit, soc_feature_ets)) {
int index = 0;
if ((count < 1) || (count > 16)) {
return (BCM_E_PARAM);
}
if ((NULL == cosq_array) || (NULL == priority_array)) {
return (BCM_E_PARAM);
}
for (index = 0; index < count; index++) {
if (!BCM_COSQ_QUEUE_VALID(unit, cosq_array[index])) {
return (BCM_E_PARAM);
}
}
if (BCM_GPORT_IS_SET(port)){
BCM_IF_ERROR_RETURN(bcm_esw_port_local_get(unit, port, &port));
}
}
return (bcm_kt2_cosq_port_mapping_multi_set(unit, port,count,
priority_array, cosq_array));
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_stat_config_set
* Purpose:
* configures the stat types provided in stat_array
* Parameters:
* unit - StrataSwitch unit number.
* stat_count - number of stat type entries in the stat_array
* stat_array - array containing information regarding the stats to be configured
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_stat_config_set(
int unit, int stat_count,
bcm_cosq_stat_t *stat_array)
{
#if defined(BCM_KATANA2_SUPPORT)
if (SOC_IS_KATANA2(unit)) {
return (bcm_kt2_cosq_stat_config_set(unit, stat_count, stat_array));
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_stat_config_get
* Purpose:
* configures the stat types provided in stat_array
* Parameters:
* unit - StrataSwitch unit number.
* stat_count - number of stat type entries in the stat_array
* stat_array - array containing information regarding the stats to be configured
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_stat_config_get(
int unit, int stat_count,
bcm_cosq_stat_t *stat_array)
{
#if defined(BCM_KATANA2_SUPPORT)
if (SOC_IS_KATANA2(unit)) {
return (bcm_kt2_cosq_stat_config_get(unit, stat_count, stat_array));
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_gport_egress_mapping_set
* Purpose:
* Set which cosq a given priority should fall into
* Parameters:
* unit - StrataSwitch unit number.
* gport - GPORT ID.
* priority - Priority value to map
* cosq - COS queue to map to
* flags - specify to which type of mapping
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_gport_egress_mapping_set(
int unit, bcm_port_t gport, bcm_cos_t priority,
bcm_cos_t cosq, uint32 flags)
{
switch(flags) {
case BCM_COSQ_GPORT_EGRESS_MAPPING_REDIRECTION_COS:
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_gport_egress_mapping_set(
unit, gport, priority,
cosq, flags);
}
#endif /* BCM_KATANA2_SUPPORT */
break;
default :
break;
}
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_gport_egress_mapping_get
* Purpose:
* Get cosq for the corresponding priority
* Parameters:
* unit - StrataSwitch unit number.
* gport - GPORT ID.
* priority - Priority value to map
* cosq - COS queue to map to
* flags - specify to which type of mapping
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_gport_egress_mapping_get(
int unit, bcm_port_t gport, bcm_cos_t *priority,
bcm_cos_t *cosq, uint32 flags)
{
switch(flags) {
case BCM_COSQ_GPORT_EGRESS_MAPPING_REDIRECTION_COS:
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_gport_egress_mapping_get(
unit, gport, priority,
cosq, flags);
}
#endif /* BCM_KATANA2_SUPPORT */
break;
default :
break;
}
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_congestion_mapping_set
* Purpose:
* Set congestion state as per the desired flow control for fabric
* Parameters:
* unit - StrataSwitch unit number.
* fabric_modid - Specify the fabric_modid on which congestion state
* need to be applied
* config - specify the flow control bits, which the fabric is interested
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_congestion_mapping_set(int unit,int fabric_modid ,
bcm_cosq_congestion_mapping_info_t *config)
{
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_congestion_mapping_set(unit, fabric_modid,
config);
}
#endif /* BCM_KATANA2_SUPPORT */
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_congestion_mapping_get
* Purpose:
* Get congestion state as per the configured flow control value for fabric
* Parameters:
* unit - StrataSwitch unit number.
* fabric_modid - Specify the fabric_modid on which congestion state
* need to be applied
* config - specify the flow control bits, which the fabric is interested
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_congestion_mapping_get(int unit,int fabric_modid ,
bcm_cosq_congestion_mapping_info_t *config)
{
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_congestion_mapping_get(unit, fabric_modid,
config);
}
#endif /* BCM_KATANA2_SUPPORT */
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_mapping_get
* Purpose:
* Determine which COS queue a given priority currently maps to.
* Parameters:
* unit - StrataSwitch unit number.
* priority - Priority value
* cosq - (Output) COS queue number
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_mapping_get(int unit, bcm_cos_t priority, bcm_cos_queue_t *cosq)
{
return (mbcm_driver[unit]->mbcm_cosq_mapping_get(unit, -1,
priority, cosq));
}
int
bcm_esw_cosq_port_mapping_get(int unit, bcm_port_t port,
bcm_cos_t priority, bcm_cos_queue_t *cosq)
{
if (!soc_feature(unit, soc_feature_ets)) {
if (BCM_GPORT_IS_SET(port) && !SOC_IS_KATANAX(unit)) {
BCM_IF_ERROR_RETURN(bcm_esw_port_local_get(unit, port, &port));
}
}
return (mbcm_driver[unit]->mbcm_cosq_mapping_get(unit, port,
priority, cosq));
}
/*
* Function:
* bcm_esw_cosq_mapping_multi_get
* Purpose:
* Determine which COS queue a given priority currently maps to.
* Parameters:
* unit - StrataSwitch unit number.
* port - Ingress PORT
* priority - Priority array for which we need cosq values
* count - number of entries to be retrieved
* cosq - (Output) COS queue array
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_port_mapping_multi_get(int unit, bcm_port_t port, int count,
bcm_cos_t *priority_array, bcm_cos_queue_t *cosq_array)
{
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
if (!soc_feature(unit, soc_feature_ets)) {
if (BCM_GPORT_IS_SET(port)) {
BCM_IF_ERROR_RETURN(bcm_esw_port_local_get(unit, port, &port));
}
}
return bcm_kt2_cosq_port_mapping_multi_get(unit, port, count,
priority_array, cosq_array);
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_priority_mapping_get_all
*
* Purpose:
* Get all priorities associated to the specific priority_group or
* service_pool on one port.
* Parameters:
* unit - Unit number.
* gport - Gport ID.
* index - Priority group ID or service pool id, depends on type value.
* type - Support priority group or ingress service pool.
* pri_max - Indicate the cosq number user required.
* pri_array - Priority list attached to the priority_group on the port,
* -1 is invalid value.
* pri_count - Indicate cosq number returned. When pri_max is zero,
* pri_array is null, pri_count will return the total cosq
* number attached to the port pg/port sp.
* Returns:
* BCM_E_XXX
*/
int bcm_esw_cosq_priority_mapping_get_all(int unit, bcm_gport_t gport,
int index, bcm_cosq_priority_mapping_t type,
int pri_max, bcm_cos_queue_t *pri_array,
int *pri_count)
{
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_priority_mapping_get_all(unit, gport, index, type,
pri_max, pri_array, pri_count);
}
#endif /* BCM_APACHE_SUPPORT */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit) && !SOC_IS_TOMAHAWK3(unit)) {
return bcm_th_cosq_priority_mapping_get_all(unit, gport, index, type,
pri_max, pri_array, pri_count);
}
#endif
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
return bcm_td3_cosq_priority_mapping_get_all(unit, gport, index, type,
pri_max, pri_array, pri_count);
}
#endif
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TRIDENT2(unit) || SOC_IS_TRIDENT2PLUS(unit)) {
return bcm_td2_cosq_priority_mapping_get_all(unit, gport, index, type,
pri_max, pri_array, pri_count);
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_sched_set
* Purpose:
* Set up class-of-service policy and corresponding weights and delay
* Parameters:
* unit - StrataSwitch unit number.
* mode - Scheduling mode, one of BCM_COSQ_xxx
* weights - Weights for each COS queue
* Unused if mode is BCM_COSQ_STRICT.
* Indicates number of packets sent before going on to
* the next COS queue.
* delay - Maximum delay in microseconds before returning the
* round-robin to the highest priority COS queue
* (Unused if mode other than BCM_COSQ_BOUNDED_DELAY)
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_sched_set(int unit, int mode, const int weights[], int delay)
{
bcm_pbmp_t pbmp;
if (soc_feature(unit, soc_feature_ets)) {
BCM_PBMP_ASSIGN(pbmp, PBMP_CMIC(unit));
} else {
BCM_PBMP_ASSIGN(pbmp, PBMP_ALL(unit));
}
return (mbcm_driver[unit]->mbcm_cosq_port_sched_set(unit, pbmp, mode,
weights, delay));
}
int
bcm_esw_cosq_port_sched_set(int unit, bcm_pbmp_t pbm,
int mode, const int weights[], int delay)
{
bcm_pbmp_t pbm_all = PBMP_ALL(unit);
BCM_PBMP_AND(pbm_all, pbm);
if (BCM_PBMP_NEQ(pbm_all, pbm)) {
return BCM_E_PORT;
}
return (mbcm_driver[unit]->mbcm_cosq_port_sched_set(unit,
pbm,
mode, weights, delay));
}
/*
* Function:
* bcm_esw_cosq_sched_get
* Purpose:
* Retrieve class-of-service policy and corresponding weights and delay
* Parameters:
* unit - StrataSwitch unit number.
* mode_ptr - (output) Scheduling mode, one of BCM_COSQ_xxx
* weights - (output) Weights for each COS queue
* Unused if mode is BCM_COSQ_STRICT.
* delay - (output) Maximum delay in microseconds before returning
* the round-robin to the highest priority COS queue
* Unused if mode other than BCM_COSQ_BOUNDED_DELAY.
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_sched_get(int unit, int *mode, int weights[], int *delay)
{
bcm_pbmp_t pbmp;
if (soc_feature(unit, soc_feature_ets)) {
BCM_PBMP_ASSIGN(pbmp, PBMP_CMIC(unit));
} else {
BCM_PBMP_ASSIGN(pbmp, PBMP_ALL(unit));
}
return (mbcm_driver[unit]->mbcm_cosq_port_sched_get(unit, pbmp, mode,
weights, delay));
}
int
bcm_esw_cosq_port_sched_get(int unit, bcm_pbmp_t pbm,
int *mode, int weights[], int *delay)
{
bcm_pbmp_t pbm_all = PBMP_ALL(unit);
BCM_PBMP_AND(pbm_all, pbm);
if (BCM_PBMP_NEQ(pbm_all, pbm)) {
return BCM_E_PARAM;
}
return (mbcm_driver[unit]->mbcm_cosq_port_sched_get(unit,
pbm,
mode, weights, delay));
}
/*
* Function:
* bcm_esw_cosq_sched_weight_max_get
* Purpose:
* Retrieve maximum weights for given COS policy.
* Parameters:
* unit - StrataSwitch unit number.
* mode - Scheduling mode, one of BCM_COSQ_xxx
* weight_max - (output) Maximum weight for COS queue.
* 0 if mode is BCM_COSQ_STRICT.
* 1 if mode is BCM_COSQ_ROUND_ROBIN.
* -1 if not applicable to mode.
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_sched_weight_max_get(int unit, int mode, int *weight_max)
{
return (mbcm_driver[unit]->mbcm_cosq_sched_weight_max_get(unit,
mode,
weight_max));
}
/*
* Function:
* bcm_esw_cosq_port_bandwidth_set
* Purpose:
* Set bandwidth values for given COS policy.
* Parameters:
* unit - StrataSwitch unit number.
* port - port to configure, -1 for all ports.
* cosq - COS queue to configure, -1 for all COS queues.
* kbits_sec_min - minimum bandwidth, kbits/sec.
* kbits_sec_max - maximum bandwidth, kbits/sec.
* flags - may include:
* BCM_COSQ_BW_EXCESS_PREF
* BCM_COSQ_BW_MINIMUM_PREF
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_port_bandwidth_set(int unit, bcm_port_t port,
bcm_cos_queue_t cosq,
uint32 kbits_sec_min,
uint32 kbits_sec_max,
uint32 flags)
{
int rv = BCM_E_NONE;
bcm_pbmp_t pbmp;
bcm_port_t loc_port;
bcm_cos_queue_t start_cos, end_cos, loc_cos;
int num_cosq;
if (port < 0) {
if (SOC_IS_TRIUMPH(unit) || SOC_IS_VALKYRIE(unit) ||
SOC_IS_SC_CQ(unit) || SOC_IS_ENDURO(unit) ||
SOC_IS_KATANA(unit)) {
BCM_PBMP_ASSIGN(pbmp, PBMP_PORT_ALL(unit));
loc_port = SOC_PORT_MIN(unit,port);
} else {
BCM_PBMP_ASSIGN(pbmp, PBMP_ALL(unit));
loc_port = SOC_PORT_MIN(unit,all);
}
num_cosq = NUM_COS(unit);
} else {
if (BCM_GPORT_IS_SET(port)) {
BCM_IF_ERROR_RETURN(
bcm_esw_port_local_get(unit, port, &loc_port));
} else {
loc_port = port;
}
if (SOC_PORT_VALID(unit, loc_port)) {
BCM_PBMP_PORT_SET(pbmp, loc_port);
} else {
return BCM_E_PORT;
}
num_cosq = IS_CPU_PORT(unit, loc_port) ?
NUM_CPU_COSQ(unit) : NUM_COS(unit);
}
if (soc_feature(unit, soc_feature_wh2)) {
/* Get the configured cosq number */
BCM_IF_ERROR_RETURN(bcm_esw_cosq_config_get(unit, &num_cosq));
}
if (cosq < 0) {
start_cos = 0;
end_cos = num_cosq - 1;
} else if (cosq >= num_cosq) {
return BCM_E_PARAM;
} else {
start_cos = end_cos = cosq;
}
BCM_PBMP_ITER(pbmp, loc_port) {
if (SOC_IS_HELIX5(unit) && IS_FAE_PORT(unit, loc_port)) {
continue;
}
for (loc_cos = start_cos; loc_cos <= end_cos; loc_cos++) {
if ((rv = mbcm_driver[unit]->mbcm_cosq_port_bandwidth_set(unit,
loc_port, loc_cos, kbits_sec_min, kbits_sec_max,
kbits_sec_max, flags)) < 0) {
return rv;
}
}
}
return rv;
}
/*
* Function:
* bcm_esw_cosq_port_bandwidth_get
* Purpose:
* Retrieve bandwidth values for given COS policy.
* Parameters:
* unit - StrataSwitch unit number.
* port - port to configure, -1 for any port.
* cosq - COS queue to configure, -1 for any COS queue.
* kbits_sec_min - (OUT) minimum bandwidth, kbits/sec.
* kbits_sec_max - (OUT) maximum bandwidth, kbits/sec.
* flags - (OUT) may include:
* BCM_COSQ_BW_EXCESS_PREF
* BCM_COSQ_BW_MINIMUM_PREF
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_port_bandwidth_get(int unit, bcm_port_t port,
bcm_cos_queue_t cosq,
uint32 *kbits_sec_min,
uint32 *kbits_sec_max,
uint32 *flags)
{
bcm_port_t loc_port;
bcm_cos_queue_t loc_cos;
int num_cosq;
uint32 kbits_sec_burst; /* Dummy variable */
if (flags == NULL) {
return BCM_E_PARAM;
}
if (port < 0) {
loc_port = SOC_PORT_MIN(unit,all);
num_cosq = NUM_COS(unit);
} else {
if (BCM_GPORT_IS_SET(port)) {
BCM_IF_ERROR_RETURN(
bcm_esw_port_local_get(unit, port, &loc_port));
} else {
loc_port = port;
}
if (!SOC_PORT_VALID(unit, loc_port)) {
return BCM_E_PORT;
}
num_cosq = IS_CPU_PORT(unit, loc_port) ?
NUM_CPU_COSQ(unit) : NUM_COS(unit);
}
if (soc_feature(unit, soc_feature_wh2)) {
/* Get the configured max cosq number */
BCM_IF_ERROR_RETURN(bcm_esw_cosq_config_get(unit, &num_cosq));
}
if (cosq < 0) {
loc_cos = 0;
} else if (cosq >= num_cosq) {
return BCM_E_PARAM;
} else {
loc_cos = cosq;
}
return (mbcm_driver[unit]->mbcm_cosq_port_bandwidth_get(unit,
loc_port, loc_cos, kbits_sec_min, kbits_sec_max,
&kbits_sec_burst, flags));
}
/*
* Function:
* bcm_esw_cosq_discard_set
* Purpose:
* Set the COS queue WRED parameters
* Parameters:
* unit - StrataSwitch unit number.
* flags - BCM_COSQ_DISCARD_*
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_discard_set(int unit, uint32 flags)
{
return (mbcm_driver[unit]->mbcm_cosq_discard_set(unit, flags));
}
/*
* Function:
* bcm_esw_cosq_discard_get
* Purpose:
* Get the COS queue WRED parameters
* Parameters:
* unit - StrataSwitch unit number.
* flags - (OUT) BCM_COSQ_DISCARD_*
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_discard_get(int unit, uint32 *flags)
{
if (flags == NULL) {
return BCM_E_PARAM;
}
return (mbcm_driver[unit]->mbcm_cosq_discard_get(unit, flags));
}
/*
* Function:
* bcm_esw_cosq_discard_port_set
* Purpose:
* Set the COS queue WRED parameters
* Parameters:
* unit - StrataSwitch unit number.
* port - port to configure (-1 for all ports).
* cosq - COS queue to configure (-1 for all queues).
* color - BCM_COSQ_DISCARD_COLOR_*
* drop_start - percentage of queue
* drop_slope - degress 0..90
* average_time - in microseconds
*
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_discard_port_set(int unit, bcm_port_t port,
bcm_cos_queue_t cosq,
uint32 color,
int drop_start,
int drop_slope,
int average_time)
{
return mbcm_driver[unit]->mbcm_cosq_discard_port_set
(unit, port, cosq, color, drop_start, drop_slope, average_time);
}
/*
* Function:
* bcm_esw_cosq_discard_port_get
* Purpose:
* Set the COS queue WRED parameters
* Parameters:
* unit - StrataSwitch unit number.
* port - port to get (-1 for any).
* cosq - COS queue to get (-1 for any).
* color - BCM_COSQ_DISCARD_COLOR_*
* drop_start - (OUT) percentage of queue
* drop_slope - (OUT) degress 0..90
* average_time - (OUT) in microseconds
*
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_discard_port_get(int unit, bcm_port_t port,
bcm_cos_queue_t cosq,
uint32 color,
int *drop_start,
int *drop_slope,
int *average_time)
{
return mbcm_driver[unit]->mbcm_cosq_discard_port_get
(unit, port, cosq, color, drop_start, drop_slope, average_time);
}
/*
* Function:
* bcm_cosq_gport_discard_set
* Purpose:
*
* Parameters:
* unit - (IN) Unit number.
* port - (IN) GPORT ID.
* cosq - (IN) COS queue to configure
* discard - (IN) Discard settings
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_gport_discard_set(int unit, bcm_gport_t port, bcm_cos_queue_t cosq,
bcm_cosq_gport_discard_t *discard)
{
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
return bcm_mn_cosq_gport_discard_set(unit, port, cosq, discard);
}
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_gport_discard_set(unit, port, cosq, discard);
}
#endif /* BCM_APACHE_SUPPORT */
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return bcm_th3_cosq_gport_discard_set(unit, port, cosq,
BCM_COSQ_BUFFER_ID_INVALID, discard);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
return bcm_th_cosq_gport_discard_set(unit, port, cosq,
BCM_COSQ_BUFFER_ID_INVALID, discard);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
return bcm_hx5_cosq_gport_discard_set(unit, port, cosq, discard);
}
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
return bcm_td3_cosq_gport_discard_set(unit, port, cosq, discard);
}
#endif /* BCM_TRIDENT3_SUPPORT */
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_gport_discard_set(unit, port, cosq, discard);
}
#endif /* BCM_TRIDENT2_SUPPORT */
#ifdef BCM_TRIDENT_SUPPORT
if (SOC_IS_TD_TT(unit)) {
return bcm_td_cosq_gport_discard_set(unit, port, cosq, discard);
}
#endif /* BCM_TRIDENT_SUPPORT */
#ifdef BCM_KATANA_SUPPORT
if (SOC_IS_KATANA(unit)) {
return bcm_kt_cosq_gport_discard_set(unit, port, cosq, discard);
}
#endif /* BCM_KATANA_SUPPORT */
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_gport_discard_set(unit, port, cosq, discard);
}
#endif /* BCM_KATANA2_SUPPORT */
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_gport_discard_set(unit, port, cosq, discard);
}
#endif /* BCM_TRIUMPH3_SUPPORT */
/*Removed GPORT_INVALID check for KT/KT2/TR3/TD/TD2 to enable
global wred discard profile for all ports when -1 is passed */
if (port == BCM_GPORT_INVALID) {
return (BCM_E_PORT);
}
#ifdef BCM_TRIUMPH2_SUPPORT
if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) ||
SOC_IS_VALKYRIE2(unit)) {
return bcm_tr2_cosq_gport_discard_set(unit, port, cosq, discard);
}
#endif
#ifdef BCM_TRX_SUPPORT
if (SOC_IS_TRX(unit)) {
#if defined(BCM_HURRICANE_SUPPORT)
if(SOC_IS_HURRICANE(unit) || SOC_IS_HURRICANE2(unit)) {
return bcm_hu_cosq_gport_discard_set(unit, port, cosq, discard);
} else
#endif /*BCM_HURRICANE_SUPPORT*/
#if defined(BCM_GREYHOUND_SUPPORT)
if(SOC_IS_GREYHOUND(unit) || SOC_IS_HURRICANE3(unit)) {
return bcm_gh_cosq_gport_discard_set(unit, port, cosq, discard);
} else
#endif /*BCM_GREYHOUND_SUPPORT*/
#if defined(BCM_GREYHOUND2_SUPPORT)
if (SOC_IS_GREYHOUND2(unit)) {
return bcmi_gh2_cosq_gport_discard_set(unit, port, cosq, discard);
} else
#endif /* BCM_GREYHOUND2_SUPPORT */
{
return bcm_tr_cosq_gport_discard_set(unit, port, cosq, discard);
}
}
#endif /* BCM_TRX_SUPPORT */
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_cosq_gport_discard_get
* Purpose:
*
* Parameters:
* unit - (IN) Unit number.
* port - (IN) GPORT ID.
* cosq - (IN) COS queue to get
* discard - (IN/OUT) Discard settings
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_gport_discard_get(int unit, bcm_gport_t port, bcm_cos_queue_t cosq,
bcm_cosq_gport_discard_t *discard)
{
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
return bcm_mn_cosq_gport_discard_get(unit, port, cosq, discard);
}
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_gport_discard_get(unit, port, cosq, discard);
}
#endif /* BCM_APACHE_SUPPORT */
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return bcm_th3_cosq_gport_discard_get(unit, port, cosq,
BCM_COSQ_BUFFER_ID_INVALID, discard);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
return bcm_th_cosq_gport_discard_get(unit, port, cosq,
BCM_COSQ_BUFFER_ID_INVALID, discard);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
return bcm_hx5_cosq_gport_discard_get(unit, port, cosq, discard);
}
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
return bcm_td3_cosq_gport_discard_get(unit, port, cosq, discard);
}
#endif /* BCM_TRIDENT3_SUPPORT */
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_gport_discard_get(unit, port, cosq, discard);
}
#endif /* BCM_TRIDENT_SUPPORT */
#ifdef BCM_TRIDENT_SUPPORT
if (SOC_IS_TD_TT(unit)) {
return bcm_td_cosq_gport_discard_get(unit, port, cosq, discard);
}
#endif /* BCM_TRIDENT_SUPPORT */
#ifdef BCM_KATANA_SUPPORT
if (SOC_IS_KATANA(unit)) {
return bcm_kt_cosq_gport_discard_get(unit, port, cosq, discard);
}
#endif /* BCM_KATANA_SUPPORT */
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_gport_discard_get(unit, port, cosq, discard);
}
#endif /* BCM_KATANA2_SUPPORT */
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_gport_discard_get(unit, port, cosq, discard);
}
#endif /* BCM_TRIUMPH3_SUPPORT */
/*Removed GPORT_INVALID check for KT/KT2/TR3/TD/TD2 to enable
global wred discard profile for all ports when -1 is passed */
if (port == BCM_GPORT_INVALID) {
return (BCM_E_PORT);
}
#ifdef BCM_TRIUMPH2_SUPPORT
if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) ||
SOC_IS_VALKYRIE2(unit)) {
return bcm_tr2_cosq_gport_discard_get(unit, port, cosq, discard);
}
#endif
#ifdef BCM_TRX_SUPPORT
if (SOC_IS_TRX(unit)) {
#if defined(BCM_HURRICANE_SUPPORT)
if(SOC_IS_HURRICANE(unit) || SOC_IS_HURRICANE2(unit)) {
return bcm_hu_cosq_gport_discard_get(unit, port, cosq, discard);
} else
#endif
#if defined(BCM_GREYHOUND_SUPPORT)
if(SOC_IS_GREYHOUND(unit) || SOC_IS_HURRICANE3(unit)) {
return bcm_gh_cosq_gport_discard_get(unit, port, cosq, discard);
} else
#endif /*BCM_GREYHOUND_SUPPORT*/
#if defined(BCM_GREYHOUND2_SUPPORT)
if (SOC_IS_GREYHOUND2(unit)) {
return bcmi_gh2_cosq_gport_discard_get(unit, port, cosq, discard);
} else
#endif /* BCM_GREYHOUND2_SUPPORT */
{
return bcm_tr_cosq_gport_discard_get(unit, port, cosq, discard);
}
}
#endif /* BCM_TRX_SUPPORT */
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_gport_discard_extended_set
* Purpose:
*
* Parameters:
* unit - (IN) Unit number.
* id - (IN) Integrated cosq index
* discard - (IN) Discard settings
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_gport_discard_extended_set(
int unit,
bcm_cosq_object_id_t *id,
bcm_cosq_gport_discard_t *discard)
{
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return BCM_E_UNAVAIL;
}
#endif /* BCM_TOMAHAWK3_SUPPORT */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit) && !SOC_IS_TOMAHAWK3(unit)) {
return bcm_th_cosq_gport_discard_set(unit,
id->port, id->cosq, id->buffer, discard);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_gport_discard_extended_get
* Purpose:
*
* Parameters:
* unit - (IN) Unit number.
* id - (IN) Integrated cosq index
* discard - (OUT) Discard settings
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_gport_discard_extended_get(
int unit,
bcm_cosq_object_id_t *id,
bcm_cosq_gport_discard_t *discard)
{
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return BCM_E_UNAVAIL;
}
#endif /* BCM_TOMAHAWK3_SUPPORT */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit) && !SOC_IS_TOMAHAWK3(unit)) {
return bcm_th_cosq_gport_discard_get(unit,
id->port, id->cosq, id->buffer, discard);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_discard_profile_create
* Purpose:
* Create an empty rule profile
* Parameters:
* unit - (IN) unit number
* profile_id - (OUT) profile index
* Returns:
* BCM_E_XXX
*/
int bcm_esw_cosq_discard_profile_create(
int unit,
int *profile_id)
{
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return bcm_th3_cosq_wred_resolution_entry_create(unit, profile_id);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit) && !SOC_IS_TOMAHAWK3(unit)) {
return bcm_th_cosq_wred_resolution_entry_create(unit, profile_id);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
return bcm_hx5_cosq_wred_resolution_entry_create(unit, profile_id);
}
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
return bcm_td3_cosq_wred_resolution_entry_create(unit, profile_id);
}
#endif /* BCM_TRIDENT3_SUPPORT */
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_discard_profile_destroy
* Purpose:
* Destroy a rule profile
* Parameters:
* unit - (IN) unit number
* profile_id - (IN) profile index
* Returns:
* BCM_E_XXX
*/
int bcm_esw_cosq_discard_profile_destroy(
int unit,
int profile_id)
{
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return bcm_th3_cosq_wred_resolution_entry_destroy(unit, profile_id);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit) && !SOC_IS_TOMAHAWK3(unit)) {
return bcm_th_cosq_wred_resolution_entry_destroy(unit, profile_id);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
return bcm_hx5_cosq_wred_resolution_entry_destroy(unit, profile_id);
}
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
return bcm_td3_cosq_wred_resolution_entry_destroy(unit, profile_id);
}
#endif /* BCM_TRIDENT3_SUPPORT */
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_discard_profile_update
* Purpose:
* Update one rule in a profile
* Parameters:
* unit - (IN) unit number
* profile_id - (IN) profile index
* rule - (IN) discard rule
* Returns:
* BCM_E_XXX
*/
int bcm_esw_cosq_discard_profile_update(
int unit,
int profile_id,
bcm_cosq_discard_rule_t *rule)
{
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return bcm_th3_cosq_wred_resolution_set(unit, profile_id, rule);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit) && !SOC_IS_TOMAHAWK3(unit)) {
return bcm_th_cosq_wred_resolution_set(unit, profile_id, rule);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
return bcm_hx5_cosq_wred_resolution_set(unit, profile_id, rule);
}
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
return bcm_td3_cosq_wred_resolution_set(unit, profile_id, rule);
}
#endif /* BCM_TRIDENT3_SUPPORT */
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_discard_profile_get
* Purpose:
* Get all rules of a profile
* Parameters:
* unit - (IN) unit number
* profile_id - (IN) profile index
* max - (IN) rule array size
* rule_array - (OUT) rule array
* rule_count - (OUT) actual rules count
* Returns:
* BCM_E_XXX
*/
int bcm_esw_cosq_discard_profile_get(
int unit,
int profile_id,
int max,
bcm_cosq_discard_rule_t *rule_array,
int *rule_count)
{
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return bcm_th3_cosq_wred_resolution_get(unit, profile_id, max,
rule_array, rule_count);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit) && !SOC_IS_TOMAHAWK3(unit)) {
return bcm_th_cosq_wred_resolution_get(unit, profile_id, max,
rule_array, rule_count);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
return bcm_hx5_cosq_wred_resolution_get(unit, profile_id, max,
rule_array, rule_count);
}
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
return bcm_td3_cosq_wred_resolution_get(unit, profile_id, max,
rule_array, rule_count);
}
#endif /* BCM_TRIDENT3_SUPPORT */
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_cosq_gport_add
* Purpose:
*
* Parameters:
* unit - (IN) Unit number.
* port - (IN) Physical port.
* numq - (IN) Number of COS queues.
* flags - (IN) Flags.
* gport - (IN/OUT) GPORT ID.
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_gport_add(int unit, bcm_gport_t port, int numq,
uint32 flags, bcm_gport_t *gport)
{
if (port == BCM_GPORT_INVALID) {
return (BCM_E_PORT);
}
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
return bcm_mn_cosq_gport_add(unit, port, numq, flags, gport);
}
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_gport_add(unit, port, numq, flags, gport);
}
#endif
#ifdef BCM_TRIUMPH2_SUPPORT
if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) ||
SOC_IS_VALKYRIE2(unit)) {
return bcm_tr2_cosq_gport_add(unit, port, numq, flags, gport);
}
#endif
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
/* Return BCM_E_PARAM because of fixed hierarchy gport tree
is created during init */
return BCM_E_PARAM;
}
#endif /* BCM_TOMAHAWK3_SUPPORT */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
/* Return BCM_E_PARAM because of fixed hierarchy gport tree
is created during init */
return BCM_E_PARAM;
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
/* Return BCM_E_PARAM because of fixed hierarchy gport tree
is created during init */
return BCM_E_PARAM;
}
#endif /* BCM_TRIDENT3_SUPPORT */
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_gport_add(unit, port, numq, flags, gport);
}
#endif /* BCM_TRIDENT2_SUPPORT */
#ifdef BCM_TRIDENT_SUPPORT
if (SOC_IS_TD_TT(unit)) {
return bcm_td_cosq_gport_add(unit, port, numq, flags, gport);
}
#endif /* BCM_TRIDENT_SUPPORT */
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_gport_add(unit, port, numq, flags, gport, 0);
}
#endif
#ifdef BCM_KATANA_SUPPORT
if (SOC_IS_KATANA(unit)) {
return bcm_kt_cosq_gport_add(unit, port, numq, flags, gport);
}
#endif /* BCM_KATANA_SUPPORT */
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_gport_add(unit, port, numq, flags, gport);
}
#endif /* BCM_KATANA2_SUPPORT */
#ifdef BCM_TRIUMPH_SUPPORT
if (SOC_IS_TR_VL(unit)) {
if (!SOC_IS_HURRICANEX(unit) && !SOC_IS_GREYHOUND(unit) &&
!SOC_IS_GREYHOUND2(unit)) {
return bcm_tr_cosq_gport_add(unit, port, numq, flags, gport);
}
}
#endif
#ifdef BCM_GREYHOUND2_SUPPORT
if (SOC_IS_GREYHOUND2(unit)) {
return bcmi_gh2_cosq_gport_add(unit, port, numq, flags, gport);
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_cosq_gport_delete
* Purpose:
*
* Parameters:
* unit - (IN) Unit number.
* gport - (IN) GPORT ID.
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_gport_delete(int unit, bcm_gport_t gport)
{
if (gport == BCM_GPORT_INVALID) {
return (BCM_E_PORT);
}
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
return bcm_mn_cosq_gport_delete(unit, gport);
}
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_gport_delete(unit, gport);
}
#endif
#ifdef BCM_TRIUMPH2_SUPPORT
if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) ||
SOC_IS_VALKYRIE2(unit)) {
return bcm_tr2_cosq_gport_delete(unit, gport);
}
#endif
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
/* Return BCM_E_PARAM because of fixed hierarchy gport tree
is created during init */
return BCM_E_PARAM;
}
#endif
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
/* Return BCM_E_PARAM because of fixed hierarchy gport tree
is created during init */
return BCM_E_PARAM;
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
/* Return BCM_E_PARAM because of fixed hierarchy gport tree
is created during init */
return BCM_E_PARAM;
}
#endif /* BCM_TRIDENT3_SUPPORT */
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_gport_delete(unit, gport);
}
#endif /* BCM_TRIDENT2_SUPPORT */
#ifdef BCM_TRIDENT_SUPPORT
if (SOC_IS_TD_TT(unit)) {
return bcm_td_cosq_gport_delete(unit, gport);
}
#endif /* BCM_TRIDENT_SUPPORT */
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_gport_delete(unit, gport);
}
#endif /* BCM_TRIDENT_SUPPORT */
#ifdef BCM_KATANA_SUPPORT
if (SOC_IS_KATANA(unit)) {
return bcm_kt_cosq_gport_delete(unit, gport);
}
#endif /* BCM_KATANA_SUPPORT */
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_gport_delete(unit, gport);
}
#endif /* BCM_KATANA2_SUPPORT */
#ifdef BCM_TRIUMPH_SUPPORT
/*no stage 1 queues and s1 scheduler to delete for HU*/
if (SOC_IS_TR_VL(unit)) {
if (!SOC_IS_HURRICANEX(unit) && !SOC_IS_GREYHOUND(unit) &&
!SOC_IS_GREYHOUND2(unit)) {
return bcm_tr_cosq_gport_delete(unit, gport);
}
}
#endif
#ifdef BCM_GREYHOUND2_SUPPORT
if (SOC_IS_GREYHOUND2(unit)) {
return bcmi_gh2_cosq_gport_delete(unit, gport);
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_cosq_gport_traverse
* Purpose:
* Walks through the valid COSQ GPORTs and calls
* the user supplied callback function for each entry.
* Parameters:
* unit - (IN) bcm device.
* trav_fn - (IN) Callback function.
* user_data - (IN) User data to be passed to callback function.
* Returns:
* BCM_E_NONE - Success.
* BCM_E_XXX
*/
int
bcm_esw_cosq_gport_traverse(int unit, bcm_cosq_gport_traverse_cb cb,
void *user_data)
{
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
return bcm_mn_cosq_gport_traverse(unit, cb, user_data);
}
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_gport_traverse(unit, cb, user_data);
}
#endif
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return bcm_th3_cosq_gport_traverse(unit, cb, user_data);
}
#endif /* BCM_TOMAHAWK3_SUPPORT */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
return bcm_th_cosq_gport_traverse(unit, cb, user_data);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
return bcm_hx5_cosq_gport_traverse(unit, cb, user_data);
}
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
return bcm_td3_cosq_gport_traverse(unit, cb, user_data);
}
#endif /* BCM_TRIDENT3_SUPPORT */
#ifdef BCM_TRIUMPH2_SUPPORT
if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) ||
SOC_IS_VALKYRIE2(unit)) {
return bcm_tr2_cosq_gport_traverse(unit, cb, user_data);
}
#endif
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_gport_traverse(unit, cb, user_data);
}
#endif /* BCM_TRIDENT2_SUPPORT */
#ifdef BCM_TRIDENT_SUPPORT
if (SOC_IS_TD_TT(unit)) {
return bcm_td_cosq_gport_traverse(unit, cb, user_data);
}
#endif /* BCM_TRIDENT_SUPPORT */
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_gport_traverse(unit, cb, user_data);
}
#endif /* BCM_TRIUMPH3_SUPPORT */
#ifdef BCM_KATANA_SUPPORT
if (SOC_IS_KATANA(unit)) {
return bcm_kt_cosq_gport_traverse(unit, cb, user_data);
}
#endif /* BCM_KATANA_SUPPORT */
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_gport_traverse(unit, cb, user_data);
}
#endif /* BCM_KATANA2_SUPPORT */
#ifdef BCM_TRIUMPH_SUPPORT
/*for each 24q ports, this calls a call-back func
for scheduler gport. 24q ports and scheduler (S1) do not
exist for Hurricane*/
if (SOC_IS_TR_VL(unit)) {
if (!SOC_IS_HURRICANEX(unit) && !SOC_IS_GREYHOUND(unit) &&
!SOC_IS_GREYHOUND2(unit)) {
return bcm_tr_cosq_gport_traverse(unit, cb, user_data);
}
}
#endif
#ifdef BCM_GREYHOUND2_SUPPORT
if (SOC_IS_GREYHOUND2(unit)) {
return bcmi_gh2_cosq_gport_traverse(unit, cb, user_data);
}
#endif /* BCM_GREYHOUND2_SUPPORT */
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_cosq_gport_traverse_by_port
* Purpose:
* Walks through the valid COSQ GPORTs belong to a port and calls
* the user supplied callback function for each entry.
* Parameters:
* unit - (IN) unit number
* port - (IN) port number or GPORT identifier
* trav_fn - (IN) Callback function.
* user_data - (IN) User data to be passed to callback function
* Returns:
* BCM_E_NONE - Success.
* BCM_E_XXX
*/
int
bcm_esw_cosq_gport_traverse_by_port(int unit, bcm_gport_t port,
bcm_cosq_gport_traverse_cb cb,
void *user_data)
{
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
return bcm_th_cosq_gport_traverse_by_port(unit, port, cb, user_data);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
return bcm_hx5_cosq_gport_traverse_by_port(unit, port, cb, user_data);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
return BCM_E_UNAVAIL;
}
int
bcm_esw_cosq_gport_mapping_set(int unit, bcm_port_t ing_port,
bcm_cos_t int_pri, uint32 flags,
bcm_gport_t gport, bcm_cos_queue_t cosq)
{
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
return bcm_mn_cosq_gport_mapping_set(unit, ing_port, int_pri, flags,
gport, cosq);
}
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_gport_mapping_set(unit, ing_port, int_pri, flags,
gport, cosq);
}
#endif
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_gport_mapping_set(unit, ing_port, int_pri, flags,
gport, cosq);
}
#endif /* BCM_TRIDENT_SUPPORT */
if (!soc_feature(unit, soc_feature_ets)) {
return BCM_E_UNAVAIL;
}
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return bcm_th3_cosq_gport_mapping_set(unit, ing_port, int_pri, flags,
gport, cosq);
}
#endif /* BCM_TOMAHAWK3_SUPPORT */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
return bcm_th_cosq_gport_mapping_set(unit, ing_port, int_pri, flags,
gport, cosq);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
return bcm_hx5_cosq_gport_mapping_set(unit, ing_port, int_pri, flags,
gport, cosq);
}
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
return bcm_td3_cosq_gport_mapping_set(unit, ing_port, int_pri, flags,
gport, cosq);
}
#endif /* BCM_TRIDENT3_SUPPORT */
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_gport_mapping_set(unit, ing_port, int_pri, flags,
gport, cosq);
}
#endif /* BCM_TRIDENT2_SUPPORT */
#ifdef BCM_TRIDENT_SUPPORT
if (SOC_IS_TD_TT(unit)) {
return bcm_td_cosq_gport_mapping_set(unit, ing_port, int_pri, flags,
gport, cosq);
}
#endif /* BCM_TRIDENT_SUPPORT */
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_gport_mapping_set(unit, ing_port, int_pri, flags,
gport, cosq);
}
#endif /* BCM_TRIDENT_SUPPORT */
return BCM_E_UNAVAIL;
}
int
bcm_esw_cosq_gport_mapping_get(int unit, bcm_port_t ing_port,
bcm_cos_t int_pri, uint32 flags,
bcm_gport_t *gport, bcm_cos_queue_t *cosq)
{
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_gport_mapping_get(unit, ing_port, int_pri, flags,
gport, cosq);
}
#endif /* BCM_KATANA2_SUPPORT */
if (!soc_feature(unit, soc_feature_ets)) {
return BCM_E_UNAVAIL;
}
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
return bcm_mn_cosq_gport_mapping_get(unit, ing_port, int_pri, flags,
gport, cosq);
}
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_gport_mapping_get(unit, ing_port, int_pri, flags,
gport, cosq);
}
#endif
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return bcm_th3_cosq_gport_mapping_get(unit, ing_port, int_pri, flags,
gport, cosq);
}
#endif /* BCM_TOMAHAWK3_SUPPORT */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
return bcm_th_cosq_gport_mapping_get(unit, ing_port, int_pri, flags,
gport, cosq);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
return bcm_hx5_cosq_gport_mapping_get(unit, ing_port, int_pri, flags,
gport, cosq);
}
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
return bcm_td3_cosq_gport_mapping_get(unit, ing_port, int_pri, flags,
gport, cosq);
}
#endif /* BCM_TRIDENT3_SUPPORT */
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_gport_mapping_get(unit, ing_port, int_pri, flags,
gport, cosq);
}
#endif /* BCM_TRIDENT2_SUPPORT */
#ifdef BCM_TRIDENT_SUPPORT
if (SOC_IS_TD_TT(unit)) {
return bcm_td_cosq_gport_mapping_get(unit, ing_port, int_pri, flags,
gport, cosq);
}
#endif /* BCM_TRIDENT_SUPPORT */
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_gport_mapping_get(unit, ing_port, int_pri, flags,
gport, cosq);
}
#endif /* BCM_TRIUMPH3_SUPPORT */
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_cosq_gport_bandwidth_set
* Purpose:
*
* Parameters:
* unit - (IN) Unit number.
* gport - (IN) GPORT ID.
* cosq - (IN) COS queue to configure, -1 for all COS queues.
* kbits_sec_min - (IN) minimum bandwidth, kbits/sec.
* kbits_sec_max - (IN) maximum bandwidth, kbits/sec.
* flags - (IN) BCM_COSQ_BW_*
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_gport_bandwidth_set(int unit, bcm_gport_t gport,
bcm_cos_queue_t cosq, uint32 kbits_sec_min,
uint32 kbits_sec_max, uint32 flags)
{
if (gport == BCM_GPORT_INVALID) {
return (BCM_E_PORT);
}
if ((kbits_sec_max != 0) && (kbits_sec_max < kbits_sec_min )) {
return (BCM_E_PARAM);
}
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
return bcm_mn_cosq_gport_bandwidth_set(unit, gport,
cosq, kbits_sec_min,
kbits_sec_max, flags);
}
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_gport_bandwidth_set(unit, gport,
cosq, kbits_sec_min,
kbits_sec_max, flags);
}
#endif
#ifdef BCM_TRIUMPH2_SUPPORT
if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) ||
SOC_IS_VALKYRIE2(unit)) {
return bcm_tr2_cosq_gport_bandwidth_set(unit, gport,
cosq, kbits_sec_min,
kbits_sec_max, flags);
}
#endif
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return bcm_th3_cosq_gport_bandwidth_set(unit, gport, cosq,
kbits_sec_min, kbits_sec_max,
flags);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit) && !SOC_IS_TOMAHAWK3(unit)) {
return bcm_th_cosq_gport_bandwidth_set(unit, gport, cosq,
kbits_sec_min, kbits_sec_max,
flags);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
return bcm_hx5_cosq_gport_bandwidth_set(unit, gport, cosq,
kbits_sec_min, kbits_sec_max,
flags);
}
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
return bcm_td3_cosq_gport_bandwidth_set(unit, gport, cosq,
kbits_sec_min, kbits_sec_max,
flags);
}
#endif /* BCM_TRIDENT3_SUPPORT */
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_gport_bandwidth_set(unit, gport, cosq,
kbits_sec_min, kbits_sec_max,
flags);
}
#endif /* BCM_TRIDENT2_SUPPORT */
#ifdef BCM_TRIDENT_SUPPORT
if (SOC_IS_TD_TT(unit)) {
return bcm_td_cosq_gport_bandwidth_set(unit, gport, cosq,
kbits_sec_min, kbits_sec_max,
flags);
}
#endif /* BCM_TRIDENT_SUPPORT */
#ifdef BCM_KATANA_SUPPORT
if (SOC_IS_KATANA(unit)) {
return bcm_kt_cosq_gport_child_node_bandwidth_set(unit, gport, cosq,
kbits_sec_min, kbits_sec_max,
flags);
}
#endif /* BCM_KATANA_SUPPORT */
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_gport_child_node_bandwidth_set(unit, gport, cosq,
kbits_sec_min, kbits_sec_max,
flags);
}
#endif /* BCM_KATANA2_SUPPORT */
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_gport_bandwidth_set(unit, gport, cosq,
kbits_sec_min, kbits_sec_max,
flags);
}
#endif /* BCM_TRIUMPH3_SUPPORT */
#ifdef BCM_TRIUMPH_SUPPORT
if (SOC_IS_TR_VL(unit)) {
#if defined(BCM_HURRICANE_SUPPORT)
if(SOC_IS_HURRICANEX(unit) || SOC_IS_GREYHOUND(unit)) {
return bcm_hu_cosq_gport_bandwidth_set(unit, gport,
cosq, kbits_sec_min,
kbits_sec_max, flags);
}
#endif /*SOC_IS_HURRICANE*/
#if defined(BCM_GREYHOUND2_SUPPORT)
if (SOC_IS_GREYHOUND2(unit)) {
return bcmi_gh2_cosq_gport_bandwidth_set(unit, gport,
cosq, kbits_sec_min,
kbits_sec_max, flags);
}
#endif /* BCM_GREYHOUND2_SUPPORT */
return bcm_tr_cosq_gport_bandwidth_set(unit, gport,
cosq, kbits_sec_min,
kbits_sec_max, flags);
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_cosq_gport_bandwidth_get
* Purpose:
*
* Parameters:
* unit - (IN) Unit number.
* gport - (IN) GPORT ID.
* cosq - (IN) COS queue to configure, -1 for all COS queues.
* kbits_sec_min - (OUT) minimum bandwidth, kbits/sec.
* kbits_sec_max - (OUT) maximum bandwidth, kbits/sec.
* flags - (OUT) BCM_COSQ_BW_*
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_gport_bandwidth_get(int unit, bcm_gport_t gport,
bcm_cos_queue_t cosq, uint32 *kbits_sec_min,
uint32 *kbits_sec_max, uint32 *flags)
{
if (gport == BCM_GPORT_INVALID) {
return (BCM_E_PORT);
}
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
return bcm_mn_cosq_gport_bandwidth_get(unit, gport,
cosq, kbits_sec_min,
kbits_sec_max, flags);
}
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_gport_bandwidth_get(unit, gport,
cosq, kbits_sec_min,
kbits_sec_max, flags);
}
#endif
#ifdef BCM_TRIUMPH2_SUPPORT
if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) ||
SOC_IS_VALKYRIE2(unit)) {
return bcm_tr2_cosq_gport_bandwidth_get(unit, gport,
cosq, kbits_sec_min,
kbits_sec_max, flags);
}
#endif
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return bcm_th3_cosq_gport_bandwidth_get(unit, gport, cosq,
kbits_sec_min, kbits_sec_max,
flags);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit) && !SOC_IS_TOMAHAWK3(unit)) {
return bcm_th_cosq_gport_bandwidth_get(unit, gport, cosq,
kbits_sec_min, kbits_sec_max,
flags);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
return bcm_hx5_cosq_gport_bandwidth_get(unit, gport, cosq,
kbits_sec_min, kbits_sec_max,
flags);
}
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
return bcm_td3_cosq_gport_bandwidth_get(unit, gport, cosq,
kbits_sec_min, kbits_sec_max,
flags);
}
#endif /* BCM_TRIDENT3_SUPPORT */
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_gport_bandwidth_get(unit, gport, cosq,
kbits_sec_min, kbits_sec_max,
flags);
}
#endif /* BCM_TRIDENT2_SUPPORT */
#ifdef BCM_TRIDENT_SUPPORT
if (SOC_IS_TD_TT(unit)) {
return bcm_td_cosq_gport_bandwidth_get(unit, gport, cosq,
kbits_sec_min, kbits_sec_max,
flags);
}
#endif /* BCM_TRIDENT_SUPPORT */
#ifdef BCM_KATANA_SUPPORT
if (SOC_IS_KATANA(unit)) {
return bcm_kt_cosq_gport_child_node_bandwidth_get(unit, gport, cosq,
kbits_sec_min, kbits_sec_max,
flags);
}
#endif /* BCM_KATANA_SUPPORT */
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_gport_child_node_bandwidth_get(unit, gport, cosq,
kbits_sec_min, kbits_sec_max,
flags);
}
#endif /* BCM_KATANA2_SUPPORT */
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_gport_bandwidth_get(unit, gport, cosq,
kbits_sec_min, kbits_sec_max,
flags);
}
#endif /* BCM_TRIUMPH3_SUPPORT */
#ifdef BCM_TRIUMPH_SUPPORT
if (SOC_IS_TR_VL(unit)) {
#if defined(BCM_HURRICANE_SUPPORT)
if(SOC_IS_HURRICANEX(unit) || SOC_IS_GREYHOUND(unit)) {
return bcm_hu_cosq_gport_bandwidth_get(unit, gport,
cosq, kbits_sec_min,
kbits_sec_max, flags);
} else
#endif /* BCM_HURRICANE_SUPPORT*/
#if defined(BCM_GREYHOUND2_SUPPORT)
if (SOC_IS_GREYHOUND2(unit)) {
return bcmi_gh2_cosq_gport_bandwidth_get(unit, gport,
cosq, kbits_sec_min,
kbits_sec_max, flags);
} else
#endif /* BCM_GREYHOUND2_SUPPORT */
{
return bcm_tr_cosq_gport_bandwidth_get(unit, gport,
cosq, kbits_sec_min,
kbits_sec_max, flags);
}
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_cosq_gport_sched_set
* Purpose:
*
* Parameters:
* unit - (IN) Unit number.
* gport - (IN) GPORT ID.
* cosq - (IN) COS queue to configure, -1 for all COS queues.
* mode - (IN) Scheduling mode, one of BCM_COSQ_xxx
* weight - (IN) Weight for the specified COS queue(s)
* Unused if mode is BCM_COSQ_STRICT.
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_gport_sched_set(int unit, bcm_gport_t gport,
bcm_cos_queue_t cosq, int mode, int weight)
{
if (gport == BCM_GPORT_INVALID) {
return (BCM_E_PORT);
}
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
return bcm_mn_cosq_gport_sched_set(unit, gport, cosq, mode, weight);
}
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_gport_sched_set(unit, gport, cosq, mode, weight);
}
#endif
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return bcm_th3_cosq_gport_sched_set(unit, gport, cosq, mode, weight);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
return bcm_th_cosq_gport_sched_set(unit, gport, cosq, mode, weight);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
return bcm_hx5_cosq_gport_sched_set(unit, gport, cosq, mode, weight);
}
#endif
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
return bcm_td3_cosq_gport_sched_set(unit, gport, cosq, mode, weight);
}
#endif /* BCM_TRIDENT3_SUPPORT */
#ifdef BCM_TRIUMPH2_SUPPORT
if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) ||
SOC_IS_VALKYRIE2(unit)) {
return bcm_tr2_cosq_gport_sched_set(unit, gport, cosq, mode, weight);
}
#endif
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_gport_sched_set(unit, gport, cosq, mode, weight);
}
#endif /* BCM_TRIDENT2_SUPPORT */
#ifdef BCM_TRIDENT_SUPPORT
if (SOC_IS_TD_TT(unit)) {
return bcm_td_cosq_gport_sched_set(unit, gport, cosq, mode, weight);
}
#endif /* BCM_TRIDENT_SUPPORT */
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_gport_sched_set(unit, gport, cosq, mode, weight);
}
#endif /* BCM_TRIDENT_SUPPORT */
#ifdef BCM_KATANA_SUPPORT
if (SOC_IS_KATANA(unit)) {
return bcm_kt_cosq_gport_sched_set(unit, gport, cosq, mode, weight);
}
#endif /* BCM_KATANA_SUPPORT */
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_gport_sched_set(unit, gport, cosq, mode, weight);
}
#endif /* BCM_KATANA2_SUPPORT */
#ifdef BCM_TRIUMPH_SUPPORT
if (SOC_IS_TR_VL(unit)) {
#if defined(BCM_HURRICANE_SUPPORT)
if(SOC_IS_HURRICANEX(unit) || SOC_IS_GREYHOUND(unit)) {
return bcm_hu_cosq_gport_sched_set(unit, gport, cosq, mode, weight);
} else
#endif /* BCM_HURRICANE_SUPPORT*/
#if defined(BCM_GREYHOUND2_SUPPORT)
if (SOC_IS_GREYHOUND2(unit)) {
return bcmi_gh2_cosq_gport_sched_set(
unit, gport, cosq, mode, weight);
} else
#endif /* BCM_GREYHOUND2_SUPPORT */
{
return bcm_tr_cosq_gport_sched_set(unit, gport, cosq, mode, weight);
}
}
#endif
#ifdef BCM_SCORPION_SUPPORT
if (SOC_IS_SC_CQ(unit)) {
return bcm_sc_cosq_gport_sched_set(unit, gport, cosq, mode, weight);
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_cosq_gport_sched_get
* Purpose:
*
* Parameters:
* unit - (IN) Unit number.
* gport - (IN) GPORT ID.
* cosq - (IN) COS queue
* mode - (OUT) Scheduling mode, one of BCM_COSQ_xxx
* weight - (OUT) Weight for the specified COS queue(s)
* Unused if mode is BCM_COSQ_STRICT.
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_gport_sched_get(int unit, bcm_gport_t gport,
bcm_cos_queue_t cosq, int *mode, int *weight)
{
if (gport == BCM_GPORT_INVALID) {
return (BCM_E_PORT);
}
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
return bcm_mn_cosq_gport_sched_get(unit, gport, cosq, mode, weight);
}
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_gport_sched_get(unit, gport, cosq, mode, weight);
}
#endif
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return bcm_th3_cosq_gport_sched_get(unit, gport, cosq, mode, weight);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
return bcm_th_cosq_gport_sched_get(unit, gport, cosq, mode, weight);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
return bcm_hx5_cosq_gport_sched_get(unit, gport, cosq, mode, weight);
}
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
return bcm_td3_cosq_gport_sched_get(unit, gport, cosq, mode, weight);
}
#endif /* BCM_TRIDENT3_SUPPORT */
#ifdef BCM_TRIUMPH2_SUPPORT
if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) ||
SOC_IS_VALKYRIE2(unit)) {
return bcm_tr2_cosq_gport_sched_get(unit, gport, cosq, mode, weight);
}
#endif
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_gport_sched_get(unit, gport, cosq, mode, weight);
}
#endif /* BCM_TRIDENT2_SUPPORT */
#ifdef BCM_TRIDENT_SUPPORT
if (SOC_IS_TD_TT(unit)) {
return bcm_td_cosq_gport_sched_get(unit, gport, cosq, mode, weight);
}
#endif /* BCM_TRIDENT_SUPPORT */
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_gport_sched_get(unit, gport, cosq, mode, weight);
}
#endif /* BCM_TRIDENT_SUPPORT */
#ifdef BCM_KATANA_SUPPORT
if (SOC_IS_KATANA(unit)) {
return bcm_kt_cosq_gport_sched_get(unit, gport, cosq, mode, weight);
}
#endif /* BCM_KATANA_SUPPORT */
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_gport_sched_get(unit, gport, cosq, mode, weight);
}
#endif /* BCM_KATANA2_SUPPORT */
#ifdef BCM_TRIUMPH_SUPPORT
if (SOC_IS_TR_VL(unit)) {
#if defined(BCM_HURRICANE_SUPPORT)
if(SOC_IS_HURRICANEX(unit) || SOC_IS_GREYHOUND(unit)) {
return bcm_hu_cosq_gport_sched_get(unit, gport, cosq, mode, weight);
} else
#endif /* BCM_HURRICANE_SUPPORT*/
#if defined(BCM_GREYHOUND2_SUPPORT)
if (SOC_IS_GREYHOUND2(unit)) {
return bcmi_gh2_cosq_gport_sched_get(
unit, gport, cosq, mode, weight);
} else
#endif /* BCM_GREYHOUND2_SUPPORT */
{
return bcm_tr_cosq_gport_sched_get(unit, gport, cosq, mode, weight);
}
}
#endif
#ifdef BCM_SCORPION_SUPPORT
if (SOC_IS_SC_CQ(unit)) {
return bcm_sc_cosq_gport_sched_get(unit, gport, cosq, mode, weight);
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_cosq_gport_attach
* Purpose:
*
* Parameters:
* unit - (IN) Unit number.
* sched_port - (IN) Scheduler GPORT ID.
* input_port - (IN) GPORT to attach to.
* cosq - (IN) COS queue to attach to.
* Returns:
* BCM_E_XXX
* Notes:
*/
int
bcm_esw_cosq_gport_attach(int unit, bcm_gport_t sched_gport,
bcm_gport_t input_gport, bcm_cos_queue_t cosq)
{
if (sched_gport == BCM_GPORT_INVALID) {
return (BCM_E_PORT);
}
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
return bcm_mn_cosq_gport_attach(unit, sched_gport,
input_gport, cosq);
}
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_gport_attach(unit, sched_gport,
input_gport, cosq);
}
#endif
#ifdef BCM_TRIUMPH2_SUPPORT
if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) ||
SOC_IS_VALKYRIE2(unit)) {
return bcm_tr2_cosq_gport_attach(unit, sched_gport,
input_gport, cosq);
}
#endif
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return bcm_th3_cosq_gport_attach(unit, sched_gport, input_gport, cosq);
}
#endif /* BCM_TOMAHAWK3_SUPPORT */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
return bcm_th_cosq_gport_attach(unit, sched_gport, input_gport, cosq);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
return bcm_hx5_cosq_gport_attach(unit, sched_gport, input_gport, cosq);
}
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
return bcm_td3_cosq_gport_attach(unit, sched_gport, input_gport, cosq);
}
#endif /* BCM_TRIDENT3_SUPPORT */
#if defined(BCM_TRIDENT2_SUPPORT)
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_gport_attach(unit, sched_gport, input_gport, cosq);
}
#endif /* BCM_TRIDENT2_SUPPORT */
#if defined(BCM_TRIDENT_SUPPORT)
if (SOC_IS_TD_TT(unit)) {
return bcm_td_cosq_gport_attach(unit, sched_gport, input_gport, cosq);
}
#endif /* BCM_TRIDENT_SUPPORT */
#if defined(BCM_TRIUMPH3_SUPPORT)
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_gport_attach(unit, sched_gport, input_gport, cosq);
}
#endif /* BCM_TRIUMPH3_SUPPORT */
#ifdef BCM_KATANA_SUPPORT
if (SOC_IS_KATANA(unit)) {
return bcm_kt_cosq_gport_attach(unit, sched_gport, input_gport, cosq);
}
#endif /* BCM_KATANA_SUPPORT */
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
BCM_IF_ERROR_RETURN(bcm_kt2_cosq_gport_validate(unit,
sched_gport, input_gport, cosq));
return bcm_kt2_cosq_gport_attach(unit, sched_gport, input_gport, cosq);
}
#endif /* BCM_KATANA2_SUPPORT */
#ifdef BCM_TRIUMPH_SUPPORT
/*for HU there is no VLAN cosq and scheduler (S1)*/
if (SOC_IS_TR_VL(unit)) {
if (!SOC_IS_HURRICANEX(unit) && ! SOC_IS_GREYHOUND(unit) &&
!SOC_IS_GREYHOUND2(unit)) {
return bcm_tr_cosq_gport_attach(unit, sched_gport,
input_gport, cosq);
}
}
#endif
#if defined(BCM_GREYHOUND2_SUPPORT)
if (SOC_IS_GREYHOUND2(unit)) {
return bcmi_gh2_cosq_gport_attach(unit, sched_gport, input_gport, cosq);
}
#endif /* BCM_GREYHOUND2_SUPPORT */
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_cosq_gport_reattach
* Purpose:
*
* Parameters:
* unit - (IN) Unit number.
* sched_port - (IN) Scheduler GPORT ID.
* input_port - (IN) GPORT to attach to.
* cosq - (IN) COS queue to attach to.
* Returns:
* BCM_E_XXX
* Notes:
*/
int
bcm_esw_cosq_gport_reattach(int unit, bcm_gport_t sched_gport,
bcm_gport_t input_gport, bcm_cos_queue_t cosq)
{
if (sched_gport == BCM_GPORT_INVALID) {
return (BCM_E_PORT);
}
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_gport_reattach(unit, sched_gport,
input_gport, cosq);
}
#endif /* BCM_KATANA2_SUPPORT */
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_cosq_gport_detach
* Purpose:
*
* Parameters:
* unit - (IN) Unit number.
* sched_port - (IN) Scheduler GPORT ID.
* input_port - (IN) GPORT to detach from.
* cosq - (IN) COS queue to detach from.
* Returns:
* BCM_E_XXX
* Notes:
*/
int
bcm_esw_cosq_gport_detach(int unit, bcm_gport_t sched_gport,
bcm_gport_t input_gport, bcm_cos_queue_t cosq)
{
if (sched_gport == BCM_GPORT_INVALID || input_gport == BCM_GPORT_INVALID) {
return (BCM_E_PORT);
}
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
return bcm_mn_cosq_gport_detach(unit, sched_gport,
input_gport, cosq);
}
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_gport_detach(unit, sched_gport,
input_gport, cosq);
}
#endif
#ifdef BCM_TRIUMPH2_SUPPORT
if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) ||
SOC_IS_VALKYRIE2(unit)) {
return bcm_tr2_cosq_gport_detach(unit, sched_gport,
input_gport, cosq);
}
#endif
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return bcm_th3_cosq_gport_detach(unit, sched_gport, input_gport, cosq);
}
#endif /* BCM_TOMAHAWK3_SUPPORT */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
return bcm_th_cosq_gport_detach(unit, sched_gport, input_gport, cosq);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
return bcm_hx5_cosq_gport_detach(unit, sched_gport, input_gport, cosq);
}
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
return bcm_td3_cosq_gport_detach(unit, sched_gport, input_gport, cosq);
}
#endif /* BCM_TRIDENT3_SUPPORT */
#if defined(BCM_TRIDENT2_SUPPORT)
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_gport_detach(unit, sched_gport, input_gport, cosq);
}
#endif /* BCM_TRIDENT2_SUPPORT */
#if defined(BCM_TRIDENT_SUPPORT)
if (SOC_IS_TD_TT(unit)) {
return bcm_td_cosq_gport_detach(unit, sched_gport, input_gport, cosq);
}
#endif /* BCM_TRIDENT_SUPPORT */
#if defined(BCM_TRIUMPH3_SUPPORT)
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_gport_detach(unit, sched_gport, input_gport, cosq);
}
#endif /* BCM_TRIUMPH3_SUPPORT */
#if defined(BCM_KATANA_SUPPORT)
if (SOC_IS_KATANA(unit)) {
return bcm_kt_cosq_gport_detach(unit, sched_gport, input_gport, cosq);
}
#endif /* BCM_KATANA_SUPPORT */
#if defined(BCM_KATANA2_SUPPORT)
if (SOC_IS_KATANA2(unit)) {
BCM_IF_ERROR_RETURN (bcm_kt2_cosq_gport_validate
(unit, sched_gport, input_gport, cosq));
return bcm_kt2_cosq_gport_detach(unit, sched_gport, input_gport, cosq);
}
#endif /* BCM_KATANA2_SUPPORT */
#ifdef BCM_TRIUMPH_SUPPORT
if (SOC_IS_TR_VL(unit)) {
if (!SOC_IS_HURRICANEX(unit) && ! SOC_IS_GREYHOUND(unit) &&
!SOC_IS_GREYHOUND2(unit)) {
return bcm_tr_cosq_gport_detach(unit, sched_gport,
input_gport, cosq);
}
}
#endif
#if defined(BCM_GREYHOUND2_SUPPORT)
if (SOC_IS_GREYHOUND2(unit)) {
return bcmi_gh2_cosq_gport_detach(unit, sched_gport, input_gport, cosq);
}
#endif /* BCM_GREYHOUND2_SUPPORT */
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_cosq_gport_attach_get
* Purpose:
*
* Parameters:
* unit - (IN) Unit number.
* sched_port - (IN) Scheduler GPORT ID.
* input_port - (OUT) GPORT attached to.
* cosq - (OUT) COS queue attached to.
* Returns:
* BCM_E_XXX
* Notes:
*/
int
bcm_esw_cosq_gport_attach_get(int unit, bcm_gport_t sched_gport,
bcm_gport_t *input_gport, bcm_cos_queue_t *cosq)
{
if (sched_gport == BCM_GPORT_INVALID) {
return (BCM_E_PORT);
}
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
return bcm_mn_cosq_gport_attach_get(unit, sched_gport,
input_gport, cosq);
}
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_gport_attach_get(unit, sched_gport,
input_gport, cosq);
}
#endif
#ifdef BCM_TRIUMPH2_SUPPORT
if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) ||
SOC_IS_VALKYRIE2(unit)) {
return bcm_tr2_cosq_gport_attach_get(unit, sched_gport,
input_gport, cosq);
}
#endif
#if defined(BCM_TOMAHAWK3_SUPPORT)
if (SOC_IS_TOMAHAWK3(unit)) {
return bcm_th3_cosq_gport_attach_get(unit, sched_gport, input_gport,
cosq);
}
#endif /* BCM_TOMAHAWK3_SUPPORT */
#if defined(BCM_TOMAHAWK_SUPPORT)
if (SOC_IS_TOMAHAWKX(unit)) {
return bcm_th_cosq_gport_attach_get(unit, sched_gport, input_gport,
cosq);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
return bcm_hx5_cosq_gport_attach_get(unit, sched_gport, input_gport,
cosq);
}
#endif /* BCM_HELIX5_SUPPORT */
#if defined(BCM_TRIDENT3_SUPPORT)
if (SOC_IS_TRIDENT3X(unit)) {
return bcm_td3_cosq_gport_attach_get(unit, sched_gport, input_gport,
cosq);
}
#endif /* BCM_TRIDENT3_SUPPORT */
#if defined(BCM_TRIDENT2_SUPPORT)
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_gport_attach_get(unit, sched_gport, input_gport,
cosq);
}
#endif /* BCM_TRIDENT2_SUPPORT */
#if defined(BCM_TRIDENT_SUPPORT)
if (SOC_IS_TD_TT(unit)) {
return bcm_td_cosq_gport_attach_get(unit, sched_gport, input_gport,
cosq);
}
#endif /* BCM_TRIDENT_SUPPORT */
#if defined(BCM_KATANA_SUPPORT)
if (SOC_IS_KATANA(unit)) {
return bcm_kt_cosq_gport_attach_get(unit, sched_gport, input_gport,
cosq);
}
#endif /* BCM_KATANA_SUPPORT */
#if defined(BCM_KATANA2_SUPPORT)
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_gport_attach_get(unit, sched_gport, input_gport,
cosq);
}
#endif /* BCM_KATANA2_SUPPORT */
#if defined(BCM_TRIUMPH3_SUPPORT)
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_gport_attach_get(unit, sched_gport, input_gport,
cosq);
}
#endif /* BCM_TRIUMPH3_SUPPORT */
#ifdef BCM_TRIUMPH_SUPPORT
if (SOC_IS_TR_VL(unit)) {
if (!SOC_IS_HURRICANEX(unit) && ! SOC_IS_GREYHOUND(unit) &&
!SOC_IS_GREYHOUND2(unit)) {
return bcm_tr_cosq_gport_attach_get(unit, sched_gport,
input_gport, cosq);
}
}
#endif
#if defined(BCM_GREYHOUND2_SUPPORT)
if (SOC_IS_GREYHOUND2(unit)) {
return bcmi_gh2_cosq_gport_attach_get(unit, sched_gport, input_gport,
cosq);
}
#endif /* BCM_GREYHOUND2_SUPPORT */
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_cosq_gport_child_get
* Purpose:
*
* Parameters:
* unit - (IN) Unit number.
* in_gport - (IN) Scheduler GPORT ID.
* cosq - (IN) COS queue attached to.
* out_gport - (OUT) child GPORT ID.
* Returns:
* BCM_E_XXX
* Notes:
*/
int
bcm_esw_cosq_gport_child_get(int unit, bcm_gport_t in_gport,
bcm_cos_queue_t cosq,
bcm_gport_t *out_gport)
{
if (in_gport == BCM_GPORT_INVALID) {
return (BCM_E_PORT);
}
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return bcm_th3_cosq_gport_child_get(unit, in_gport,cosq,
out_gport);
}
#endif /* BCM_TOMAHAWK3_SUPPORT */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
return bcm_th_cosq_gport_child_get(unit, in_gport,cosq,
out_gport);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
return bcm_mn_cosq_gport_child_get(unit, in_gport,cosq,
out_gport);
}
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
return bcm_hx5_cosq_gport_child_get(unit, in_gport,cosq,
out_gport);
}
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
return bcm_td3_cosq_gport_child_get(unit, in_gport,cosq,
out_gport);
}
#endif /* BCM_TRIDENT3_SUPPORT */
#if defined(BCM_APACHE_SUPPORT)
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_gport_child_get(unit, in_gport,cosq,
out_gport);
}
#endif /* BCM_APACHE_SUPPORT */
#if defined(BCM_TRIDENT2_SUPPORT)
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_gport_child_get(unit, in_gport,cosq,
out_gport);
}
#endif /* BCM_TRIDENT2_SUPPORT */
#if defined(BCM_GREYHOUND2_SUPPORT)
if (SOC_IS_GREYHOUND2(unit)) {
return bcmi_gh2_cosq_gport_child_get(unit, in_gport, cosq,
out_gport);
}
#endif /* BCM_GREYHOUND2_SUPPORT */
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_gport_child_get(unit, in_gport,cosq,
out_gport);
}
#endif /* BCM_TRIUMPH3_SUPPORT */
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_cosq_gport_get
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_gport_get(
int unit,
bcm_gport_t gport,
bcm_gport_t *physical_port,
int *num_cos_levels,
uint32 *flags)
{
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
return bcm_mn_cosq_gport_get(unit, gport, physical_port,
num_cos_levels, flags);
}
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_gport_get(unit, gport, physical_port,
num_cos_levels, flags);
}
#endif
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return bcm_th3_cosq_gport_get(unit, gport, physical_port,
num_cos_levels, flags);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
return bcm_th_cosq_gport_get(unit, gport, physical_port,
num_cos_levels, flags);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
return bcm_hx5_cosq_gport_get(unit, gport, physical_port,
num_cos_levels, flags);
}
#endif /* BCM_TRIDENT3_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
return bcm_td3_cosq_gport_get(unit, gport, physical_port,
num_cos_levels, flags);
}
#endif /* BCM_TRIDENT3_SUPPORT */
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_gport_get(unit, gport, physical_port,
num_cos_levels, flags);
}
#endif /* BCM_TRIDENT2_SUPPORT */
#ifdef BCM_TRIDENT_SUPPORT
if (SOC_IS_TD_TT(unit)) {
return bcm_td_cosq_gport_get(unit, gport, physical_port,
num_cos_levels, flags);
}
#endif /* BCM_TRIDENT_SUPPORT */
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_gport_get(unit, gport, physical_port,
num_cos_levels, flags);
}
#endif /* BCM_TRIUMPH3_SUPPORT */
#ifdef BCM_KATANA_SUPPORT
if (SOC_IS_KATANA(unit)) {
return bcm_kt_cosq_gport_get(unit, gport, physical_port,
num_cos_levels, flags);
}
#endif /* BCM_KATANA_SUPPORT */
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_gport_get(unit, gport, physical_port,
num_cos_levels, flags);
}
#endif /* BCM_KATANA2_SUPPORT */
#ifdef BCM_GREYHOUND2_SUPPORT
if (SOC_IS_GREYHOUND2(unit)) {
return bcmi_gh2_cosq_gport_get(unit, gport, physical_port,
num_cos_levels, flags);
}
#endif /* BCM_GREYHOUND2_SUPPORT */
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_cosq_gport_size_set
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_gport_size_set(
int unit,
bcm_gport_t gport,
bcm_cos_queue_t cosq,
uint32 bytes_min,
uint32 bytes_max)
{
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_cosq_gport_size_get
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_gport_size_get(
int unit,
bcm_gport_t gport,
bcm_cos_queue_t cosq,
uint32 *bytes_min,
uint32 *bytes_max)
{
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_cosq_gport_enable_set
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_gport_enable_set(
int unit,
bcm_gport_t gport,
bcm_cos_queue_t cosq,
int enable)
{
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_cosq_gport_enable_get
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_gport_enable_get(
int unit,
bcm_gport_t gport,
bcm_cos_queue_t cosq,
int *enable)
{
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_cosq_gport_stat_enable_set
* Purpose:
* ?
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_gport_stat_enable_set(
int unit,
bcm_gport_t gport,
int enable)
{
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_cosq_gport_stat_enable_get
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_gport_stat_enable_get(
int unit,
bcm_gport_t gport,
int *enable)
{
return BCM_E_UNAVAIL;
}
/*
* Function:
* _bcm_esw_cosq_gport_stat_get
* if sync_mode is set, sync the sw accumulated count
* with hw count value first, else return sw count.
*
*Parameters:
* unit - (IN) Unit number.
* sync_mode - (IN) hwcount is to be synced to sw count
* port - (IN) GPORT ID.
* cosq - (IN) COS queue to configure
* stat - (IN) Statistic to be retrieved.
* value - (OUT) Returned statistic value.
* Returns:
* BCM_E_XXX
*/
int
_bcm_esw_cosq_gport_stat_get(
int unit,
int sync_mode,
bcm_gport_t gport,
bcm_cos_queue_t cosq,
bcm_cosq_gport_stats_t stat,
uint64 *value)
{
#ifdef BCM_KATANA_SUPPORT
if (soc_feature(unit, soc_feature_cosq_gport_stat_ability)) {
return bcm_kt_cosq_gport_stat_get(unit, sync_mode, gport, cosq,
stat, value);
}
#endif /* BCM_KATANA_SUPPORT */
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_gport_stat_get
* Parameters:
* unit - (IN) Unit number
* gport - (IN) GPORT ID
* cosq - (IN) COS queue.
* stat - (IN) Statistic to be retrieved.
* value - (OUT) Returned statistic value.
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_gport_stat_get(
int unit,
bcm_gport_t gport,
bcm_cos_queue_t cosq,
bcm_cosq_gport_stats_t stat,
uint64 *value)
{
return _bcm_esw_cosq_gport_stat_get(unit, 0, gport, cosq, stat, value);
}
/*
* Function:
* bcm_esw_cosq_gport_stat_sync_get
* sw accumulated counters synced with hw count.
* Parameters:
* unit - (IN) Unit number
* gport - (IN) GPORT ID
* cosq - (IN) COS queue.
* stat - (IN) Statistic to be retrieved.
* value - (OUT) Returned statistic value.
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_gport_stat_sync_get(
int unit,
bcm_gport_t gport,
bcm_cos_queue_t cosq,
bcm_cosq_gport_stats_t stat,
uint64 *value)
{
return _bcm_esw_cosq_gport_stat_get(unit, 1, gport, cosq, stat, value);
}
/*
* Function:
* bcm_cosq_gport_stat_set
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_gport_stat_set(
int unit,
bcm_gport_t gport,
bcm_cos_queue_t cosq,
bcm_cosq_gport_stats_t stat,
uint64 value)
{
#ifdef BCM_KATANA_SUPPORT
if (soc_feature(unit, soc_feature_cosq_gport_stat_ability)) {
return bcm_kt_cosq_gport_stat_set(unit, gport, cosq,
stat, value);
}
#endif /* BCM_KATANA_SUPPORT */
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_control_set
* Purpose:
* Set specified feature configuration
*
* Parameters:
* unit - (IN) Unit number.
* port - (IN) GPORT ID.
* cosq - (IN) COS queue.
* type - (IN) feature
* arg - (IN) feature value
* Returns:
* BCM_E_XXX
* Notes:
*/
int
bcm_esw_cosq_control_set(int unit, bcm_gport_t gport, bcm_cos_queue_t cosq,
bcm_cosq_control_t type, int arg)
{
uint32 kbits_sec_min, kbits_sec_max, kbits_sec_burst;
uint32 kbits_burst, flags;
bcm_pbmp_t pbmp;
bcm_port_t port;
bcm_cos_queue_t start_cos, end_cos, loc_cos;
uint32 cm_val, ocm_val, cmc1_val, ocmc1_val;
uint64 cmc_val64, ocmc_val64, mask64;
int num_cos = NUM_COS(unit);
uint32 kbits_burst_min, kbits_burst_max;
#if defined(BCM_HURRICANE2_SUPPORT)
soc_reg_t select_reg[8] = { \
EEE_PROFILE_SEL_0r, EEE_PROFILE_SEL_1r, \
EEE_PROFILE_SEL_2r, EEE_PROFILE_SEL_3r, \
EEE_PROFILE_SEL_4r, EEE_PROFILE_SEL_5r, \
EEE_PROFILE_SEL_6r, EEE_PROFILE_SEL_7r};
#endif /* BCM_HURRICANE2_SUPPORT */
kbits_burst_min = 0;
kbits_burst_max = 0;
COMPILER_REFERENCE(kbits_burst_min);
COMPILER_REFERENCE(kbits_burst_max);
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return bcm_th3_cosq_control_set(unit, gport, cosq,
BCM_COSQ_BUFFER_ID_INVALID, type, arg);
}
#endif /* BCM_TOMAHAWK3_SUPPORT */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
return bcm_th_cosq_control_set(unit, gport, cosq,
BCM_COSQ_BUFFER_ID_INVALID, type, arg);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
return (bcm_hx5_cosq_control_set(unit, gport, cosq, type, arg));
}
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
return (bcm_td3_cosq_control_set(unit, gport, cosq, type, arg));
}
#endif /* BCM_TRIDENT3_SUPPORT */
switch (type) {
case bcmCosqControlBandwidthBurstMax:
kbits_burst = arg & 0x7fffffff; /* Convert to uint32 */
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
BCM_IF_ERROR_RETURN
(bcm_mn_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
&kbits_burst_min,
&kbits_burst_max));
return bcm_mn_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
kbits_burst_min,
kbits_burst);
}
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
BCM_IF_ERROR_RETURN
(bcm_ap_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
&kbits_burst_min,
&kbits_burst_max));
return bcm_ap_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
kbits_burst_min,
kbits_burst);
}
#endif /* BCM_APACHE_SUPPORT */
#ifdef BCM_TRIUMPH2_SUPPORT
if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) ||
SOC_IS_VALKYRIE2(unit)) {
BCM_IF_ERROR_RETURN(
bcm_tr2_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
&kbits_burst_min, &kbits_burst_max));
return bcm_tr2_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
kbits_burst_min, kbits_burst);
}
#endif
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
BCM_IF_ERROR_RETURN(
bcm_tr3_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
&kbits_burst_min, &kbits_burst_max));
return bcm_tr3_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
kbits_burst_min, kbits_burst);
}
#endif /* BCM_TRIUMPH3_SUPPORT */
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
BCM_IF_ERROR_RETURN(
bcm_td2_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
&kbits_burst_min, &kbits_burst_max));
return bcm_td2_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
kbits_burst_min, kbits_burst);
}
#endif /* BCM_TRIDENT2_SUPPORT */
#ifdef BCM_TRIDENT_SUPPORT
if (SOC_IS_TD_TT(unit)) {
BCM_IF_ERROR_RETURN(
bcm_td_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
&kbits_burst_min, &kbits_burst_max));
return bcm_td_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
kbits_burst_min, kbits_burst);
}
#endif /* BCM_TRIDENT_SUPPORT */
#ifdef BCM_KATANA_SUPPORT
if (SOC_IS_KATANA(unit)) {
BCM_IF_ERROR_RETURN
(bcm_kt_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
&kbits_burst_min,
&kbits_burst_max));
return bcm_kt_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
kbits_burst_min,
kbits_burst);
}
#endif /* BCM_KATANA_SUPPORT */
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
BCM_IF_ERROR_RETURN
(bcm_kt2_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
&kbits_burst_min,
&kbits_burst_max));
return bcm_kt2_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
kbits_burst_min,
kbits_burst);
}
#endif /* BCM_KATANA2_SUPPORT */
#ifdef BCM_TRIUMPH_SUPPORT
if (SOC_IS_TR_VL(unit)) {
#if defined(BCM_HURRICANE_SUPPORT)
if(SOC_IS_HURRICANEX(unit) || SOC_IS_GREYHOUND(unit)) {
return bcm_hu_cosq_gport_bandwidth_burst_set(unit, gport,
cosq, kbits_burst);
} else
#endif /* BCM_HURRICANE_SUPPORT*/
#if defined(BCM_GREYHOUND2_SUPPORT)
if (SOC_IS_GREYHOUND2(unit)) {
return bcmi_gh2_cosq_gport_bandwidth_burst_set(unit, gport,
cosq,
kbits_burst);
} else
#endif /* BCM_GREYHOUND2_SUPPORT */
{
BCM_IF_ERROR_RETURN(
bcm_tr_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
&kbits_burst_min, &kbits_burst_max));
return bcm_tr_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
kbits_burst_min , kbits_burst);
}
}
#endif
if (gport < 0) {
BCM_PBMP_ASSIGN(pbmp, PBMP_ALL(unit));
} else {
/* Must use local ports on legacy devices */
BCM_IF_ERROR_RETURN
(bcm_esw_port_local_get(unit, gport, &port));
if (SOC_PORT_VALID(unit, port)) {
BCM_PBMP_PORT_SET(pbmp, port);
} else {
return BCM_E_PORT;
}
}
if (cosq < 0) {
start_cos = 0;
end_cos = NUM_COS(unit) - 1;
} else {
if (cosq < NUM_COS(unit)) {
start_cos = end_cos = cosq;
} else {
return BCM_E_PARAM;
}
}
BCM_PBMP_ITER(pbmp, port) {
for (loc_cos = start_cos; loc_cos <= end_cos; loc_cos++) {
BCM_IF_ERROR_RETURN
(mbcm_driver[unit]->
mbcm_cosq_port_bandwidth_get(unit, port, loc_cos,
&kbits_sec_min,
&kbits_sec_max,
&kbits_sec_burst, &flags));
BCM_IF_ERROR_RETURN
(mbcm_driver[unit]->
mbcm_cosq_port_bandwidth_set(unit, port, loc_cos,
kbits_sec_min,
kbits_sec_max,
kbits_burst, flags));
}
}
return BCM_E_NONE;
case bcmCosqControlBandwidthBurstMin:
kbits_burst = arg & 0x7fffffff; /* Convert to uint32 */
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
BCM_IF_ERROR_RETURN
(bcm_mn_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
&kbits_burst_min,
&kbits_burst_max));
return bcm_mn_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
kbits_burst,
kbits_burst_max);
}
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
BCM_IF_ERROR_RETURN
(bcm_ap_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
&kbits_burst_min,
&kbits_burst_max));
return bcm_ap_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
kbits_burst,
kbits_burst_max);
} else
#endif /* BCM_APACHE_SUPPORT */
#ifdef BCM_KATANA_SUPPORT
if (SOC_IS_KATANA(unit)) {
BCM_IF_ERROR_RETURN
(bcm_kt_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
&kbits_burst_min,
&kbits_burst_max));
return bcm_kt_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
kbits_burst,
kbits_burst_max);
} else
#endif /* BCM_KATANA_SUPPORT */
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
BCM_IF_ERROR_RETURN
(bcm_kt2_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
&kbits_burst_min,
&kbits_burst_max));
return bcm_kt2_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
kbits_burst,
kbits_burst_max);
} else
#endif /* BCM_KATANA2_SUPPORT */
#ifdef BCM_TRIUMPH2_SUPPORT
if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) ||
SOC_IS_VALKYRIE2(unit)) {
BCM_IF_ERROR_RETURN(
bcm_tr2_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
&kbits_burst_min, &kbits_burst_max));
return bcm_tr2_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
kbits_burst, kbits_burst_max);
} else
#endif
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
BCM_IF_ERROR_RETURN(
bcm_tr3_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
&kbits_burst_min, &kbits_burst_max));
return bcm_tr3_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
kbits_burst, kbits_burst_max);
} else
#endif /* BCM_TRIUMPH3_SUPPORT */
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
BCM_IF_ERROR_RETURN(
bcm_td2_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
&kbits_burst_min, &kbits_burst_max));
return bcm_td2_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
kbits_burst, kbits_burst_max);
} else
#endif /* BCM_TRIDENT2_SUPPORT */
#ifdef BCM_TRIDENT_SUPPORT
if (SOC_IS_TD_TT(unit)) {
BCM_IF_ERROR_RETURN(
bcm_td_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
&kbits_burst_min, &kbits_burst_max));
return bcm_td_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
kbits_burst, kbits_burst_max);
} else
#endif /* BCM_TRIDENT_SUPPORT */
#ifdef BCM_TRIUMPH_SUPPORT
if (SOC_IS_TR_VL(unit)) {
#if defined(BCM_HURRICANE_SUPPORT)
/* coverity[dead_error_begin : FALSE] */
if(SOC_IS_HURRICANEX(unit) || SOC_IS_GREYHOUND(unit) ||
SOC_IS_GREYHOUND2(unit)) {
/*need to support later*/
return BCM_E_UNAVAIL;
} else
#endif /* BCM_HURRICANE_SUPPORT*/
{
BCM_IF_ERROR_RETURN(
bcm_tr_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
&kbits_burst_min, &kbits_burst_max));
return bcm_tr_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
kbits_burst, kbits_burst_max);
}
} else
#endif /* BCM_TRIUMPH_SUPPORT */
return BCM_E_UNAVAIL;
case bcmCosqControlSchedulable:
if (!soc_reg_field_valid(unit, COSMASKr, COSMASKf)) {
return BCM_E_UNAVAIL;
}
if (gport < 0) {
BCM_PBMP_ASSIGN(pbmp, PBMP_ALL(unit));
} else {
/* Must use local ports on legacy devices */
BCM_IF_ERROR_RETURN
(bcm_esw_port_local_get(unit, gport, &port));
if (SOC_PORT_VALID(unit, port)) {
BCM_PBMP_PORT_SET(pbmp, port);
} else {
return BCM_E_PORT;
}
}
if (BCM_PBMP_MEMBER(pbmp, CMIC_PORT(unit))) {
if (soc_reg_field_valid(unit, COSMASK_CPU1r, COSMASKf)) {
if (cosq < 0) {
start_cos = 0;
end_cos = 31;
} else {
if (cosq < 32) {
start_cos = end_cos = cosq;
} else {
return BCM_E_PARAM;
}
}
port = CMIC_PORT(unit);
BCM_IF_ERROR_RETURN(READ_COSMASKr(unit, port, &cm_val));
BCM_IF_ERROR_RETURN
(READ_COSMASK_CPU1r(unit, &cmc1_val));
ocm_val = cm_val;
ocmc1_val = cmc1_val;
for (loc_cos = start_cos; loc_cos <= end_cos; loc_cos++) {
if (loc_cos < 10) {
if (arg) {
cm_val &= ~(1 << loc_cos);
} else {
cm_val |= (1 << loc_cos);
}
} else {
if (arg) {
cmc1_val &= ~(1 << loc_cos);
} else {
cmc1_val |= (1 << loc_cos);
}
}
}
if (ocm_val != cm_val) {
BCM_IF_ERROR_RETURN(WRITE_COSMASKr(unit, port, cm_val));
}
if (ocmc1_val != cmc1_val) {
BCM_IF_ERROR_RETURN
(WRITE_COSMASK_CPU1r(unit, cmc1_val));
}
BCM_PBMP_PORT_REMOVE(pbmp, CMIC_PORT(unit));
} else if (soc_reg_field_valid(unit, COSMASK_CPUr, COSMASKf)) {
if (cosq < 0) {
start_cos = 0;
end_cos = 47;
} else {
if (cosq < 48) {
start_cos = end_cos = cosq;
} else {
return BCM_E_PARAM;
}
}
BCM_IF_ERROR_RETURN
(READ_COSMASK_CPUr(unit, &cmc_val64));
ocmc_val64 = cmc_val64;
for (loc_cos = start_cos; loc_cos <= end_cos; loc_cos++) {
COMPILER_64_MASK_CREATE(mask64, 1, loc_cos);
if (arg) {
COMPILER_64_NOT(mask64);
COMPILER_64_AND(cmc_val64, mask64);
} else {
COMPILER_64_OR(cmc_val64, mask64);
}
}
if (COMPILER_64_NE(ocmc_val64, cmc_val64)) {
BCM_IF_ERROR_RETURN
(WRITE_COSMASK_CPUr(unit, cmc_val64));
}
BCM_PBMP_PORT_REMOVE(pbmp, CMIC_PORT(unit));
} else {
/* Handle below */
num_cos = 10; /* CMIC has more COS queues */
}
}
if (BCM_PBMP_IS_NULL(pbmp)) {
/* Done */
return BCM_E_NONE;
}
if (cosq < 0) {
start_cos = 0;
end_cos = num_cos - 1;
} else {
if (cosq < num_cos) {
start_cos = end_cos = cosq;
} else {
return BCM_E_PARAM;
}
}
BCM_PBMP_ITER(pbmp, port) {
BCM_IF_ERROR_RETURN(READ_COSMASKr(unit, port, &cm_val));
ocm_val = cm_val;
for (loc_cos = start_cos; loc_cos <= end_cos; loc_cos++) {
if (arg) {
/*
* COVERITY
*
* Max left shift of only 10.
* This code is intentional.
*/
/* coverity[large_shift] */
cm_val &= ~(1 << loc_cos);
} else {
/*
* COVERITY
*
* Max left shift of only 10.
* This code is intentional.
*/
/* coverity[large_shift] */
cm_val |= (1 << loc_cos);
}
}
if (ocm_val != cm_val) {
BCM_IF_ERROR_RETURN(WRITE_COSMASKr(unit, port, cm_val));
}
}
return BCM_E_NONE;
case bcmCosqControlCongestionManagedQueue:
if (soc_feature(unit, soc_feature_qcn)) {
#if defined(BCM_APACHE_SUPPORT)
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_congestion_queue_set(unit, gport, cosq, arg);
}
#endif
#if defined(BCM_TRIDENT2_SUPPORT)
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_congestion_queue_set(unit, gport, cosq, arg);
}
#endif
#if defined(BCM_TRIDENT_SUPPORT)
if (SOC_IS_TD_TT(unit)) {
return bcm_td_cosq_congestion_queue_set(unit, gport, cosq, arg);
}
#endif
#if defined(BCM_TRIUMPH3_SUPPORT)
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_congestion_queue_set(unit, gport, cosq, arg);
}
#endif
}
break;
case bcmCosqControlCongestionFeedbackWeight:
if (soc_feature(unit, soc_feature_qcn)) {
#if defined(BCM_APACHE_SUPPORT)
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_congestion_quantize_set(unit, gport, cosq, arg,
-1);
}
#endif
#if defined(BCM_TRIDENT2_SUPPORT)
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_congestion_quantize_set(unit, gport, cosq, arg,
-1);
}
#endif
#if defined(BCM_TRIDENT_SUPPORT)
if (SOC_IS_TD_TT(unit)) {
return bcm_td_cosq_congestion_quantize_set(unit, gport, cosq, arg,
-1);
}
#endif
#if defined(BCM_TRIUMPH3_SUPPORT)
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_congestion_quantize_set(unit, gport,
cosq, arg, -1);
}
#endif
}
break;
case bcmCosqControlCongestionSetPoint:
if (soc_feature(unit, soc_feature_qcn)) {
#if defined(BCM_APACHE_SUPPORT)
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_congestion_quantize_set(unit, gport, cosq, -1,
arg);
}
#endif
#if defined(BCM_TRIDENT2_SUPPORT)
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_congestion_quantize_set(unit, gport, cosq, -1,
arg);
}
#endif
#if defined(BCM_TRIDENT_SUPPORT)
if (SOC_IS_TD_TT(unit)) {
return bcm_td_cosq_congestion_quantize_set(unit, gport, cosq, -1,
arg);
}
#endif
#if defined(BCM_TRIUMPH3_SUPPORT)
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_congestion_quantize_set(unit, gport, cosq, -1,
arg);
}
#endif
}
break;
case bcmCosqControlCongestionSampleBytesMin:
if (soc_feature(unit, soc_feature_qcn)) {
#if defined(BCM_APACHE_SUPPORT)
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_congestion_sample_int_set(unit, gport, cosq,
arg, -1);
}
#endif
#if defined(BCM_TRIDENT2_SUPPORT)
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_congestion_sample_int_set(unit, gport, cosq,
arg, -1);
}
#endif
#if defined(BCM_TRIDENT_SUPPORT)
if (SOC_IS_TD_TT(unit)) {
return bcm_td_cosq_congestion_sample_int_set(unit, gport, cosq,
arg, -1);
}
#endif
#if defined(BCM_TRIUMPH3_SUPPORT)
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_congestion_sample_int_set(unit, gport, cosq,
arg, -1);
}
#endif
}
break;
case bcmCosqControlCongestionSampleBytesMax:
if (soc_feature(unit, soc_feature_qcn)) {
#if defined(BCM_APACHE_SUPPORT)
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_congestion_sample_int_set(unit, gport, cosq,
-1, arg);
}
#endif
#if defined(BCM_TRIDENT2_SUPPORT)
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_congestion_sample_int_set(unit, gport, cosq,
-1, arg);
}
#endif
#if defined(BCM_TRIDENT_SUPPORT)
if (SOC_IS_TD_TT(unit)) {
return bcm_td_cosq_congestion_sample_int_set(unit, gport, cosq,
-1, arg);
}
#endif
#if defined(BCM_TRIUMPH3_SUPPORT)
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_congestion_sample_int_set(unit, gport, cosq,
-1, arg);
}
#endif
}
break;
case bcmCosqControlCongestionProxy:
if (!SOC_REG_IS_VALID(unit, QCN_CNM_PRP_CTRLr)) {
return BCM_E_UNAVAIL;
}
#if defined(BCM_TRIDENT2_SUPPORT)
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_control_set(unit, gport, cosq, type, arg);
}
#endif
#if defined(BCM_TRIUMPH3_SUPPORT)
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_control_set(unit, gport, cosq, type, arg);
}
#endif
break;
case bcmCosqControlEgressPool:
case bcmCosqControlEgressPoolLimitBytes:
case bcmCosqControlEgressPoolYellowLimitBytes:
case bcmCosqControlEgressPoolRedLimitBytes:
case bcmCosqControlEgressPoolLimitEnable:
case bcmCosqControlEgressUCQueueMinLimitBytes:
case bcmCosqControlEgressUCQueueSharedLimitBytes:
case bcmCosqControlEgressUCQueueLimitEnable:
case bcmCosqControlEgressUCQueueColorLimitEnable:
case bcmCosqControlEgressUCSharedDynamicEnable:
case bcmCosqControlEgressMCQueueSharedLimitBytes:
case bcmCosqControlEgressMCQueueMinLimitBytes:
case bcmCosqControlEgressMCSharedDynamicEnable:
case bcmCosqControlEgressMCQueueLimitEnable:
case bcmCosqControlEgressMCQueueColorLimitEnable:
case bcmCosqControlIngressPortPGSharedLimitBytes:
case bcmCosqControlIngressPortPoolMaxLimitBytes:
case bcmCosqControlIngressPortPGSharedDynamicEnable:
case bcmCosqControlIngressPortPoolMinLimitBytes:
case bcmCosqControlDropLimitAlpha:
case bcmCosqControlUCDropLimitAlpha:
case bcmCosqControlMCDropLimitAlpha:
case bcmCosqControlIngressPool:
case bcmCosqControlEgressPortPoolYellowLimitBytes:
case bcmCosqControlEgressPortPoolRedLimitBytes:
case bcmCosqControlUCEgressPool:
case bcmCosqControlMCEgressPool:
case bcmCosqControlIngressPoolLimitBytes:
case bcmCosqControlIngressPortPGHeadroomLimitBytes:
case bcmCosqControlIngressPortPGResetFloorBytes:
case bcmCosqControlEgressPoolSharedLimitBytes:
case bcmCosqControlEgressPoolResumeLimitBytes:
case bcmCosqControlEgressPoolYellowSharedLimitBytes:
case bcmCosqControlEgressPoolYellowResumeLimitBytes:
case bcmCosqControlEgressPoolRedSharedLimitBytes:
case bcmCosqControlEgressPoolRedResumeLimitBytes:
case bcmCosqControlEgressUCQueueGroupMinEnable:
case bcmCosqControlEgressUCQueueGroupSharedLimitEnable:
case bcmCosqControlEgressUCQueueGroupMinLimitBytes:
case bcmCosqControlEgressUCQueueGroupSharedLimitBytes:
case bcmCosqControlEgressUCQueueGroupSharedDynamicEnable:
case bcmCosqControlEgressUCQueueGroupDropLimitAlpha:
case bcmCosqControlObmDiscardLimit:
case bcmCosqControlObmMinLimit:
case bcmCosqControlEgressUCQueueColorLimitDynamicEnable:
case bcmCosqControlEgressMCQueueColorLimitDynamicEnable:
case bcmCosqControlEgressUCQueueRedLimit:
case bcmCosqControlEgressUCQueueYellowLimit:
case bcmCosqControlEgressMCQueueRedLimit:
case bcmCosqControlEgressMCQueueYellowLimit:
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
return bcm_mn_cosq_control_set(unit, gport, cosq, type, arg);
}
#endif /* BCM_MONTEREY_SUPPORT */
#if defined(BCM_APACHE_SUPPORT)
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_control_set(unit, gport, cosq, type, arg);
}
#endif
#if defined(BCM_TRIDENT2_SUPPORT)
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_control_set(unit, gport, cosq, type, arg);
}
#endif
#if defined(BCM_TRIDENT_SUPPORT)
if (SOC_IS_TD_TT(unit)) {
return bcm_td_cosq_control_set(unit, gport, cosq, type, arg);
}
#endif
#if defined(BCM_TRIUMPH3_SUPPORT)
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_control_set(unit, gport, cosq, type, arg);
}
#endif
#if defined(BCM_KATANA2_SUPPORT)
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_control_set(unit, gport, cosq, type, arg);
}
#endif /* BCM_KATANA2_SUPPORT */
break;
case bcmCosqControlIngressPortPGMinLimitBytes:
#if defined(BCM_KATANA2_SUPPORT)
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_control_set(unit, gport, cosq, type, arg);
}
#endif /* BCM_KATANA2_SUPPORT */
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
return bcm_mn_cosq_control_set(unit, gport, cosq, type, arg);
}
#endif /* BCM_MONTEREY_SUPPORT */
#if defined(BCM_APACHE_SUPPORT)
if (SOC_IS_APACHE(unit)){
return bcm_ap_cosq_control_set(unit, gport, cosq, type, arg);
}
#endif /*BCM_APACHE_SUPPORT*/
#if defined(BCM_TRIDENT2_SUPPORT)
if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TITAN2X(unit)) {
return bcm_td2_cosq_control_set(unit, gport, cosq, type, arg);
}
#endif /* BCM_TRIDENT2_SUPPORT */
#if defined(BCM_TRIUMPH3_SUPPORT)
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_control_set(unit, gport, cosq, type, arg);
}
#endif
break;
case bcmCosqControlEfPropagation:
#if defined(BCM_TRIDENT2_SUPPORT)
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_control_set(unit, gport, cosq, type, arg);
}
#endif
#if defined(BCM_TRIUMPH3_SUPPORT)
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_control_set(unit, gport, cosq, type, arg);
}
#endif
#if defined(BCM_KATANA_SUPPORT)
if (SOC_IS_KATANA(unit)) {
return bcm_kt_cosq_control_set(unit, gport, cosq, type, arg);
}
#endif /* BCM_KATANA_SUPPORT */
#if defined(BCM_KATANA2_SUPPORT)
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_control_set(unit, gport, cosq, type, arg);
}
#endif /* BCM_KATANA2_SUPPORT */
break;
case bcmCosqControlRedirectQueueSharedLimitBytes:
case bcmCosqControlRedirectQueueMinLimitBytes:
case bcmCosqControlRedirectSharedDynamicEnable:
case bcmCosqControlRedirectQueueLimitEnable:
case bcmCosqControlRedirectColorDynamicEnable:
case bcmCosqControlRedirectColorEnable:
#if defined(BCM_KATANA2_SUPPORT)
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_control_set(unit, gport, cosq, type, arg);
}
#endif /* BCM_KATANA2_SUPPORT */
break;
case bcmCosqControlEEEQueueThresholdProfileSelect:
if (soc_feature(unit, soc_feature_eee_bb_mode)) {
int num_cosq;
#if defined(BCM_GREYHOUND2_SUPPORT)
if (SOC_IS_GREYHOUND2(unit)) {
return bcmi_gh2_cosq_control_set(unit, gport, cosq, type, arg);
}
#endif /* BCM_GREYHOUND2_SUPPORT */
if (soc_feature(unit, soc_feature_wh2)) {
/* Get the configured max cosq number */
BCM_IF_ERROR_RETURN(bcm_esw_cosq_config_get(unit, &num_cosq));
} else {
num_cosq = NUM_COS(unit);
}
if ((cosq < 0) || (cosq >= num_cosq)) {
return BCM_E_PARAM;
}
BCM_IF_ERROR_RETURN
(bcm_esw_port_local_get(unit, gport, &port));
if (!SOC_PORT_VALID(unit, port)) {
return BCM_E_PORT;
}
#if defined(BCM_HURRICANE2_SUPPORT)
if (SOC_IS_HURRICANE2(unit)||SOC_IS_GREYHOUND(unit)||
SOC_IS_HURRICANE3(unit)) {
BCM_IF_ERROR_RETURN(
soc_reg_field32_modify(unit, select_reg[cosq], port,
EEE_THRESH_SELf, arg));
return BCM_E_NONE;
}
#endif /* BCM_HURRICANE2_SUPPORT */
}
break;
case bcmCosqControlEEEPacketLatencyProfileSelect:
if (soc_feature(unit, soc_feature_eee_bb_mode)) {
int num_cosq;
#if defined(BCM_GREYHOUND2_SUPPORT)
if (SOC_IS_GREYHOUND2(unit)) {
return bcmi_gh2_cosq_control_set(unit, gport, cosq, type, arg);
}
#endif /* BCM_GREYHOUND2_SUPPORT */
if (soc_feature(unit, soc_feature_wh2)) {
/* Get the configured max cosq number */
BCM_IF_ERROR_RETURN(bcm_esw_cosq_config_get(unit, &num_cosq));
} else {
num_cosq = NUM_COS(unit);
}
if ((cosq < 0) || (cosq >= num_cosq)) {
return BCM_E_PARAM;
}
BCM_IF_ERROR_RETURN
(bcm_esw_port_local_get(unit, gport, &port));
if (!SOC_PORT_VALID(unit, port)) {
return BCM_E_PORT;
}
#if defined(BCM_HURRICANE2_SUPPORT)
if (SOC_IS_HURRICANE2(unit)||SOC_IS_GREYHOUND(unit)||
SOC_IS_HURRICANE3(unit)) {
BCM_IF_ERROR_RETURN(
soc_reg_field32_modify(unit, select_reg[cosq], port,
EEE_LATENCY_SELf, arg));
return BCM_E_NONE;
}
#endif /* BCM_HURRICANE2_SUPPORT */
}
break;
case bcmCosqControlPFCBackpressureEnable:
if (soc_feature(unit, soc_feature_priority_flow_control)) {
#if defined(BCM_GREYHOUND_SUPPORT)
if (soc_feature(unit, soc_feature_gh_style_pfc_config)) {
return bcm_gh_cosq_control_set(unit, gport, cosq, type, arg);
}
#endif /* BCM_GREYHOUND_SUPPORT */
}
break;
case bcmCosqControlE2ECCTransmitEnable:
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_gport_e2ecc_transmit_set(unit, gport, cosq,
type, arg);
}
#endif /* BCM_KATANA2_SUPPORT */
break;
case bcmCosqControlAlternateStoreForward:
if (soc_feature(unit, soc_feature_asf)) {
#if defined(BCM_GREYHOUND2_SUPPORT)
if (SOC_IS_GREYHOUND2(unit)) {
return bcmi_gh2_cosq_control_set(unit, gport, cosq, type, arg);
}
#endif /* BCM_GREYHOUND2_SUPPORT */
}
break;
default:
break;
}
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_control_get
* Purpose:
* Get specified feature configuration
*
* Parameters:
* unit - (IN) Unit number.
* port - (IN) GPORT ID.
* cosq - (IN) COS queue.
* type - (IN) feature
* arg - (OUT) feature value
* Returns:
* BCM_E_XXX
* Notes:
*/
int
bcm_esw_cosq_control_get(int unit, bcm_gport_t gport, bcm_cos_queue_t cosq,
bcm_cosq_control_t type, int *arg)
{
uint32 kbits_sec_min, kbits_sec_max, kbits_burst, flags;
bcm_port_t port;
bcm_cos_queue_t loc_cos;
uint32 cm_val, cmc1_val;
uint64 cmc_val64;
#if defined(BCM_HURRICANE2_SUPPORT)
soc_reg_t select_reg[8] = { \
EEE_PROFILE_SEL_0r, EEE_PROFILE_SEL_1r, \
EEE_PROFILE_SEL_2r, EEE_PROFILE_SEL_3r, \
EEE_PROFILE_SEL_4r, EEE_PROFILE_SEL_5r, \
EEE_PROFILE_SEL_6r, EEE_PROFILE_SEL_7r};
#endif /* BCM_HURRICANE2_SUPPORT */
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return bcm_th3_cosq_control_get(unit, gport, cosq,
BCM_COSQ_BUFFER_ID_INVALID, type, arg);
}
#endif /* BCM_TOMAHAWK3_SUPPORT */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
return bcm_th_cosq_control_get(unit, gport, cosq,
BCM_COSQ_BUFFER_ID_INVALID, type, arg);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
return (bcm_hx5_cosq_control_get(unit, gport, cosq, type, arg));
}
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
return (bcm_td3_cosq_control_get(unit, gport, cosq, type, arg));
}
#endif /* BCM_TRIDENT3_SUPPORT */
switch (type) {
case bcmCosqControlBandwidthBurstMax:
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
uint32 kburst_tmp;
BCM_IF_ERROR_RETURN
(bcm_mn_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
&kburst_tmp, &kbits_burst));
} else
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
uint32 kburst_tmp;
BCM_IF_ERROR_RETURN
(bcm_ap_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
&kburst_tmp, &kbits_burst));
} else
#endif /* BCM_APACHE_SUPPORT */
#ifdef BCM_TRIUMPH2_SUPPORT
if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) ||
SOC_IS_VALKYRIE2(unit)) {
uint32 kburst_tmp;
BCM_IF_ERROR_RETURN
(bcm_tr2_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
&kburst_tmp, &kbits_burst));
} else
#endif
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
uint32 kburst_tmp;
BCM_IF_ERROR_RETURN
(bcm_td2_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
&kburst_tmp, &kbits_burst));
} else
#endif /* BCM_TRIDENT2_SUPPORT */
#ifdef BCM_TRIDENT_SUPPORT
if (SOC_IS_TD_TT(unit)) {
uint32 kburst_tmp;
BCM_IF_ERROR_RETURN
(bcm_td_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
&kburst_tmp, &kbits_burst));
} else
#endif /* BCM_TRIDENT_SUPPORT */
#ifdef BCM_KATANA_SUPPORT
if (SOC_IS_KATANA(unit)) {
uint32 kburst_tmp;
BCM_IF_ERROR_RETURN
(bcm_kt_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
&kburst_tmp, &kbits_burst));
} else
#endif /* BCM_KATANA_SUPPORT */
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
uint32 kburst_tmp;
BCM_IF_ERROR_RETURN
(bcm_kt2_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
&kburst_tmp, &kbits_burst));
} else
#endif /* BCM_KATANA2_SUPPORT */
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
uint32 kburst_tmp;
BCM_IF_ERROR_RETURN
(bcm_tr3_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
&kburst_tmp, &kbits_burst));
} else
#endif /* BCM_TRIUMPH3_SUPPORT */
#ifdef BCM_TRIUMPH_SUPPORT
if (SOC_IS_TR_VL(unit)) {
uint32 kburst_tmp;
#if defined(BCM_HURRICANE_SUPPORT)
if(SOC_IS_HURRICANEX(unit) || SOC_IS_GREYHOUND(unit)) {
BCM_IF_ERROR_RETURN
(bcm_hu_cosq_gport_bandwidth_burst_get(unit, gport,
cosq, &kbits_burst));
} else
#endif /* BCM_HURRICANE_SUPPORT*/
#if defined(BCM_GREYHOUND2_SUPPORT)
if (SOC_IS_GREYHOUND2(unit)) {
BCM_IF_ERROR_RETURN
(bcmi_gh2_cosq_gport_bandwidth_burst_get(unit, gport,
cosq,
&kbits_burst));
} else
#endif /* BCM_GREYHOUND2_SUPPORT */
{
BCM_IF_ERROR_RETURN
(bcm_tr_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
&kburst_tmp, &kbits_burst));
}
} else /*SOC_IS_TR_VL*/
#endif
{
if (gport < 0) {
port = SOC_PORT_MIN(unit,all);
} else {
/* Must use local ports on legacy devices */
BCM_IF_ERROR_RETURN
(bcm_esw_port_local_get(unit, gport, &port));
if (!SOC_PORT_VALID(unit, port)) {
return BCM_E_PORT;
}
}
if (cosq < 0) {
loc_cos = 0;
} else {
if (cosq < NUM_COS(unit)) {
loc_cos = cosq;
} else {
return BCM_E_PARAM;
}
}
BCM_IF_ERROR_RETURN
(mbcm_driver[unit]->
mbcm_cosq_port_bandwidth_get(unit, port, loc_cos,
&kbits_sec_min, &kbits_sec_max,
&kbits_burst, &flags));
}
*arg = kbits_burst & 0x7fffffff; /* Convert to int */
return BCM_E_NONE;
case bcmCosqControlBandwidthBurstMin:
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
uint32 kburst_tmp;
return bcm_mn_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
(uint32*)arg, &kburst_tmp);
} else
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
uint32 kburst_tmp;
return bcm_ap_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
(uint32*)arg, &kburst_tmp);
} else
#endif /* BCM_APACHE_SUPPORT */
#ifdef BCM_TRIUMPH2_SUPPORT
if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) ||
SOC_IS_VALKYRIE2(unit)) {
uint32 kburst_tmp;
BCM_IF_ERROR_RETURN
(bcm_tr2_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
(uint32*)arg, &kburst_tmp));
} else
#endif
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
uint32 kburst_tmp;
return bcm_td2_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
(uint32*)arg, &kburst_tmp);
} else
#endif /* BCM_TRIDENT2_SUPPORT */
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
uint32 kburst_tmp;
return bcm_tr3_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
(uint32*)arg, &kburst_tmp);
} else
#endif /* BCM_TRIUMPH3_SUPPORT */
#if defined(BCM_TRIDENT_SUPPORT)
if (SOC_IS_TD_TT(unit)) {
uint32 kburst_tmp;
return bcm_td_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
(uint32*)arg, &kburst_tmp);
} else
#endif
#ifdef BCM_KATANA_SUPPORT
if (SOC_IS_KATANA(unit)) {
uint32 kburst_tmp;
return bcm_kt_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
(uint32*)arg, &kburst_tmp);
} else
#endif /* BCM_KATANA_SUPPORT */
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
uint32 kburst_tmp;
return bcm_kt2_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
(uint32*)arg, &kburst_tmp);
} else
#endif /* BCM_KATANA2_SUPPORT */
#ifdef BCM_TRIUMPH_SUPPORT
if (SOC_IS_TR_VL(unit)) {
uint32 kburst_tmp;
#if defined(BCM_HURRICANE_SUPPORT)
/* coverity[dead_error_begin : FALSE] */
if(SOC_IS_HURRICANEX(unit) || SOC_IS_GREYHOUND(unit)) {
/*need to support later*/
} else
#endif /* BCM_HURRICANE_SUPPORT*/
{
BCM_IF_ERROR_RETURN
(bcm_tr_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
(uint32*)arg, &kburst_tmp));
}
} else /*BCM_TRIUMPH_SUPPORT*/
#endif
/* coverity[dead_error_begin : FALSE] */
{
/*do nothing*/
}
return BCM_E_UNAVAIL;
case bcmCosqControlSchedulable:
if (!soc_reg_field_valid(unit, COSMASKr, COSMASKf)) {
return BCM_E_UNAVAIL;
}
if (gport < 0) {
port = SOC_PORT_MIN(unit,all);
} else {
/* Must use local ports on legacy devices */
BCM_IF_ERROR_RETURN
(bcm_esw_port_local_get(unit, gport, &port));
if (!SOC_PORT_VALID(unit, port)) {
return BCM_E_PORT;
}
}
loc_cos = (cosq < 0) ? 0 : cosq;
if (port == CMIC_PORT(unit)) {
if (soc_reg_field_valid(unit, COSMASK_CPUr, COSMASKf)) {
if (loc_cos > 47) {
return BCM_E_PARAM;
}
BCM_IF_ERROR_RETURN
(READ_COSMASK_CPUr(unit, &cmc_val64));
*arg = COMPILER_64_BITTEST(cmc_val64, loc_cos) ?
FALSE : TRUE;
} else if (soc_reg_field_valid(unit, COSMASK_CPU1r, COSMASKf)) {
if (loc_cos < 10) {
BCM_IF_ERROR_RETURN(READ_COSMASKr(unit, port, &cm_val));
*arg = (cm_val & (1 << loc_cos)) ? FALSE : TRUE;
} else if (loc_cos < 32) {
BCM_IF_ERROR_RETURN(READ_COSMASK_CPU1r(unit, &cmc1_val));
*arg = (cmc1_val & (1 << loc_cos)) ? FALSE : TRUE;
} else {
return BCM_E_PARAM;
}
} else {
if (loc_cos < 10) {
BCM_IF_ERROR_RETURN(READ_COSMASKr(unit, port, &cm_val));
*arg = (cm_val & (1 << loc_cos)) ? FALSE : TRUE;
} else {
return BCM_E_PARAM;
}
}
} else {
if (cosq < NUM_COS(unit)) {
BCM_IF_ERROR_RETURN(READ_COSMASKr(unit, port, &cm_val));
*arg = (cm_val & (1 << loc_cos)) ? FALSE : TRUE;
} else {
return BCM_E_PARAM;
}
}
return BCM_E_NONE;
case bcmCosqControlCongestionManagedQueue:
if (soc_feature(unit, soc_feature_qcn)) {
#if defined(BCM_APACHE_SUPPORT)
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_congestion_queue_get(unit, gport, cosq, arg);
}
#endif
#if defined(BCM_TRIDENT2_SUPPORT)
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_congestion_queue_get(unit, gport, cosq, arg);
}
#endif
#if defined(BCM_TRIDENT_SUPPORT)
if (SOC_IS_TD_TT(unit)) {
return bcm_td_cosq_congestion_queue_get(unit, gport, cosq, arg);
}
#endif
#if defined(BCM_TRIUMPH3_SUPPORT)
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_congestion_queue_get(unit, gport, cosq, arg);
}
#endif
}
break;
case bcmCosqControlCongestionFeedbackWeight:
if (soc_feature(unit, soc_feature_qcn)) {
#if defined(BCM_APACHE_SUPPORT)
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_congestion_quantize_get(unit, gport,
cosq, arg, NULL);
}
#endif
#if defined(BCM_TRIDENT2_SUPPORT)
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_congestion_quantize_get(unit, gport,
cosq, arg, NULL);
}
#endif
#if defined(BCM_TRIDENT_SUPPORT)
if (SOC_IS_TD_TT(unit)) {
return bcm_td_cosq_congestion_quantize_get(unit, gport,
cosq, arg, NULL);
}
#endif
#if defined(BCM_TRIUMPH3_SUPPORT)
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_congestion_quantize_get(unit, gport,
cosq, arg, NULL);
}
#endif
}
break;
case bcmCosqControlCongestionSetPoint:
if (soc_feature(unit, soc_feature_qcn)) {
#if defined(BCM_APACHE_SUPPORT)
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_congestion_quantize_get(unit, gport,
cosq, NULL, arg);
}
#endif
#if defined(BCM_TRIDENT2_SUPPORT)
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_congestion_quantize_get(unit, gport,
cosq, NULL, arg);
}
#endif
#if defined(BCM_TRIDENT_SUPPORT)
if (SOC_IS_TD_TT(unit)) {
return bcm_td_cosq_congestion_quantize_get(unit, gport,
cosq, NULL, arg);
}
#endif
#if defined(BCM_TRIUMPH3_SUPPORT)
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_congestion_quantize_get(unit, gport,
cosq, NULL, arg);
}
#endif
}
break;
case bcmCosqControlCongestionSampleBytesMin:
if (soc_feature(unit, soc_feature_qcn)) {
#if defined(BCM_APACHE_SUPPORT)
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_congestion_sample_int_get(unit, gport, cosq,
arg, NULL);
}
#endif
#if defined(BCM_TRIDENT2_SUPPORT)
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_congestion_sample_int_get(unit, gport, cosq,
arg, NULL);
}
#endif
#if defined(BCM_TRIDENT_SUPPORT)
if (SOC_IS_TD_TT(unit)) {
return bcm_td_cosq_congestion_sample_int_get(unit, gport, cosq,
arg, NULL);
}
#endif
#if defined(BCM_TRIUMPH3_SUPPORT)
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_congestion_sample_int_get(unit, gport, cosq,
arg, NULL);
}
#endif
}
break;
case bcmCosqControlCongestionSampleBytesMax:
if (soc_feature(unit, soc_feature_qcn)) {
#if defined(BCM_APACHE_SUPPORT)
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_congestion_sample_int_get(unit, gport, cosq,
NULL, arg);
}
#endif
#if defined(BCM_TRIDENT2_SUPPORT)
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_congestion_sample_int_get(unit, gport, cosq,
NULL, arg);
}
#endif
#if defined(BCM_TRIDENT_SUPPORT)
if (SOC_IS_TD_TT(unit)) {
return bcm_td_cosq_congestion_sample_int_get(unit, gport, cosq,
NULL, arg);
}
#endif
#if defined(BCM_TRIUMPH3_SUPPORT)
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_congestion_sample_int_get(unit, gport, cosq,
NULL, arg);
}
#endif
}
break;
case bcmCosqControlEgressPool:
case bcmCosqControlEgressPoolLimitBytes:
case bcmCosqControlEgressPoolYellowLimitBytes:
case bcmCosqControlEgressPoolRedLimitBytes:
case bcmCosqControlEgressPoolLimitEnable:
case bcmCosqControlEgressUCQueueMinLimitBytes:
case bcmCosqControlEgressUCQueueSharedLimitBytes:
case bcmCosqControlEgressUCQueueLimitEnable:
case bcmCosqControlEgressUCQueueColorLimitEnable:
case bcmCosqControlEgressUCSharedDynamicEnable:
case bcmCosqControlEgressMCQueueSharedLimitBytes:
case bcmCosqControlEgressMCQueueMinLimitBytes:
case bcmCosqControlEgressMCSharedDynamicEnable:
case bcmCosqControlEgressMCQueueLimitEnable:
case bcmCosqControlEgressMCQueueColorLimitEnable:
case bcmCosqControlIngressPortPGSharedLimitBytes:
case bcmCosqControlIngressPortPoolMaxLimitBytes:
case bcmCosqControlIngressPortPGSharedDynamicEnable:
case bcmCosqControlIngressPortPoolMinLimitBytes:
case bcmCosqControlDropLimitAlpha:
case bcmCosqControlUCDropLimitAlpha:
case bcmCosqControlMCDropLimitAlpha:
case bcmCosqControlSPPortLimitState:
case bcmCosqControlPGPortLimitState:
case bcmCosqControlPGPortXoffState:
case bcmCosqControlPoolRedDropState:
case bcmCosqControlPoolYellowDropState:
case bcmCosqControlPoolGreenDropState:
case bcmCosqControlIngressPool:
case bcmCosqControlEgressPortPoolYellowLimitBytes:
case bcmCosqControlEgressPortPoolRedLimitBytes:
case bcmCosqControlUCEgressPool:
case bcmCosqControlMCEgressPool:
case bcmCosqControlIngressPoolLimitBytes:
case bcmCosqControlIngressPortPGHeadroomLimitBytes:
case bcmCosqControlIngressPortPGResetFloorBytes:
case bcmCosqControlEgressPoolSharedLimitBytes:
case bcmCosqControlEgressPoolResumeLimitBytes:
case bcmCosqControlEgressPoolYellowSharedLimitBytes:
case bcmCosqControlEgressPoolYellowResumeLimitBytes:
case bcmCosqControlEgressPoolRedSharedLimitBytes:
case bcmCosqControlEgressPoolRedResumeLimitBytes:
case bcmCosqControlEgressUCQueueGroupMinEnable:
case bcmCosqControlEgressUCQueueGroupSharedLimitEnable:
case bcmCosqControlEgressUCQueueGroupMinLimitBytes:
case bcmCosqControlEgressUCQueueGroupSharedLimitBytes:
case bcmCosqControlEgressUCQueueGroupSharedDynamicEnable:
case bcmCosqControlEgressUCQueueGroupDropLimitAlpha:
case bcmCosqControlObmDiscardLimit:
case bcmCosqControlObmMinLimit:
case bcmCosqControlEgressUCQueueColorLimitDynamicEnable:
case bcmCosqControlEgressMCQueueColorLimitDynamicEnable:
case bcmCosqControlEgressUCQueueRedLimit:
case bcmCosqControlEgressUCQueueYellowLimit:
case bcmCosqControlEgressMCQueueRedLimit:
case bcmCosqControlEgressMCQueueYellowLimit:
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
return bcm_mn_cosq_control_get(unit, gport, cosq, type, arg);
}
#endif /* BCM_MONTEREY_SUPPORT */
#if defined(BCM_APACHE_SUPPORT)
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_control_get(unit, gport, cosq, type, arg);
}
#endif
#if defined(BCM_TRIDENT2_SUPPORT)
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_control_get(unit, gport, cosq, type, arg);
}
#endif
if (SOC_IS_TD_TT(unit)) {
#if defined(BCM_TRIDENT_SUPPORT)
if (SOC_IS_TD_TT(unit)) {
return bcm_td_cosq_control_get(unit, gport, cosq, type, arg);
}
#endif
}
#if defined(BCM_TRIUMPH3_SUPPORT)
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_control_get(unit, gport, cosq, type, arg);
}
#endif
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_control_get(unit, gport, cosq, type, arg);
}
#endif /* BCM_KATANA2_SUPPORT */
break;
case bcmCosqControlCongestionProxy:
if (!SOC_REG_IS_VALID(unit, QCN_CNM_PRP_CTRLr)) {
return BCM_E_UNAVAIL;
}
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
return bcm_mn_cosq_control_get(unit, gport, cosq, type, arg);
}
#endif /* BCM_MONTEREY_SUPPORT */
#if defined(BCM_APACHE_SUPPORT)
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_control_get(unit, gport, cosq, type, arg);
}
#endif
#if defined(BCM_TRIDENT2_SUPPORT)
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_control_get(unit, gport, cosq, type, arg);
}
#endif
break;
case bcmCosqControlIngressPortPGMinLimitBytes:
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_control_get(unit, gport, cosq, type, arg);
}
#endif /* BCM_KATANA2_SUPPORT */
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
return bcm_mn_cosq_control_get(unit, gport, cosq, type, arg);
}
#endif /* BCM_MONTEREY_SUPPORT */
#if defined(BCM_APACHE_SUPPORT)
if (SOC_IS_APACHE(unit)){
return bcm_ap_cosq_control_get(unit, gport, cosq, type, arg);
}
#endif /* BCM_APACHE_SUPPORT*/
#if defined(BCM_TRIDENT2_SUPPORT)
if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TITAN2X(unit)) {
return bcm_td2_cosq_control_get(unit, gport, cosq, type, arg);
}
#endif /* BCM_TRIDENT2_SUPPORT */
#if defined(BCM_TRIUMPH3_SUPPORT)
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_control_get(unit, gport, cosq, type, arg);
}
#endif
break;
case bcmCosqControlEfPropagation:
#if defined(BCM_TRIDENT2_SUPPORT)
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_control_get(unit, gport, cosq, type, arg);
}
#endif
#ifdef BCM_KATANA_SUPPORT
if (SOC_IS_KATANA(unit)) {
return bcm_kt_cosq_control_get(unit, gport, cosq, type, arg);
}
#endif /* BCM_KATANA_SUPPORT */
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_control_get(unit, gport, cosq, type, arg);
}
#endif /* BCM_KATANA2_SUPPORT */
break;
case bcmCosqControlEEEQueueThresholdProfileSelect:
if (soc_feature(unit, soc_feature_eee_bb_mode)) {
int num_cosq;
#if defined(BCM_GREYHOUND2_SUPPORT)
if (SOC_IS_GREYHOUND2(unit)) {
return bcmi_gh2_cosq_control_get(unit, gport, cosq, type, arg);
}
#endif /* BCM_GREYHOUND2_SUPPORT */
if (soc_feature(unit, soc_feature_wh2)) {
/* Get the configured max cosq number */
BCM_IF_ERROR_RETURN(bcm_esw_cosq_config_get(unit, &num_cosq));
} else {
num_cosq = NUM_COS(unit);
}
if ((cosq < 0) || (cosq >= num_cosq)) {
return BCM_E_PARAM;
}
BCM_IF_ERROR_RETURN
(bcm_esw_port_local_get(unit, gport, &port));
if (!SOC_PORT_VALID(unit, port)) {
return BCM_E_PORT;
}
#if defined(BCM_HURRICANE2_SUPPORT)
if (SOC_IS_HURRICANE2(unit)||SOC_IS_GREYHOUND(unit)||
SOC_IS_HURRICANE3(unit)) {
uint32 rval = 0;
BCM_IF_ERROR_RETURN(
soc_reg32_get(unit, select_reg[cosq], port, 0, &rval));
*arg = soc_reg_field_get(unit, select_reg[cosq],
rval, EEE_THRESH_SELf);
return BCM_E_NONE;
}
#endif /* BCM_HURRICANE2_SUPPORT */
}
break;
case bcmCosqControlEEEPacketLatencyProfileSelect:
if (soc_feature(unit, soc_feature_eee_bb_mode)) {
int num_cosq;
#if defined(BCM_GREYHOUND2_SUPPORT)
if (SOC_IS_GREYHOUND2(unit)) {
return bcmi_gh2_cosq_control_get(unit, gport, cosq, type, arg);
}
#endif /* BCM_GREYHOUND2_SUPPORT */
if (soc_feature(unit, soc_feature_wh2)) {
/* Get the configured max cosq number */
BCM_IF_ERROR_RETURN(bcm_esw_cosq_config_get(unit, &num_cosq));
} else {
num_cosq = NUM_COS(unit);
}
if ((cosq < 0) || (cosq >= num_cosq)) {
return BCM_E_PARAM;
}
BCM_IF_ERROR_RETURN
(bcm_esw_port_local_get(unit, gport, &port));
if (!SOC_PORT_VALID(unit, port)) {
return BCM_E_PORT;
}
#if defined(BCM_HURRICANE2_SUPPORT)
if (SOC_IS_HURRICANE2(unit)||SOC_IS_GREYHOUND(unit)||
SOC_IS_HURRICANE3(unit)) {
uint32 rval = 0;
BCM_IF_ERROR_RETURN(
soc_reg32_get(unit, select_reg[cosq], port, 0, &rval));
*arg = soc_reg_field_get(unit, select_reg[cosq],
rval, EEE_LATENCY_SELf);
return BCM_E_NONE;
}
#endif /* BCM_HURRICANE2_SUPPORT */
}
break;
case bcmCosqControlPortQueueUcast:
case bcmCosqControlPortQueueMcast:
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
return bcm_mn_cosq_control_get(unit, gport, cosq, type, arg);
}
#endif /* BCM_MONTEREY_SUPPORT */
#if defined(BCM_APACHE_SUPPORT)
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_control_get(unit, gport, cosq, type, arg);
}
#endif
#if defined(BCM_TRIDENT2_SUPPORT)
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_control_get(unit, gport, cosq, type, arg);
}
#endif
#if defined(BCM_TRIUMPH3_SUPPORT)
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_control_get(unit, gport, cosq, type, arg);
}
#endif
#ifdef BCM_KATANA_SUPPORT
if (SOC_IS_KATANA(unit)) {
return bcm_kt_cosq_control_get(unit, gport, cosq, type, arg);
}
#endif
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_control_get(unit, gport, cosq, type, arg);
}
#endif
if (!BCM_COSQ_QUEUE_VALID(unit, cosq)) {
return BCM_E_PARAM;
}
if (arg == NULL) {
return BCM_E_PARAM;
}
*arg = cosq;
break;
case bcmCosqControlRedirectQueueSharedLimitBytes:
case bcmCosqControlRedirectQueueMinLimitBytes:
case bcmCosqControlRedirectSharedDynamicEnable:
case bcmCosqControlRedirectQueueLimitEnable:
case bcmCosqControlRedirectColorDynamicEnable:
case bcmCosqControlRedirectColorEnable:
#if defined(BCM_KATANA2_SUPPORT)
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_control_get(unit, gport, cosq, type, arg);
}
#endif /* BCM_KATANA2_SUPPORT */
break;
case bcmCosqControlPFCBackpressureEnable:
if (soc_feature(unit, soc_feature_priority_flow_control)) {
#if defined(BCM_GREYHOUND_SUPPORT)
if (soc_feature(unit, soc_feature_gh_style_pfc_config)) {
return bcm_gh_cosq_control_get(unit, gport, cosq, type, arg);
}
#endif /* BCM_GREYHOUND_SUPPORT */
}
break;
case bcmCosqControlE2ECCTransmitEnable:
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_gport_e2ecc_transmit_get(unit, gport, cosq,
type, arg);
}
#endif /* BCM_KATANA2_SUPPORT */
break;
case bcmCosqControlAlternateStoreForward:
if (soc_feature(unit, soc_feature_asf)) {
#if defined(BCM_GREYHOUND2_SUPPORT)
if (SOC_IS_GREYHOUND2(unit)) {
return bcmi_gh2_cosq_control_get(unit, gport, cosq, type, arg);
}
#endif /* BCM_GREYHOUND2_SUPPORT */
}
break;
default:
break;
}
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_control_extended_set
* Purpose:
* Set specified feature configuration
*
* Parameters:
* unit - (IN) Unit number
* id - (IN) Integrated cosq index
* control - (IN) Integrated cosq control data
* Returns:
* BCM_E_XXX
* Notes:
*/
int
bcm_esw_cosq_control_extended_set(
int unit,
bcm_cosq_object_id_t *id,
bcm_cosq_control_data_t *control)
{
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return bcm_th3_cosq_control_set(unit,
id->port, id->cosq, id->buffer,
control->type, control->arg);
}
#endif /* BCM_TOMAHAWK3_SUPPORT */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit) && !SOC_IS_TOMAHAWK3(unit)) {
return bcm_th_cosq_control_set(unit,
id->port, id->cosq, id->buffer,
control->type, control->arg);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_control_extended_get
* Purpose:
* Get specified feature configuration
*
* Parameters:
* unit - (IN) Unit number
* id - (IN) Integrated cosq index
* control - (INOUT) Integrated cosq control data
* Returns:
* BCM_E_XXX
* Notes:
*/
int
bcm_esw_cosq_control_extended_get(
int unit,
bcm_cosq_object_id_t *id,
bcm_cosq_control_data_t *control)
{
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return bcm_th3_cosq_control_get(unit,
id->port, id->cosq, id->buffer,
control->type, &(control->arg));
}
#endif /* BCM_TOMAHAWK3_SUPPORT */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit) && !SOC_IS_TOMAHAWK3(unit)) {
return bcm_th_cosq_control_get(unit,
id->port, id->cosq, id->buffer,
control->type, &(control->arg));
}
#endif /* BCM_TOMAHAWK_SUPPORT */
return BCM_E_UNAVAIL;
}
STATIC int _bcm_esw_cosq_num_validate(int cosq, int max_cosq_per_port)
{
if (((cosq >= 0) && (cosq < max_cosq_per_port)) ||
(cosq == BCM_COS_INVALID)) {
return BCM_E_NONE;
}
return BCM_E_PARAM;
}
/*
* Function:
* _bcm_cosq_stat_get
* Purpose:
* Get MMU statistics on a per port per cosq basis.
* Parameters:
* unit - (IN) Unit number.
* gport - (IN) GPORT ID
* cosq - (IN) COS queue.
* stat - (IN) Statistic to be retrieved.
* value - (OUT) Returned statistic value.
* Returns:
* BCM_E_xxx
* Notes:
* Triumph and Triumph2 have the following MMU drop counters:
* - Per cosq packet drop: DROP_PKT_CNT.
* - Per cosq byte drop: DROP_BYTE_CNT.
* - Additional per port packet drop: DROP_PKT_CNT_ING.
* - Additional per port byte drop: DROP_BYTE_CNT_ING.
* - Per port yellow packet drop: DROP_PKT_CNT_YEL.
* - Per port red packet drop: DROP_PKT_CNT_RED.
*
* Scorpion has the following MMU drop counters:
* - Per cosq packet drop: HOLDROP_PKT_CNT.
* - Additional per port packet drop: IBP_DROP_PKT_CNT, CFAP_DROP_PKT_CNT.
* - Per port yellow packet drop: YELLOW_CNG_DROP_CNT.
* - Per port red packet drop: RED_CN_DROP_CNT.
*
* Bradley has the following MMU drop counters:
* - Per port packet drop: DROP_PKT_CNT.
*
* Firebolt and Hurricane have the following MMU drop counters:
* - Per port packet drop: EGRDROPPKTCOUNT.
* - Per port yellow packet drop: CNGDROPCOUNT1.
* - Per port red packet drop: CNGDROPCOUNT0.
*/
int
_bcm_esw_cosq_stat_get(
int unit,
bcm_gport_t gport,
bcm_cos_queue_t cosq,
bcm_cosq_stat_t stat,
int sync_mode,
uint64 *value)
{
int max_cosq_per_port;
bcm_port_t local_port;
int (*counter_get) (int , soc_port_t , soc_reg_t , int , uint64 *);
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return bcm_th3_cosq_stat_get(unit, gport, cosq, stat, sync_mode, value);
}
#endif /* BCM_TOMAHAWK3_SUPPORT */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
return bcm_th_cosq_stat_get(unit, gport, cosq, stat, sync_mode, value);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
return bcm_mn_cosq_stat_get(unit, gport, cosq, stat, sync_mode, value);
}
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
return bcm_hx5_cosq_stat_get(unit, gport, cosq, stat, sync_mode, value);
}
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
return bcm_td3_cosq_stat_get(unit, gport, cosq, stat, sync_mode, value);
}
#endif /* BCM_TRIDENT3_SUPPORT */
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_stat_get(unit, gport, cosq, stat, sync_mode, value);
}
#endif /* BCM_APACHE_SUPPORT */
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_stat_get(unit, gport, cosq, stat, sync_mode, value);
}
#endif /* BCM_TRIDENT_SUPPORT */
#ifdef BCM_TRIDENT_SUPPORT
if (SOC_IS_TD_TT(unit)) {
return bcm_td_cosq_stat_get(unit, gport, cosq, stat, sync_mode, value);
}
#endif /* BCM_TRIDENT_SUPPORT */
#ifdef BCM_KATANA_SUPPORT
if (SOC_IS_KATANA(unit)) {
return bcm_kt_cosq_stat_get(unit, gport, cosq, stat, sync_mode, value);
}
#endif /* BCM_KATANA_SUPPORT */
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_stat_get(unit, gport, cosq, stat, sync_mode, value);
}
#endif /* BCM_KATANA2_SUPPORT */
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_stat_get(unit, gport, cosq, stat, sync_mode, value);
}
#endif /* BCM_TRIDENT_SUPPORT */
#ifdef BCM_GREYHOUND2_SUPPORT
if (SOC_IS_GREYHOUND2(unit)) {
return bcmi_gh2_cosq_stat_get(unit, gport, cosq, stat, sync_mode,
value);
}
#endif /* BCM_GREYHOUND2_SUPPORT */
if (SOC_IS_HURRICANEX(unit) || SOC_IS_GREYHOUND(unit) ||
SOC_IS_TR_VL(unit) || SOC_IS_SC_CQ(unit) ||
SOC_IS_HB_GW(unit) || SOC_IS_FB_FX_HX(unit)) {
max_cosq_per_port = 0;
} else {
return BCM_E_UNAVAIL;
}
if (value == NULL) {
return BCM_E_PARAM;
}
/*
* if sync-mode is set, update the software cached counter value,
* with the hardware count and then retrieve the count.
* else return the software cache counter value.
*/
counter_get = (sync_mode == 1)? soc_counter_sync_get: soc_counter_get;
COMPILER_64_ZERO(*value);
switch (stat) {
case bcmCosqStatDroppedPackets:
#ifdef BCM_TRIUMPH_SUPPORT
if (SOC_IS_TR_VL(unit) && !(SOC_IS_HURRICANE(unit))) {
uint64 val64;
int i, rv;
BCM_IF_ERROR_RETURN(_bcm_esw_port_gport_validate(unit, gport, &local_port));
if (soc_feature(unit, soc_feature_wh2)) {
BCM_IF_ERROR_RETURN(
bcm_esw_cosq_config_get(unit, &max_cosq_per_port));
} else {
max_cosq_per_port = IS_CPU_PORT(unit, local_port) ? \
NUM_CPU_COSQ(unit) : NUM_COS(unit);
}
BCM_IF_ERROR_RETURN(_bcm_esw_cosq_num_validate(cosq, max_cosq_per_port));
if (cosq == BCM_COS_INVALID) {
for (i = 0; i < max_cosq_per_port; i++) {
rv = counter_get(unit, local_port,
SOC_COUNTER_NON_DMA_COSQ_DROP_PKT, i, &val64);
if (SOC_SUCCESS(rv)) {
COMPILER_64_ADD_64(*value, val64);
} else {
break;
}
}
} else {
SOC_IF_ERROR_RETURN(counter_get(unit, local_port,
SOC_COUNTER_NON_DMA_COSQ_DROP_PKT, cosq, value));
}
} else
#endif /* BCM_TRIUMPH_SUPPORT */
#ifdef BCM_SCORPION_SUPPORT
if (SOC_IS_SC_CQ(unit)) {
uint64 val64;
int i, rv;
BCM_IF_ERROR_RETURN(_bcm_esw_port_gport_validate(unit, gport, &local_port));
max_cosq_per_port = IS_CPU_PORT(unit, local_port) ? NUM_CPU_COSQ(unit) : NUM_COS(unit);
BCM_IF_ERROR_RETURN(_bcm_esw_cosq_num_validate(cosq, max_cosq_per_port));
if (cosq == BCM_COS_INVALID) {
for (i = 0; i < max_cosq_per_port; i++) {
rv = counter_get(unit, local_port,
SOC_COUNTER_NON_DMA_COSQ_DROP_PKT, i, &val64);
if (SOC_SUCCESS(rv)) {
COMPILER_64_ADD_64(*value, val64);
} else {
break;
}
}
/* Also add per port IBP_DROP_PKT_CNT */
SOC_IF_ERROR_RETURN(counter_get(unit, local_port,
SOC_COUNTER_NON_DMA_PORT_DROP_PKT_IBP, 0, &val64));
COMPILER_64_ADD_64(*value, val64);
/* Also add per port CFAP_DROP_PKT_CNT */
SOC_IF_ERROR_RETURN(counter_get(unit, local_port,
SOC_COUNTER_NON_DMA_PORT_DROP_PKT_CFAP, 0, &val64));
COMPILER_64_ADD_64(*value, val64);
} else {
SOC_IF_ERROR_RETURN(counter_get(unit, local_port,
SOC_COUNTER_NON_DMA_COSQ_DROP_PKT, cosq, value));
}
} else
#endif /* BCM_SCORPION_SUPPORT */
#ifdef BCM_BRADLEY_SUPPORT
if (SOC_IS_HB_GW(unit)) {
BCM_IF_ERROR_RETURN(_bcm_esw_port_gport_validate(unit, gport, &local_port));
max_cosq_per_port = IS_CPU_PORT(unit, local_port) ? NUM_CPU_COSQ(unit) : NUM_COS(unit);
BCM_IF_ERROR_RETURN(_bcm_esw_cosq_num_validate(cosq, max_cosq_per_port));
/* Only the per port DROP_PKT_CNT is available */
if (cosq != BCM_COS_INVALID) {
return BCM_E_UNAVAIL;
}
SOC_IF_ERROR_RETURN(counter_get(unit, local_port,
SOC_COUNTER_NON_DMA_PORT_DROP_PKT, 0, value));
} else
#endif /* BCM_BRADLEY_SUPPORT */
#ifdef BCM_FIREBOLT_SUPPORT
if (SOC_IS_FB_FX_HX(unit) || SOC_IS_HURRICANE(unit)) {
BCM_IF_ERROR_RETURN(_bcm_esw_port_gport_validate(unit, gport, &local_port));
max_cosq_per_port = IS_CPU_PORT(unit, local_port) ? NUM_CPU_COSQ(unit) : NUM_COS(unit);
BCM_IF_ERROR_RETURN(_bcm_esw_cosq_num_validate(cosq, max_cosq_per_port));
/* Only the per port EGRDROPPKTCOUNT is available */
if (cosq != BCM_COS_INVALID) {
return BCM_E_UNAVAIL;
}
_bcm_stat_counter_extra_get(unit, EGRDROPPKTCOUNTr,
local_port, value);
} else
#endif /* BCM_FIREBOLT_SUPPORT */
{
return BCM_E_UNAVAIL;
}
break;
case bcmCosqStatDroppedBytes:
#ifdef BCM_TRIUMPH_SUPPORT
if (SOC_IS_TR_VL(unit) &&
!(SOC_IS_HURRICANEX(unit)||SOC_IS_GREYHOUND(unit) ||
SOC_IS_GREYHOUND2(unit))) {
uint64 val64;
int i, rv;
BCM_IF_ERROR_RETURN(_bcm_esw_port_gport_validate(unit, gport, &local_port));
max_cosq_per_port = IS_CPU_PORT(unit, local_port) ? NUM_CPU_COSQ(unit) : NUM_COS(unit);
BCM_IF_ERROR_RETURN(_bcm_esw_cosq_num_validate(cosq, max_cosq_per_port));
if (cosq == BCM_COS_INVALID) {
for (i = 0; i < max_cosq_per_port; i++) {
rv = counter_get(unit, local_port,
SOC_COUNTER_NON_DMA_COSQ_DROP_BYTE, i, &val64);
if (SOC_SUCCESS(rv)) {
COMPILER_64_ADD_64(*value, val64);
} else {
break;
}
}
/* Also add the per port DROP_BYTE_CNT_ING */
SOC_IF_ERROR_RETURN(counter_get(unit, local_port,
SOC_COUNTER_NON_DMA_PORT_DROP_BYTE_ING, 0, &val64));
COMPILER_64_ADD_64(*value, val64);
} else {
SOC_IF_ERROR_RETURN(counter_get(unit, local_port,
SOC_COUNTER_NON_DMA_COSQ_DROP_BYTE, cosq, value));
}
} else
#endif /* BCM_TRIUMPH_SUPPORT */
{
return BCM_E_UNAVAIL;
}
break;
case bcmCosqStatYellowCongestionDroppedPackets:
BCM_IF_ERROR_RETURN(_bcm_esw_port_gport_validate(unit, gport, &local_port));
if (soc_feature(unit, soc_feature_wh2)) {
BCM_IF_ERROR_RETURN(
bcm_esw_cosq_config_get(unit, &max_cosq_per_port));
} else {
max_cosq_per_port = IS_CPU_PORT(unit, local_port) ? \
NUM_CPU_COSQ(unit) : NUM_COS(unit);
}
BCM_IF_ERROR_RETURN(_bcm_esw_cosq_num_validate(cosq, max_cosq_per_port));
if (cosq != BCM_COS_INVALID) {
/* Yellow dropped packet counters are available only on a per
* port basis.
*/
return BCM_E_UNAVAIL;
}
SOC_IF_ERROR_RETURN(counter_get(unit, local_port,
SOC_COUNTER_NON_DMA_PORT_DROP_PKT_YELLOW, 0, value));
break;
case bcmCosqStatRedCongestionDroppedPackets:
BCM_IF_ERROR_RETURN(_bcm_esw_port_gport_validate(unit, gport, &local_port));
if (soc_feature(unit, soc_feature_wh2)) {
BCM_IF_ERROR_RETURN(
bcm_esw_cosq_config_get(unit, &max_cosq_per_port));
} else {
max_cosq_per_port = IS_CPU_PORT(unit, local_port) ? \
NUM_CPU_COSQ(unit) : NUM_COS(unit);
}
BCM_IF_ERROR_RETURN(_bcm_esw_cosq_num_validate(cosq, max_cosq_per_port));
if (cosq != BCM_COS_INVALID) {
/* Red dropped packet counters are available only on a per
* port basis.
*/
return BCM_E_UNAVAIL;
}
SOC_IF_ERROR_RETURN(counter_get(unit, local_port,
SOC_COUNTER_NON_DMA_PORT_DROP_PKT_RED, 0, value));
break;
case bcmCosqStatOutPackets:
#ifdef BCM_TRIUMPH_SUPPORT
if (SOC_IS_TR_VL(unit)) {
uint64 val64;
int i, rv;
BCM_IF_ERROR_RETURN(_bcm_esw_port_gport_validate(unit, gport, &local_port));
if (soc_feature(unit, soc_feature_wh2)) {
BCM_IF_ERROR_RETURN(
bcm_esw_cosq_config_get(unit, &max_cosq_per_port));
} else {
max_cosq_per_port = IS_CPU_PORT(unit, local_port) ? \
NUM_CPU_COSQ(unit) : NUM_COS(unit);
}
BCM_IF_ERROR_RETURN(_bcm_esw_cosq_num_validate(cosq, max_cosq_per_port));
COMPILER_64_ZERO(*value);
if (cosq == BCM_COS_INVALID) {
for (i = 0; i < max_cosq_per_port; i++) {
rv = counter_get(unit, local_port,
SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_PKT, i, &val64);
if (SOC_SUCCESS(rv)) {
COMPILER_64_ADD_64(*value, val64);
} else {
break;
}
}
} else {
SOC_IF_ERROR_RETURN(counter_get(unit, local_port,
SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_PKT, cosq, value));
}
} else
#endif
{
return BCM_E_UNAVAIL;
}
break;
case bcmCosqStatOutBytes:
#ifdef BCM_TRIUMPH_SUPPORT
if (SOC_IS_TR_VL(unit)) {
uint64 val64;
int i, rv;
BCM_IF_ERROR_RETURN(_bcm_esw_port_gport_validate(unit, gport, &local_port));
if (soc_feature(unit, soc_feature_wh2)) {
BCM_IF_ERROR_RETURN(
bcm_esw_cosq_config_get(unit, &max_cosq_per_port));
} else {
max_cosq_per_port = IS_CPU_PORT(unit, local_port) ? \
NUM_CPU_COSQ(unit) : NUM_COS(unit);
}
BCM_IF_ERROR_RETURN(_bcm_esw_cosq_num_validate(cosq, max_cosq_per_port));
COMPILER_64_ZERO(*value);
if (cosq == BCM_COS_INVALID) {
for (i = 0; i < max_cosq_per_port; i++) {
rv = counter_get(unit, local_port,
SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_BYTE, i, &val64);
if (SOC_SUCCESS(rv)) {
COMPILER_64_ADD_64(*value, val64);
} else {
break;
}
}
} else {
SOC_IF_ERROR_RETURN(counter_get(unit, local_port,
SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_BYTE, cosq, value));
}
} else
#endif
{
return BCM_E_UNAVAIL;
}
break;
case bcmCosqStatDiscardDroppedPackets:
#if defined(BCM_GREYHOUND_SUPPORT)
if (soc_feature(unit, soc_feature_wred_drop_counter_per_port)) {
BCM_IF_ERROR_RETURN(_bcm_esw_port_gport_validate(unit, gport, &local_port));
if (soc_feature(unit, soc_feature_wh2)) {
BCM_IF_ERROR_RETURN(
bcm_esw_cosq_config_get(unit, &max_cosq_per_port));
} else {
max_cosq_per_port = IS_CPU_PORT(unit, local_port) ? \
NUM_CPU_COSQ(unit) : NUM_COS(unit);
}
BCM_IF_ERROR_RETURN(_bcm_esw_cosq_num_validate(cosq, max_cosq_per_port));
COMPILER_64_ZERO(*value);
if (cosq == BCM_COS_INVALID) {
SOC_IF_ERROR_RETURN(soc_counter_get(unit, local_port,
SOC_COUNTER_NON_DMA_PORT_WRED_DROP_PKT, 0, value));
} else {
return BCM_E_UNAVAIL;
}
} else
#endif
{
return BCM_E_UNAVAIL;
}
break;
case bcmCosqStatHOLDropPackets:
#if defined(BCM_HURRICANE2_SUPPORT)
if (soc_feature(unit,soc_feature_cosq_hol_drop_packet_count)) {
bcm_port_t selected_port;
uint32 rval;
int i;
static soc_reg_t hold_reg[] = {
HOLD_COS0r, HOLD_COS1r, HOLD_COS2r, HOLD_COS3r,
HOLD_COS4r, HOLD_COS5r, HOLD_COS6r, HOLD_COS7r,
};
if (!SOC_REG_IS_VALID(unit, HOLD_COS0r)) {
return BCM_E_UNAVAIL;
}
if (!SOC_REG_IS_VALID(unit, HOLD_COS_PORT_SELECTr)) {
return BCM_E_UNAVAIL;
}
BCM_IF_ERROR_RETURN(_bcm_esw_port_gport_validate(unit, gport, &local_port));
if (soc_feature(unit, soc_feature_wh2)) {
BCM_IF_ERROR_RETURN(
bcm_esw_cosq_config_get(unit, &max_cosq_per_port));
} else {
max_cosq_per_port = IS_CPU_PORT(unit, local_port) ? \
NUM_CPU_COSQ(unit) : NUM_COS(unit);
}
BCM_IF_ERROR_RETURN(_bcm_esw_cosq_num_validate(cosq, max_cosq_per_port));
COMPILER_64_ZERO(*value);
SOC_IF_ERROR_RETURN(READ_HOLD_COS_PORT_SELECTr(unit, &rval));
selected_port = soc_reg_field_get(unit, HOLD_COS_PORT_SELECTr, rval,
PORT_NUMf);
if (selected_port != local_port) {
return BCM_E_PORT;
}
if (cosq == BCM_COS_INVALID) {
for (i = 0; i < COUNTOF(hold_reg); i++) {
SOC_IF_ERROR_RETURN(soc_reg32_get(unit, hold_reg[i], REG_PORT_ANY, 0, &rval));
COMPILER_64_ADD_32(*value, rval);
}
} else {
if (cosq >= COUNTOF(hold_reg)) {
return BCM_E_PARAM;
}
SOC_IF_ERROR_RETURN(soc_reg32_get(unit, hold_reg[cosq], REG_PORT_ANY, 0, &rval));
COMPILER_64_ADD_32(*value, rval);
}
} else
#endif
{
return BCM_E_UNAVAIL;
}
break;
default:
return BCM_E_UNAVAIL;
}
return BCM_E_NONE;
}
/*
* Function:
* bcm_cosq_stat_get
* Purpose:
* Get MMU statistics on a per port per cosq basis.
* Parameters:
* unit - (IN) Unit number.
* gport - (IN) GPORT ID
* cosq - (IN) COS queue.
* stat - (IN) Statistic to be retrieved.
* value - (OUT) Returned statistic value.
* Returns:
* BCM_E_xxx
* Notes:
* Triumph and Triumph2 have the following MMU drop counters:
* - Per cosq packet drop: DROP_PKT_CNT.
* - Per cosq byte drop: DROP_BYTE_CNT.
* - Additional per port packet drop: DROP_PKT_CNT_ING.
* - Additional per port byte drop: DROP_BYTE_CNT_ING.
* - Per port yellow packet drop: DROP_PKT_CNT_YEL.
* - Per port red packet drop: DROP_PKT_CNT_RED.
*
* Scorpion has the following MMU drop counters:
* - Per cosq packet drop: HOLDROP_PKT_CNT.
* - Additional per port packet drop: IBP_DROP_PKT_CNT, CFAP_DROP_PKT_CNT.
* - Per port yellow packet drop: YELLOW_CNG_DROP_CNT.
* - Per port red packet drop: RED_CN_DROP_CNT.
*
* Bradley has the following MMU drop counters:
* - Per port packet drop: DROP_PKT_CNT.
*
* Firebolt and Hurricane have the following MMU drop counters:
* - Per port packet drop: EGRDROPPKTCOUNT.
* - Per port yellow packet drop: CNGDROPCOUNT1.
* - Per port red packet drop: CNGDROPCOUNT0.
*/
int
bcm_esw_cosq_stat_get(
int unit,
bcm_gport_t gport,
bcm_cos_queue_t cosq,
bcm_cosq_stat_t stat,
uint64 *value)
{
int sync_mode = 0;
if (NULL == value) {
return (BCM_E_PARAM);
}
return _bcm_esw_cosq_stat_get(unit, gport, cosq, stat, sync_mode, value);
return BCM_E_NONE;
}
/*
* Function:
* bcm_cosq_stat_get32
* Purpose:
* Get MMU statistics on a per port per cosq basis.
* Parameters:
* unit - (IN) Unit number.
* gport - (IN) GPORT ID
* cosq - (IN) COS queue.
* stat - (IN) Statistic to be retrieved.
* value - (OUT) Returned statistic value.
* Returns:
* BCM_E_xxx
* Notes:
*/
int
bcm_esw_cosq_stat_get32(
int unit,
bcm_gport_t gport,
bcm_cos_queue_t cosq,
bcm_cosq_stat_t stat,
uint32 *value)
{
uint64 val64;
int rv;
if (NULL == value) {
return (BCM_E_PARAM);
}
rv = bcm_esw_cosq_stat_get(unit, gport, cosq, stat, &val64);
if (BCM_SUCCESS(rv)) {
*value = COMPILER_64_LO(val64);
}
return rv;
}
/*
* Function:
* bcm_cosq_stat_sync_get
* Purpose:
* Get MMU statistics on a per port per cosq basis.
* The software cached count is synced with the hardware
* value.
* Parameters:
* unit - (IN) Unit number.
* gport - (IN) GPORT ID
* cosq - (IN) COS queue.
* stat - (IN) Statistic to be retrieved.
* value - (OUT) Returned statistic value.
* Returns:
* BCM_E_xxx
* Notes:
* Triumph and Triumph2 have the following MMU drop counters:
* - Per cosq packet drop: DROP_PKT_CNT.
* - Per cosq byte drop: DROP_BYTE_CNT.
* - Additional per port packet drop: DROP_PKT_CNT_ING.
* - Additional per port byte drop: DROP_BYTE_CNT_ING.
* - Per port yellow packet drop: DROP_PKT_CNT_YEL.
* - Per port red packet drop: DROP_PKT_CNT_RED.
*
* Scorpion has the following MMU drop counters:
* - Per cosq packet drop: HOLDROP_PKT_CNT.
* - Additional per port packet drop: IBP_DROP_PKT_CNT, CFAP_DROP_PKT_CNT.
* - Per port yellow packet drop: YELLOW_CNG_DROP_CNT.
* - Per port red packet drop: RED_CN_DROP_CNT.
*
* Bradley has the following MMU drop counters:
* - Per port packet drop: DROP_PKT_CNT.
*
* Firebolt and Hurricane have the following MMU drop counters:
* - Per port packet drop: EGRDROPPKTCOUNT.
* - Per port yellow packet drop: CNGDROPCOUNT1.
* - Per port red packet drop: CNGDROPCOUNT0.
*/
int
bcm_esw_cosq_stat_sync_get(
int unit,
bcm_gport_t gport,
bcm_cos_queue_t cosq,
bcm_cosq_stat_t stat,
uint64 *value)
{
int sync_mode = 1;
if (NULL == value) {
return (BCM_E_PARAM);
}
return _bcm_esw_cosq_stat_get(unit, gport, cosq, stat, sync_mode, value);
}
/*
* Function:
* bcm_esw_cosq_stat_sync_multi_get
* Purpose:
* Get multiple MMU statistics on a per port per cosq basis.
* The software cached count is synced with the hardware
* value.
* Parameters:
* unit - (IN) Unit number.
* gport - (IN) GPORT ID
* cosq - (IN) COS queue.
* nstat - (IN) Number of elements in stat array
* stat_arr - (IN) Array of statistics types defined in bcm_cos_queue_t
* value_arr - (OUT) Array of collected statistics values
* Returns:
* BCM_E_xxx
*/
int
bcm_esw_cosq_stat_sync_multi_get(
int unit,
bcm_gport_t gport,
bcm_cos_queue_t cosq,
int nstat,
bcm_cosq_stat_t *stat_arr,
uint64 *value_arr)
{
int sync_mode = 1;
int stix;
if (nstat <= 0) {
return BCM_E_PARAM;
}
if ((NULL == stat_arr) || (NULL == value_arr)) {
return BCM_E_PARAM;
}
for (stix = 0; stix < nstat; stix++) {
BCM_IF_ERROR_RETURN
(_bcm_esw_cosq_stat_get(unit, gport, cosq, stat_arr[stix],
sync_mode, &(value_arr[stix])));
}
return BCM_E_NONE;
}
/*
* Function:
* bcm_cosq_stat_get32
* Purpose:
* Get MMU statistics on a per port per cosq basis.
* The software cached count is synced with the hardware
* value.
* Parameters:
* unit - (IN) Unit number.
* gport - (IN) GPORT ID
* cosq - (IN) COS queue.
* stat - (IN) Statistic to be retrieved.
* value - (OUT) Returned statistic value.
* Returns:
* BCM_E_xxx
* Notes:
*/
int
bcm_esw_cosq_stat_sync_get32(
int unit,
bcm_gport_t gport,
bcm_cos_queue_t cosq,
bcm_cosq_stat_t stat,
uint32 *value)
{
uint64 val64;
int rv;
if (NULL == value) {
return (BCM_E_PARAM);
}
rv = bcm_esw_cosq_stat_sync_get(unit, gport, cosq, stat, &val64);
if (BCM_SUCCESS(rv)) {
*value = COMPILER_64_LO(val64);
}
return rv;
}
/*
* Function:
* bcm_esw_cosq_stat_sync_multi_get32
* Purpose:
* Get multiple MMU statistics on a per port per cosq basis.
* The software cached count is synced with the hardware
* value.
* Parameters:
* unit - (IN) Unit number.
* gport - (IN) GPORT ID
* cosq - (IN) COS queue.
* nstat - (IN) Number of elements in stat array
* stat_arr - (IN) Array of statistics types defined in bcm_cos_queue_t
* value_arr - (OUT) Array of collected statistics values
* Returns:
* BCM_E_xxx
*/
int
bcm_esw_cosq_stat_sync_multi_get32(
int unit,
bcm_gport_t gport,
bcm_cos_queue_t cosq,
int nstat,
bcm_cosq_stat_t *stat_arr,
uint32 *value_arr)
{
int sync_mode = 1;
int stix;
uint64 val64;
if (nstat <= 0) {
return BCM_E_PARAM;
}
if ((NULL == stat_arr) || (NULL == value_arr)) {
return BCM_E_PARAM;
}
for (stix = 0; stix < nstat; stix++) {
COMPILER_64_ZERO(val64);
BCM_IF_ERROR_RETURN
(_bcm_esw_cosq_stat_get(unit, gport, cosq, stat_arr[stix],
sync_mode, &val64));
value_arr[stix] = COMPILER_64_LO(val64);
}
return BCM_E_NONE;
}
/*
* Function:
* bcm_cosq_stat_set
* Purpose:
* Set MMU statistics on a per port per cosq basis.
* Parameters:
* unit - (IN) Unit number.
* gport - (IN) GPORT ID
* cosq - (IN) COS queue.
* stat - (IN) Statistic to be set.
* value - (IN) Statistic value to be set.
* Returns:
* BCM_E_xxx
* Notes:
*/
int
bcm_esw_cosq_stat_set(
int unit,
bcm_gport_t gport,
bcm_cos_queue_t cosq,
bcm_cosq_stat_t stat,
uint64 value)
{
int max_cosq_per_port;
bcm_port_t local_port;
int cosq_allowed=0;
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return bcm_th3_cosq_stat_set(unit, gport, cosq, stat, value);
}
#endif /* BCM_TOMAHAWK3_SUPPORT */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
return bcm_th_cosq_stat_set(unit, gport, cosq, stat, value);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
return bcm_ap_cosq_stat_set(unit, gport, cosq, stat, value);
}
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
return bcm_hx5_cosq_stat_set(unit, gport, cosq, stat, value);
}
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
return bcm_td3_cosq_stat_set(unit, gport, cosq, stat, value);
}
#endif /* BCM_TRIDENT3_SUPPORT */
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_stat_set(unit, gport, cosq, stat, value);
}
#endif /* BCM_TRIDENT2_SUPPORT */
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_stat_set(unit, gport, cosq, stat, value);
}
#endif /* BCM_TRIDENT2_SUPPORT */
#ifdef BCM_TRIDENT_SUPPORT
if (SOC_IS_TD_TT(unit)) {
return bcm_td_cosq_stat_set(unit, gport, cosq, stat, value);
}
#endif /* BCM_TRIDENT_SUPPORT */
#ifdef BCM_KATANA_SUPPORT
if (SOC_IS_KATANA(unit)) {
return bcm_kt_cosq_stat_set(unit, gport, cosq, stat, value);
}
#endif /* BCM_KATANA_SUPPORT */
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_stat_set(unit, gport, cosq, stat, value);
}
#endif /* BCM_KATANA2_SUPPORT */
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_stat_set(unit, gport, cosq, stat, value);
}
#endif /* BCM_TRIUMPH3_SUPPORT */
#ifdef BCM_GREYHOUND2_SUPPORT
if (SOC_IS_GREYHOUND2(unit)) {
return bcmi_gh2_cosq_stat_set(unit, gport, cosq, stat, value);
}
#endif /* BCM_GREYHOUND2_SUPPORT */
if (SOC_IS_HURRICANEX(unit) || SOC_IS_GREYHOUND(unit) ||
SOC_IS_TR_VL(unit) || SOC_IS_SC_CQ(unit) ||
SOC_IS_HB_GW(unit) || SOC_IS_FB_FX_HX(unit)) {
max_cosq_per_port = 0;
} else {
return BCM_E_UNAVAIL;
}
BCM_IF_ERROR_RETURN(_bcm_esw_port_gport_validate(unit, gport, &local_port));
if (soc_feature(unit, soc_feature_wh2)) {
BCM_IF_ERROR_RETURN(bcm_esw_cosq_config_get(unit,
&max_cosq_per_port));
} else {
max_cosq_per_port = IS_CPU_PORT(unit, local_port) ? \
NUM_CPU_COSQ(unit) : NUM_COS(unit);
}
if (((cosq >= 0) && (cosq < max_cosq_per_port)) ||
(cosq == BCM_COS_INVALID)) {
cosq_allowed = 1;
}
if (!cosq_allowed) {
return BCM_E_PARAM;
}
switch (stat) {
case bcmCosqStatDroppedPackets:
#ifdef BCM_TRIUMPH_SUPPORT
if (SOC_IS_TR_VL(unit) && !(SOC_IS_HURRICANE(unit))) {
uint64 val64_zero;
int i, rv;
COMPILER_64_ZERO(val64_zero);
if (SOC_IS_HURRICANE3(unit) || SOC_IS_GREYHOUND(unit) ||
SOC_IS_HURRICANE2(unit)) {
/* Registers are read-only */
return BCM_E_UNAVAIL;
}
if (cosq == BCM_COS_INVALID) {
/* Write given value to first COS queue */
rv = soc_counter_set(unit, local_port,
SOC_COUNTER_NON_DMA_COSQ_DROP_PKT, 0, value);
/* Write zero to all other COS queues */
for (i = 1; i < max_cosq_per_port; i++) {
rv = soc_counter_set(unit, local_port,
SOC_COUNTER_NON_DMA_COSQ_DROP_PKT, i, val64_zero);
if (SOC_FAILURE(rv)) {
break;
}
}
} else {
SOC_IF_ERROR_RETURN(soc_counter_set(unit, local_port,
SOC_COUNTER_NON_DMA_COSQ_DROP_PKT, cosq, value));
}
} else
#endif /* BCM_TRIUMPH_SUPPORT */
#ifdef BCM_SCORPION_SUPPORT
if (SOC_IS_SC_CQ(unit)) {
uint64 val64_zero;
int i, rv;
COMPILER_64_ZERO(val64_zero);
if (cosq == BCM_COS_INVALID) {
/* Write given value to first COS queue */
rv = soc_counter_set(unit, local_port,
SOC_COUNTER_NON_DMA_COSQ_DROP_PKT, 0, value);
/* Write zero to all other COS queues */
for (i = 1; i < max_cosq_per_port; i++) {
rv = soc_counter_set(unit, local_port,
SOC_COUNTER_NON_DMA_COSQ_DROP_PKT, i, val64_zero);
if (SOC_FAILURE(rv)) {
break;
}
}
/* Also write zero to per port IBP_DROP_PKT_CNT */
SOC_IF_ERROR_RETURN(soc_counter_set(unit, local_port,
SOC_COUNTER_NON_DMA_PORT_DROP_PKT_IBP, 0, val64_zero));
/* Also write zero to per port CFAP_DROP_PKT_CNT */
SOC_IF_ERROR_RETURN(soc_counter_set(unit, local_port,
SOC_COUNTER_NON_DMA_PORT_DROP_PKT_CFAP, 0, val64_zero));
} else {
SOC_IF_ERROR_RETURN(soc_counter_set(unit, local_port,
SOC_COUNTER_NON_DMA_COSQ_DROP_PKT, cosq, value));
}
} else
#endif /* BCM_SCORPION_SUPPORT */
#ifdef BCM_BRADLEY_SUPPORT
if (SOC_IS_HB_GW(unit)) {
/* Only the per port DROP_PKT_CNT is available */
if (cosq != BCM_COS_INVALID) {
return BCM_E_UNAVAIL;
}
SOC_IF_ERROR_RETURN(soc_counter_set(unit, local_port,
SOC_COUNTER_NON_DMA_PORT_DROP_PKT, 0, value));
} else
#endif /* BCM_BRADLEY_SUPPORT */
#ifdef BCM_FIREBOLT_SUPPORT
if (SOC_IS_FB_FX_HX(unit) || SOC_IS_HURRICANE(unit)) {
/* EGRDROPPKTCOUNT is read-only */
return BCM_E_UNAVAIL;
} else
#endif /* BCM_FIREBOLT_SUPPORT */
{
return BCM_E_UNAVAIL;
}
break;
case bcmCosqStatDroppedBytes:
#ifdef BCM_TRIUMPH_SUPPORT
if (SOC_IS_TR_VL(unit) &&
!(SOC_IS_HURRICANEX(unit)||SOC_IS_GREYHOUND(unit))) {
uint64 val64_zero;
int i, rv;
COMPILER_64_ZERO(val64_zero);
if (cosq == BCM_COS_INVALID) {
/* Write given value to first COS queue */
rv = soc_counter_set(unit, local_port,
SOC_COUNTER_NON_DMA_COSQ_DROP_BYTE, 0, value);
/* Write zero to all other COS queues */
for (i = 1; i < max_cosq_per_port; i++) {
rv = soc_counter_set(unit, local_port,
SOC_COUNTER_NON_DMA_COSQ_DROP_BYTE, i, val64_zero);
if (SOC_FAILURE(rv)) {
break;
}
}
/* Also write zero to per port DROP_BYTE_CNT_ING */
SOC_IF_ERROR_RETURN(soc_counter_set(unit, local_port,
SOC_COUNTER_NON_DMA_PORT_DROP_BYTE_ING, 0, val64_zero));
} else {
SOC_IF_ERROR_RETURN(soc_counter_set(unit, local_port,
SOC_COUNTER_NON_DMA_COSQ_DROP_BYTE, cosq, value));
}
} else
#endif /* BCM_TRIUMPH_SUPPORT */
{
return BCM_E_UNAVAIL;
}
break;
case bcmCosqStatYellowCongestionDroppedPackets:
if (cosq != BCM_COS_INVALID) {
/* Yellow dropped packet counters are available only on a per
* port basis.
*/
return BCM_E_UNAVAIL;
}
if (SOC_IS_FB_FX_HX(unit) || SOC_IS_HURRICANEX(unit) ||
SOC_IS_GREYHOUND(unit)) {
/* CNGDROPCOUNT1 is read-only */
return BCM_E_UNAVAIL;
}
SOC_IF_ERROR_RETURN(soc_counter_set(unit, local_port,
SOC_COUNTER_NON_DMA_PORT_DROP_PKT_YELLOW, 0, value));
break;
case bcmCosqStatRedCongestionDroppedPackets:
if (cosq != BCM_COS_INVALID) {
/* Red dropped packet counters are available only on a per
* port basis.
*/
return BCM_E_UNAVAIL;
}
if (SOC_IS_FB_FX_HX(unit) || SOC_IS_HURRICANEX(unit) ||
SOC_IS_GREYHOUND(unit)) {
/* CNGDROPCOUNT0 is read-only */
return BCM_E_UNAVAIL;
}
SOC_IF_ERROR_RETURN(soc_counter_set(unit, local_port,
SOC_COUNTER_NON_DMA_PORT_DROP_PKT_RED, 0, value));
break;
case bcmCosqStatOutPackets:
#ifdef BCM_TRIUMPH_SUPPORT
if (SOC_IS_TR_VL(unit)) {
uint64 val64_zero;
int i, rv;
COMPILER_64_ZERO(val64_zero);
if (cosq == BCM_COS_INVALID) {
/* Write given value to first COS queue */
rv = soc_counter_set(unit, local_port,
SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_PKT, 0, value);
/* Write zero to all other COS queues */
for (i = 1; i < max_cosq_per_port; i++) {
rv = soc_counter_set(unit, local_port,
SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_PKT, i, val64_zero);
if (SOC_FAILURE(rv)) {
break;
}
}
} else {
SOC_IF_ERROR_RETURN(soc_counter_set(unit, local_port,
SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_PKT, cosq, value));
}
} else
#endif
{
return BCM_E_UNAVAIL;
}
break;
case bcmCosqStatOutBytes:
#ifdef BCM_TRIUMPH_SUPPORT
if (SOC_IS_TR_VL(unit)) {
uint64 val64_zero;
int i, rv;
COMPILER_64_ZERO(val64_zero);
if (cosq == BCM_COS_INVALID) {
/* Write given value to first COS queue */
rv = soc_counter_set(unit, local_port,
SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_BYTE, 0, value);
/* Write zero to all other COS queues */
for (i = 1; i < max_cosq_per_port; i++) {
rv = soc_counter_set(unit, local_port,
SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_BYTE, i, val64_zero);
if (SOC_FAILURE(rv)) {
break;
}
}
} else {
SOC_IF_ERROR_RETURN(soc_counter_set(unit, local_port,
SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_BYTE, cosq, value));
}
} else
#endif
{
return BCM_E_UNAVAIL;
}
break;
case bcmCosqStatDiscardDroppedPackets:
#if defined(BCM_GREYHOUND_SUPPORT)
if (soc_feature(unit, soc_feature_wred_drop_counter_per_port)) {
if (cosq == BCM_COS_INVALID) {
SOC_IF_ERROR_RETURN(soc_counter_set(unit, local_port,
SOC_COUNTER_NON_DMA_PORT_WRED_DROP_PKT, 0, value));
} else {
return BCM_E_UNAVAIL;
}
} else
#endif
{
return BCM_E_UNAVAIL;
}
break;
case bcmCosqStatHOLDropPackets:
#if defined(BCM_HURRICANE2_SUPPORT)
if (soc_feature(unit,soc_feature_cosq_hol_drop_packet_count)) {
int i;
static soc_reg_t hold_reg[] = {
HOLD_COS0r, HOLD_COS1r, HOLD_COS2r, HOLD_COS3r,
HOLD_COS4r, HOLD_COS5r, HOLD_COS6r, HOLD_COS7r,
};
if (!SOC_REG_IS_VALID(unit, HOLD_COS0r)) {
return BCM_E_UNAVAIL;
}
if (!SOC_REG_IS_VALID(unit, HOLD_COS_PORT_SELECTr)) {
return BCM_E_UNAVAIL;
}
BCM_IF_ERROR_RETURN(_bcm_esw_port_gport_validate(unit, gport, &local_port));
BCM_IF_ERROR_RETURN(_bcm_esw_cosq_num_validate(cosq, max_cosq_per_port));
soc_reg_field32_modify(unit, HOLD_COS_PORT_SELECTr,
REG_PORT_ANY,
PORT_NUMf, local_port);
if (cosq == BCM_COS_INVALID) {
for (i = 0; i < COUNTOF(hold_reg); i++) {
SOC_IF_ERROR_RETURN(soc_reg32_set(unit, hold_reg[i],
REG_PORT_ANY, 0, COMPILER_64_LO(value)));
}
} else {
if (cosq >= COUNTOF(hold_reg)) {
return BCM_E_PARAM;
}
SOC_IF_ERROR_RETURN(soc_reg32_set(unit, hold_reg[cosq],
REG_PORT_ANY, 0, COMPILER_64_LO(value)));
}
} else
#endif
{
return BCM_E_UNAVAIL;
}
break;
default:
return BCM_E_PARAM;
}
return BCM_E_NONE;
}
/*
* Function:
* bcm_cosq_stat_set32
* Purpose:
* Set MMU statistics on a per port per cosq basis.
* Parameters:
* unit - (IN) Unit number.
* gport - (IN) GPORT ID
* cosq - (IN) COS queue.
* stat - (IN) Statistic to be set.
* value - (IN) Statistic value to be set.
* Returns:
* BCM_E_xxx
* Notes:
*/
int
bcm_esw_cosq_stat_set32(
int unit,
bcm_gport_t gport,
bcm_cos_queue_t cosq,
bcm_cosq_stat_t stat,
uint32 value)
{
uint64 val64;
COMPILER_64_SET(val64, 0, value);
return bcm_esw_cosq_stat_set(unit, gport, cosq, stat, val64);
}
/*
* Function:
* bcm_esw_cosq_subport_flow_control_set
* Purpose:
* Set a port or node (L0, L1, L2) to flow control when
* a CoE control frame is received on a subtended port.
* Parameters:
* unit - (IN) Unit number.
* subport - (IN) Subtended port
* sched_port - (IN) Node (Port, L0, L1, L2) to flow control
* Returns:
* BCM_E_xxx
* Notes:
*/
int
bcm_esw_cosq_subport_flow_control_set(
int unit,
bcm_gport_t subport,
bcm_gport_t sched_port)
{
#ifdef BCM_HGPROXY_COE_SUPPORT
if (soc_feature(unit, soc_feature_hgproxy_subtag_coe)) {
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_subport_flow_control_set(unit, subport, sched_port);
}
#endif
if (SOC_IS_TRIDENT2PLUS(unit)) {
bcm_td2p_cosq_subport_flow_control_set(unit, subport, sched_port);
} else {
return BCM_E_UNAVAIL;
}
} else
#endif /* BCM_HGPROXY_COE_SUPPORT */
{
return BCM_E_UNAVAIL;
}
return BCM_E_NONE;
}
/*
* Function:
* bcm_esw_cosq_subport_flow_control_get
* Purpose:
* Get a port or node (L0, L1, L2) that's flow controlled when
* a CoE control frame is received on a subtended port.
* Parameters:
* unit - (IN) Unit number.
* subport - (IN) Subtended port
* sched_port - (IN) Node (Port, L0, L1, L2) being flow controlled
* Returns:
* BCM_E_xxx
* Notes:
*/
int
bcm_esw_cosq_subport_flow_control_get(
int unit,
bcm_gport_t subport,
bcm_gport_t * sched_port)
{
#ifdef BCM_HGPROXY_COE_SUPPORT
if (soc_feature(unit, soc_feature_hgproxy_subtag_coe)) {
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_subport_flow_control_get(unit, subport, sched_port);
}
#endif
if (SOC_IS_TRIDENT2PLUS(unit)) {
bcm_td2p_cosq_subport_flow_control_get(unit, subport, sched_port);
} else {
return BCM_E_UNAVAIL;
}
} else
#endif /* BCM_HGPROXY_COE_SUPPORT */
{
return BCM_E_UNAVAIL;
}
return BCM_E_NONE;
}
/*
* Function:
* bcm_esw_cosq_gport_destmod_attach
* Purpose:
* Attach gport mapping from ingress port, dest_modid to
* fabric egress port.
* Parameters:
* unit - (IN) Unit number.
* gport - (IN) GPORT ID
* ingress_port - (IN) Ingress port
* dest_modid - (IN) Destination module ID
* fabric_egress_port - (IN) Port number on fabric that
* is connected to dest_modid
* Returns:
* BCM_E_xxx
* Notes:
*/
int bcm_esw_cosq_gport_destmod_attach(int unit, bcm_gport_t gport,
bcm_port_t ingress_port,
bcm_module_t dest_modid,
int fabric_egress_port)
{
#ifdef BCM_TRIDENT_SUPPORT
if (SOC_IS_TD_TT(unit) && !SOC_IS_APACHE(unit)) {
return bcm_td_cosq_gport_destmod_attach(unit, gport, ingress_port,
dest_modid, fabric_egress_port);
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_gport_destmod_detach
* Purpose:
* Attach gport mapping from ingress port, dest_modid to
* fabric egress port.
* Parameters:
* unit - (IN) Unit number.
* gport - (IN) GPORT ID
* ingress_port - (IN) Ingress port
* dest_modid - (IN) Destination module ID
* fabric_egress_port - (IN) Port number on fabric that
* is connected to dest_modid
* Returns:
* BCM_E_xxx
* Notes:
*/
int bcm_esw_cosq_gport_destmod_detach(int unit, bcm_gport_t gport,
bcm_port_t ingress_port,
bcm_module_t dest_modid,
int fabric_egress_port)
{
#ifdef BCM_TRIDENT_SUPPORT
if (SOC_IS_TD_TT(unit) && !SOC_IS_APACHE(unit)) {
return bcm_td_cosq_gport_destmod_detach(unit, gport, ingress_port,
dest_modid, fabric_egress_port);
}
#endif
return BCM_E_UNAVAIL;
}
int bcm_esw_cosq_gport_congestion_config_set(int unit, bcm_gport_t gport,
bcm_cos_queue_t cosq,
bcm_cosq_congestion_info_t *config)
{
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
return bcm_mn_cosq_gport_congestion_config_set(unit, gport, cosq, config);
}
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_gport_congestion_config_set(unit, gport, cosq, config);
}
#endif
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_gport_congestion_config_set(unit, gport, cosq, config);
}
#endif
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_gport_congestion_config_set(unit, gport, cosq, config);
}
#endif
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_gport_congestion_config_set(unit, gport, cosq, config);
}
#endif
return BCM_E_UNAVAIL;
}
int bcm_esw_cosq_gport_congestion_config_get(int unit, bcm_gport_t gport,
bcm_cos_queue_t cosq,
bcm_cosq_congestion_info_t *config)
{
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
return bcm_mn_cosq_gport_congestion_config_get(unit, gport, cosq, config);
}
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
return bcm_ap_cosq_gport_congestion_config_get(unit, gport, cosq, config);
}
#endif
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
return bcm_td2_cosq_gport_congestion_config_get(unit, gport, cosq, config);
}
#endif
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
return bcm_tr3_cosq_gport_congestion_config_get(unit, gport, cosq, config);
}
#endif
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
return bcm_kt2_cosq_gport_congestion_config_get(unit, gport, cosq, config);
}
#endif
return BCM_E_UNAVAIL;
}
int bcm_esw_cosq_bst_profile_set(int unit,
bcm_gport_t port,
bcm_cos_queue_t cosq,
bcm_bst_stat_id_t bid,
bcm_cosq_bst_profile_t *profile)
{
if (!SOC_UNIT_VALID(unit)) {
return BCM_E_UNIT;
}
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return _bcm_th3_bst_cmn_profile_set
(unit, port, cosq, BCM_BST_DUP_XPE, bid, profile);
}
#endif
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
return bcm_th_cosq_bst_profile_set(unit, port, cosq, bid, profile);
}
#endif
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
BCM_IF_ERROR_RETURN(
bcm_mn_cosq_bst_profile_set(unit, port, cosq, bid, profile));
return BCM_E_NONE;
}
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
return bcm_td3_cosq_bst_profile_set(unit, port, cosq, bid, profile);
}
#endif
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
BCM_IF_ERROR_RETURN(
bcm_ap_cosq_bst_profile_set(unit, port, cosq, bid, profile));
return BCM_E_NONE;
}
#endif
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
BCM_IF_ERROR_RETURN(
bcm_td2_cosq_bst_profile_set(unit, port, cosq, bid, profile));
return BCM_E_NONE;
}
#endif
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
BCM_IF_ERROR_RETURN(
bcm_tr3_cosq_bst_profile_set(unit, port, cosq, bid, profile));
return BCM_E_NONE;
}
#endif
return BCM_E_UNAVAIL;
}
int bcm_esw_cosq_bst_profile_get(int unit,
bcm_gport_t port,
bcm_cos_queue_t cosq,
bcm_bst_stat_id_t bid,
bcm_cosq_bst_profile_t *profile)
{
if (!SOC_UNIT_VALID(unit)) {
return BCM_E_UNIT;
}
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return _bcm_th3_bst_cmn_profile_get
(unit, port, cosq, BCM_BST_DUP_XPE, bid, profile);
}
#endif
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
return bcm_th_cosq_bst_profile_get(unit, port, cosq, bid, profile);
}
#endif
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
BCM_IF_ERROR_RETURN(
bcm_mn_cosq_bst_profile_get(unit, port, cosq, bid, profile));
return BCM_E_NONE;
}
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
return bcm_td3_cosq_bst_profile_get(unit, port, cosq, bid, profile);
}
#endif
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
BCM_IF_ERROR_RETURN(
bcm_ap_cosq_bst_profile_get(unit, port, cosq, bid, profile));
return BCM_E_NONE;
}
#endif
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
BCM_IF_ERROR_RETURN(
bcm_td2_cosq_bst_profile_get(unit, port, cosq, bid, profile));
return BCM_E_NONE;
}
#endif
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
BCM_IF_ERROR_RETURN(
bcm_tr3_cosq_bst_profile_get(unit, port, cosq, bid, profile));
return BCM_E_NONE;
}
#endif
return BCM_E_UNAVAIL;
}
int bcm_esw_cosq_bst_multi_profile_set(int unit,
bcm_gport_t port,
bcm_cos_queue_t cosq,
bcm_bst_stat_id_t bid,
int array_size,
bcm_cosq_bst_profile_t *profile_array)
{
if (!SOC_UNIT_VALID(unit)) {
return BCM_E_UNIT;
}
#ifdef BCM_TOMAHAWK3_SUPPORT
if(SOC_IS_TOMAHAWK3(unit)) {
int i;
if(bid != bcmBstStatIdDevice) {
/* only CFAP thresh is non-duplicate */
return BCM_E_UNAVAIL;
}
if(array_size > NUM_ITM(unit)) {
return BCM_E_PARAM;
}
for(i = 0 ; i < array_size; i++) {
BCM_IF_ERROR_RETURN(
_bcm_th3_bst_cmn_profile_set(unit, port, cosq, i, bid,
&profile_array[i]));
}
return BCM_E_NONE;
}
#endif
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
return bcm_th_cosq_bst_multi_profile_set(unit, port, cosq, bid,
array_size, profile_array);
}
#endif
return BCM_E_UNAVAIL;
}
int bcm_esw_cosq_bst_multi_profile_get(int unit,
bcm_gport_t port,
bcm_cos_queue_t cosq,
bcm_bst_stat_id_t bid,
int array_size,
bcm_cosq_bst_profile_t *profile_array,
int *count)
{
if (!SOC_UNIT_VALID(unit)) {
return BCM_E_UNIT;
}
#ifdef BCM_TOMAHAWK3_SUPPORT
if(SOC_IS_TOMAHAWK3(unit)) {
int i;
if(bid != bcmBstStatIdDevice) {
/* only CFAP thresh is non-duplicate */
return BCM_E_UNAVAIL;
}
if(array_size > NUM_ITM(unit)) {
return BCM_E_PARAM;
}
for(i = 0 ; i < array_size; i++) {
BCM_IF_ERROR_RETURN(
_bcm_th3_bst_cmn_profile_get(unit, port, cosq, i,
bid, &profile_array[i]));
}
*count = i;
return BCM_E_NONE;
}
#endif
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
return bcm_th_cosq_bst_multi_profile_get(unit, port, cosq, bid,
array_size, profile_array, count);
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_bst_stat_get
* Purpose:
* Set the profile for tracking.
* Parameters:
* unit - (IN) Unit number.
* port - (IN) GPORT ID
* cosq - (IN) COS queue
* bid - (IN) BST statistics ID.
* options - (IN) Clear-on-read or not
* value - (OUT) Returned statistic value.
* Returns:
* BCM_E_XXX
*/
int bcm_esw_cosq_bst_stat_get(int unit,
bcm_gport_t port,
bcm_cos_queue_t cosq,
bcm_bst_stat_id_t bid,
uint32 options,
uint64 *pvalue)
{
if (!SOC_UNIT_VALID(unit)) {
return BCM_E_UNIT;
}
if (pvalue == NULL) {
return BCM_E_PARAM;
}
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return bcm_th3_cosq_bst_stat_get
(unit, port, cosq, BCM_COSQ_BUFFER_ID_INVALID, bid, options, pvalue);
}
#endif
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
return bcm_th_cosq_bst_stat_get
(unit, port, cosq, BCM_COSQ_BUFFER_ID_INVALID, bid, options, pvalue);
}
#endif
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
BCM_IF_ERROR_RETURN(
bcm_mn_cosq_bst_stat_get(unit, port, cosq, bid, options, pvalue));
return BCM_E_NONE;
}
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
return bcm_td3_cosq_bst_stat_get(unit, port, cosq, bid, options, pvalue);
}
#endif
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
BCM_IF_ERROR_RETURN(
bcm_ap_cosq_bst_stat_get(unit, port, cosq, bid, options, pvalue));
return BCM_E_NONE;
}
#endif
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
BCM_IF_ERROR_RETURN(
bcm_td2_cosq_bst_stat_get(unit, port, cosq, bid, options, pvalue));
return BCM_E_NONE;
}
#endif
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
BCM_IF_ERROR_RETURN(
bcm_tr3_cosq_bst_stat_get(unit, port, cosq, bid, options, pvalue));
return BCM_E_NONE;
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_bst_stat_get32
* Purpose:
* Set the profile for tracking.
* Parameters:
* unit - (IN) Unit number.
* port - (IN) GPORT ID
* cosq - (IN) COS queue
* bid - (IN) BST statistics ID.
* options - (IN) Clear-on-read or not
* value - (OUT) Returned statistic value.
* Returns:
* BCM_E_XXX
*/
int bcm_esw_cosq_bst_stat_get32(int unit,
bcm_gport_t port,
bcm_cos_queue_t cosq,
bcm_bst_stat_id_t bid,
uint32 options,
uint32 *pvalue)
{
uint64 val64;
int rv;
if (NULL == pvalue) {
return BCM_E_PARAM;
}
rv = bcm_esw_cosq_bst_stat_get(unit, port, cosq, bid, options, &val64);
if (BCM_SUCCESS(rv)) {
*pvalue = COMPILER_64_LO(val64);
}
return rv;
}
/*
* Function:
* bcm_esw_cosq_bst_stat_extended_get
* Purpose:
* Set the profile for tracking.
* Parameters:
* unit - (IN) Unit number.
* id - (IN) Integrated cosq index
* bid - (IN) BST statistics ID.
* options - (IN) Clear-on-read or not
* value - (OUT) Returned statistic value.
* Returns:
* BCM_E_XXX
*/
int bcm_esw_cosq_bst_stat_extended_get(int unit,
bcm_cosq_object_id_t *id,
bcm_bst_stat_id_t bid,
uint32 options,
uint64 *pvalue)
{
if (!SOC_UNIT_VALID(unit)) {
return BCM_E_UNIT;
}
if (pvalue == NULL) {
return BCM_E_PARAM;
}
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return bcm_th3_cosq_bst_stat_get
(unit, id->port, id->cosq, id->buffer, bid, options, pvalue);
}
#endif
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
return bcm_th_cosq_bst_stat_get
(unit, id->port, id->cosq, id->buffer, bid, options, pvalue);
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_bst_stat_extended_get32
* Purpose:
* Set the profile for tracking.
* Parameters:
* unit - (IN) Unit number.
* id - (IN) Integrated cosq index
* bid - (IN) BST statistics ID.
* options - (IN) Clear-on-read or not
* value - (OUT) Returned statistic value.
* Returns:
* BCM_E_XXX
*/
int bcm_esw_cosq_bst_stat_extended_get32(int unit,
bcm_cosq_object_id_t *id,
bcm_bst_stat_id_t bid,
uint32 options,
uint32 *pvalue)
{
uint64 val64;
int rv;
if (NULL == pvalue) {
return BCM_E_PARAM;
}
rv = bcm_esw_cosq_bst_stat_extended_get(unit, id, bid, options, &val64);
if (BCM_SUCCESS(rv)) {
*pvalue = COMPILER_64_LO(val64);
}
return rv;
}
/*
* Function:
* bcm_esw_cosq_bst_stat_multi_get
* Purpose:
* To retrieve a list of stats all at once. To match the usual API
* multi_get(), the signature for this function should take a list
* of stat IDs to fetch, and return a list of values along with
* the count of items returned.
* Parameters:
* unit - StrataSwitch unit number.
* port - port to configure, -1 for any port.
* cosq - COS queue to configure, -1 for any COS queue.
* options - BCM_COSQ_STAT_CLEAR.
* max_values - max value in id_list.
* id_list - (IN) IDs to retrieve.
* values - (OUT) values retrieved from id_list
* Returns:
* BCM_E_XXX
*/
int bcm_esw_cosq_bst_stat_multi_get(int unit,
bcm_gport_t port,
bcm_cos_queue_t cosq,
uint32 options,
int max_values,
bcm_bst_stat_id_t *id_list,
uint64 *values)
{
/* Parameter validation checks */
if (!SOC_UNIT_VALID(unit)) {
return BCM_E_UNIT;
}
if (id_list == NULL || values == NULL) {
return BCM_E_PARAM;
}
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return bcm_th3_cosq_bst_stat_multi_get(unit, port, cosq, options,
max_values, id_list, values);
}
#endif
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
return bcm_th_cosq_bst_stat_multi_get(unit, port, cosq, options,
max_values, id_list, values);
}
#endif
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
BCM_IF_ERROR_RETURN(
bcm_mn_cosq_bst_stat_multi_get(unit, port, cosq, options,
max_values, id_list, values));
return BCM_E_NONE;
}
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
return bcm_td3_cosq_bst_stat_multi_get(unit, port, cosq, options,
max_values, id_list, values);
}
#endif
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
BCM_IF_ERROR_RETURN(
bcm_ap_cosq_bst_stat_multi_get(unit, port, cosq, options,
max_values, id_list, values));
return BCM_E_NONE;
}
#endif
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
BCM_IF_ERROR_RETURN(
bcm_td2_cosq_bst_stat_multi_get(unit, port, cosq, options,
max_values, id_list, values));
return BCM_E_NONE;
}
#endif
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
BCM_IF_ERROR_RETURN(
bcm_tr3_cosq_bst_stat_multi_get(unit, port, cosq, options,
max_values, id_list, values));
return BCM_E_NONE;
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_bst_stat_multi_get32
* Purpose:
* To retrieve a list of stats all at once. To match the usual API
* multi_get(), the signature for this function should take a list
* of stat IDs to fetch, and return a list of values along with
* the count of items returned.
* Parameters:
* unit - StrataSwitch unit number.
* port - port to configure, -1 for any port.
* cosq - COS queue to configure, -1 for any COS queue.
* options - BCM_COSQ_STAT_CLEAR.
* max_values - max value in id_list.
* id_list - (IN) IDs to retrieve.
* values - (OUT) values retrieved from id_list
* Returns:
* BCM_E_XXX
*/
int bcm_esw_cosq_bst_stat_multi_get32(int unit,
bcm_gport_t port,
bcm_cos_queue_t cosq,
uint32 options,
int max_values,
bcm_bst_stat_id_t *id_list,
uint32 *values)
{
int i, rv;
uint64 *val64;
val64 = sal_alloc(max_values * sizeof(uint64), "bst_stat_multi_get32");
if (val64 == NULL) {
return BCM_E_MEMORY;
}
sal_memset(val64, 0x0, max_values * sizeof(uint64));
rv = bcm_esw_cosq_bst_stat_multi_get(unit, port, cosq, options, max_values, \
id_list, val64);
if (BCM_SUCCESS(rv)) {
for (i = 0; i < max_values; i++) {
values[i] = COMPILER_64_LO(val64[i]);
}
}
sal_free(val64);
return rv;
}
/*
* Function:
* bcm_esw_cosq_bst_stat_clear
* Purpose:
* clear given BST stats to zero
* Parameters:
* unit - StrataSwitch unit number.
* port - port to configure, -1 for any port.
* cosq - COS queue to configure, -1 for any COS queue.
* Returns:
* BCM_E_XXX
*/
int bcm_esw_cosq_bst_stat_clear(int unit, bcm_gport_t port,
bcm_cos_queue_t cosq, bcm_bst_stat_id_t bid)
{
if (!SOC_UNIT_VALID(unit)) {
return BCM_E_UNIT;
}
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return bcm_th3_cosq_bst_stat_clear
(unit, port, cosq, BCM_COSQ_BUFFER_ID_INVALID, bid);
}
#endif
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
return bcm_th_cosq_bst_stat_clear
(unit, port, cosq, BCM_COSQ_BUFFER_ID_INVALID, bid);
}
#endif
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
BCM_IF_ERROR_RETURN(
bcm_mn_cosq_bst_stat_clear(unit, port, cosq, bid));
return BCM_E_NONE;
}
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
return bcm_td3_cosq_bst_stat_clear(unit, port, cosq, bid);
}
#endif
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
BCM_IF_ERROR_RETURN(
bcm_ap_cosq_bst_stat_clear(unit, port, cosq, bid));
return BCM_E_NONE;
}
#endif
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
BCM_IF_ERROR_RETURN(
bcm_td2_cosq_bst_stat_clear(unit, port, cosq, bid));
return BCM_E_NONE;
}
#endif
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
BCM_IF_ERROR_RETURN(
bcm_tr3_cosq_bst_stat_clear(unit, port, cosq, bid));
return BCM_E_NONE;
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_bst_stat_extended_clear
* Purpose:
* clear given BST stats to zero
* Parameters:
* unit - StrataSwitch unit number.
* id - Integrated cosq index
* Returns:
* BCM_E_XXX
*/
int bcm_esw_cosq_bst_stat_extended_clear(int unit, bcm_cosq_object_id_t *id,
bcm_bst_stat_id_t bid)
{
if (!SOC_UNIT_VALID(unit)) {
return BCM_E_UNIT;
}
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return bcm_th3_cosq_bst_stat_clear
(unit, id->port, id->cosq, id->buffer, bid);
}
#endif
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
return bcm_th_cosq_bst_stat_clear
(unit, id->port, id->cosq, id->buffer, bid);
}
#endif
return BCM_E_UNAVAIL;
}
int bcm_esw_cosq_bst_stat_sync(int unit, bcm_bst_stat_id_t bid)
{
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
BCM_IF_ERROR_RETURN(
bcm_th_cosq_bst_stat_sync(unit, bid));
return BCM_E_NONE;
}
#endif
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
BCM_IF_ERROR_RETURN(
bcm_ap_cosq_bst_stat_sync(unit, bid));
return BCM_E_NONE;
}
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
BCM_IF_ERROR_RETURN(
bcm_td3_cosq_bst_stat_sync(unit, bid));
return BCM_E_NONE;
}
#endif
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
BCM_IF_ERROR_RETURN(
bcm_ap_cosq_bst_stat_sync(unit, bid));
return BCM_E_NONE;
}
#endif
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
BCM_IF_ERROR_RETURN(
bcm_td2_cosq_bst_stat_sync(unit, bid));
return BCM_E_NONE;
}
#endif
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
BCM_IF_ERROR_RETURN(
bcm_tr3_cosq_bst_stat_sync(unit, bid));
return BCM_E_NONE;
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_classifier_create
* Purpose:
* Create a cosq classifier.
* Parameters:
* unit - (IN) Unit number.
* classifier - (IN) Classifier attributes
* classifier_id - (IN/OUT) Classifier ID
* Returns:
* BCM_E_xxx
*/
int
bcm_esw_cosq_classifier_create(
int unit,
bcm_cosq_classifier_t *classifier,
int *classifier_id)
{
if ((classifier->flags & BCM_COSQ_CLASSIFIER_VLAN) &&
(classifier->flags & BCM_COSQ_CLASSIFIER_VFI)) {
return BCM_E_PARAM;
}
#ifdef BCM_TRIUMPH3_SUPPORT
if ((classifier->flags & BCM_COSQ_CLASSIFIER_FIELD) &&
(!(classifier->flags & BCM_COSQ_CLASSIFIER_WITH_ID))) {
if (soc_feature(unit, soc_feature_field_ingress_cosq_override)) {
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
BCM_IF_ERROR_RETURN
(bcm_kt2_cosq_field_classifier_id_create(unit, classifier,
classifier_id));
} else
#endif
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
BCM_IF_ERROR_RETURN
(bcm_th3_cosq_field_classifier_id_create(unit, classifier,
classifier_id));
} else
#endif
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
BCM_IF_ERROR_RETURN
(bcm_th_cosq_field_classifier_id_create(unit, classifier,
classifier_id));
} else
#endif
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
BCM_IF_ERROR_RETURN
(bcm_mn_cosq_field_classifier_id_create(unit, classifier,
classifier_id));
} else
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
BCM_IF_ERROR_RETURN
(bcm_hx5_cosq_field_classifier_id_create(unit, classifier,
classifier_id));
} else
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
BCM_IF_ERROR_RETURN
(bcm_td3_cosq_field_classifier_id_create(unit, classifier,
classifier_id));
} else
#endif /* BCM_TRIDENT3_SUPPORT */
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
BCM_IF_ERROR_RETURN
(bcm_ap_cosq_field_classifier_id_create(unit, classifier,
classifier_id));
} else
#endif
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
BCM_IF_ERROR_RETURN
(bcm_td2_cosq_field_classifier_id_create(unit, classifier,
classifier_id));
} else
#endif
{
BCM_IF_ERROR_RETURN
(bcm_tr3_cosq_field_classifier_id_create(unit, classifier,
classifier_id));
}
} else {
return (BCM_E_UNAVAIL);
}
} else
#endif
if (classifier->flags & BCM_COSQ_CLASSIFIER_L2 ||
classifier->flags & BCM_COSQ_CLASSIFIER_L3 ||
classifier->flags & BCM_COSQ_CLASSIFIER_GPORT ||
classifier->flags & BCM_COSQ_CLASSIFIER_L3_EGRESS) {
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit) &&
soc_feature(unit, soc_feature_endpoint_queuing)) {
BCM_IF_ERROR_RETURN(bcm_ap_cosq_endpoint_create(unit, classifier,
classifier_id));
} else
#endif /* BCM_APACHE_SUPPORT */
#ifdef BCM_TRIDENT2_SUPPORT
if (soc_feature(unit, soc_feature_endpoint_queuing)) {
BCM_IF_ERROR_RETURN(bcm_td2_cosq_endpoint_create(unit, classifier,
classifier_id));
} else
#endif /* BCM_TRIDENT2_SUPPORT */
{
return BCM_E_PARAM;
}
} else if (classifier->flags & BCM_COSQ_CLASSIFIER_VLAN) {
#if defined(BCM_TRIUMPH3_SUPPORT)
if (soc_feature(unit, soc_feature_service_queuing)) {
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
BCM_IF_ERROR_RETURN(bcm_kt2_cosq_service_classifier_id_create(
unit, classifier, classifier_id));
} else
#endif
#if defined(BCM_APACHE_SUPPORT)
if (SOC_IS_APACHE(unit)) {
BCM_IF_ERROR_RETURN(
bcm_ap_cosq_service_classifier_id_create(unit, classifier,
classifier_id));
} else
#endif /* BCM_APACHE_SUPPORT */
#if defined(BCM_TRIDENT2_SUPPORT)
if (SOC_IS_TRIDENT2(unit)) {
BCM_IF_ERROR_RETURN(
bcm_td2_cosq_service_classifier_id_create(unit, classifier,
classifier_id));
} else
#endif /* BCM_TRIDENT2_SUPPORT */
{
BCM_IF_ERROR_RETURN(bcm_tr3_cosq_service_classifier_id_create(
unit, classifier, classifier_id));
}
} else
#endif /* BCM_TRIUMPH3_SUPPORT */
{
return BCM_E_UNAVAIL;
}
} else if (classifier->flags & BCM_COSQ_CLASSIFIER_VFI) {
if (soc_feature(unit, soc_feature_service_queuing)) {
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
BCM_IF_ERROR_RETURN(bcm_kt2_cosq_service_classifier_id_create(
unit, classifier, classifier_id));
} else
#endif
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TRIDENT2(unit)) {
BCM_IF_ERROR_RETURN(
bcm_td2_cosq_service_classifier_id_create(unit, classifier,
classifier_id));
} else
#endif /* BCM_TRIDENT2_SUPPORT */
{
return BCM_E_UNAVAIL;
}
}
} else {
return BCM_E_PARAM;
}
return BCM_E_NONE;
}
/*
* Function:
* bcm_esw_cosq_classifier_destroy
* Purpose:
* Destroy a cosq classifier.
* Parameters:
* unit - (IN) Unit number.
* classifier_id - (IN) Classifier ID
* Returns:
* BCM_E_xxx
*/
int
bcm_esw_cosq_classifier_destroy(
int unit,
int classifier_id)
{
#ifdef BCM_TRIUMPH3_SUPPORT
if (_BCM_COSQ_CLASSIFIER_IS_FIELD(classifier_id)) {
if (soc_feature(unit, soc_feature_field_ingress_cosq_override)) {
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
BCM_IF_ERROR_RETURN
(bcm_kt2_cosq_field_classifier_id_destroy(unit,
classifier_id));
} else
#endif
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
BCM_IF_ERROR_RETURN
(bcm_th3_cosq_field_classifier_id_destroy(unit,
classifier_id));
} else
#endif
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
BCM_IF_ERROR_RETURN
(bcm_th_cosq_field_classifier_id_destroy(unit,
classifier_id));
} else
#endif
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
BCM_IF_ERROR_RETURN
(bcm_ap_cosq_field_classifier_id_destroy(unit,
classifier_id));
} else
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
BCM_IF_ERROR_RETURN
(bcm_hx5_cosq_field_classifier_id_destroy(unit,
classifier_id));
} else
#endif
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
BCM_IF_ERROR_RETURN
(bcm_td3_cosq_field_classifier_id_destroy(unit,
classifier_id));
} else
#endif
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
BCM_IF_ERROR_RETURN
(bcm_ap_cosq_field_classifier_id_destroy(unit,
classifier_id));
} else
#endif
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
BCM_IF_ERROR_RETURN
(bcm_td2_cosq_field_classifier_id_destroy(unit,
classifier_id));
} else
#endif
{
BCM_IF_ERROR_RETURN
(bcm_tr3_cosq_field_classifier_id_destroy(unit,
classifier_id));
}
} else {
return (BCM_E_UNAVAIL);
}
} else
#endif
if (_BCM_COSQ_CLASSIFIER_IS_ENDPOINT(classifier_id)) {
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit) &&
soc_feature(unit, soc_feature_endpoint_queuing)) {
BCM_IF_ERROR_RETURN
(bcm_ap_cosq_endpoint_destroy(unit, classifier_id));
} else
#endif /* BCM_APACHE_SUPPORT */
#ifdef BCM_TRIDENT2_SUPPORT
if (soc_feature(unit, soc_feature_endpoint_queuing)) {
BCM_IF_ERROR_RETURN
(bcm_td2_cosq_endpoint_destroy(unit, classifier_id));
} else
#endif /* BCM_TRIDENT2_SUPPORT */
{
return BCM_E_PARAM;
}
} else if (_BCM_COSQ_CLASSIFIER_IS_SERVICE(classifier_id)) {
#ifdef BCM_TRIUMPH3_SUPPORT
if (soc_feature(unit, soc_feature_service_queuing)) {
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
BCM_IF_ERROR_RETURN(bcm_kt2_cosq_service_classifier_id_destroy(
unit, classifier_id));
} else
#endif
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
BCM_IF_ERROR_RETURN(
bcm_ap_cosq_service_classifier_id_destroy(unit,
classifier_id));
} else
#endif /* BCM_APACHE_SUPPORT */
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TRIDENT2(unit)) {
BCM_IF_ERROR_RETURN(
bcm_td2_cosq_service_classifier_id_destroy(unit,
classifier_id));
} else
#endif /* BCM_TRIDENT2_SUPPORT */
{
BCM_IF_ERROR_RETURN(bcm_tr3_cosq_service_classifier_id_destroy(
unit, classifier_id));
}
} else
#endif /* BCM_TRIUMPH3_SUPPORT */
{
return BCM_E_UNAVAIL;
}
} else {
return BCM_E_PARAM;
}
return BCM_E_NONE;
}
/*
* Function:
* bcm_esw_cosq_classifier_get
* Purpose:
* Get info about a cosq classifier.
* Parameters:
* unit - (IN) Unit number.
* classifier_id - (IN) Classifier ID
* classifier - (OUT) Classifier attributes
* Returns:
* BCM_E_xxx
*/
int
bcm_esw_cosq_classifier_get(
int unit,
int classifier_id,
bcm_cosq_classifier_t *classifier)
{
#ifdef BCM_TRIUMPH3_SUPPORT
if (_BCM_COSQ_CLASSIFIER_IS_FIELD(classifier_id)) {
if (soc_feature(unit, soc_feature_field_ingress_cosq_override)) {
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
BCM_IF_ERROR_RETURN
(bcm_kt2_cosq_field_classifier_get(unit, classifier_id,
classifier));
} else
#endif
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
BCM_IF_ERROR_RETURN
(bcm_th3_cosq_field_classifier_get(unit, classifier_id,
classifier));
} else
#endif
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
BCM_IF_ERROR_RETURN
(bcm_th_cosq_field_classifier_get(unit, classifier_id,
classifier));
} else
#endif
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
BCM_IF_ERROR_RETURN
(bcm_mn_cosq_field_classifier_get(unit, classifier_id,
classifier));
} else
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
BCM_IF_ERROR_RETURN
(bcm_hx5_cosq_field_classifier_get(unit, classifier_id,
classifier));
} else
#endif
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
BCM_IF_ERROR_RETURN
(bcm_td3_cosq_field_classifier_get(unit, classifier_id,
classifier));
} else
#endif
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
BCM_IF_ERROR_RETURN
(bcm_ap_cosq_field_classifier_get(unit, classifier_id,
classifier));
} else
#endif
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
BCM_IF_ERROR_RETURN
(bcm_td2_cosq_field_classifier_get(unit, classifier_id,
classifier));
} else
#endif
{
BCM_IF_ERROR_RETURN
(bcm_tr3_cosq_field_classifier_get(unit, classifier_id,
classifier));
}
} else {
return (BCM_E_UNAVAIL);
}
} else
#endif
if (_BCM_COSQ_CLASSIFIER_IS_ENDPOINT(classifier_id)) {
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit) &&
soc_feature(unit, soc_feature_endpoint_queuing)) {
BCM_IF_ERROR_RETURN
(bcm_ap_cosq_endpoint_get(unit, classifier_id, classifier));
} else
#endif /* BCM_APACHE_SUPPORT */
#ifdef BCM_TRIDENT2_SUPPORT
if (soc_feature(unit, soc_feature_endpoint_queuing)) {
BCM_IF_ERROR_RETURN
(bcm_td2_cosq_endpoint_get(unit, classifier_id, classifier));
} else
#endif /* BCM_TRIDENT2_SUPPORT */
{
return BCM_E_PARAM;
}
} else if (_BCM_COSQ_CLASSIFIER_IS_SERVICE(classifier_id)) {
#ifdef BCM_TRIUMPH3_SUPPORT
if (soc_feature(unit, soc_feature_service_queuing)) {
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
BCM_IF_ERROR_RETURN(bcm_kt2_cosq_service_classifier_get(unit,
classifier_id, classifier));
} else
#endif
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
BCM_IF_ERROR_RETURN(
bcm_ap_cosq_service_classifier_get(unit, classifier_id,
classifier));
} else
#endif /* BCM_APACHE_SUPPORT */
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TRIDENT2(unit)) {
BCM_IF_ERROR_RETURN(
bcm_td2_cosq_service_classifier_get(unit, classifier_id,
classifier));
} else
#endif /* BCM_TRIDENT2_SUPPORT */
{
BCM_IF_ERROR_RETURN(bcm_tr3_cosq_service_classifier_get(unit,
classifier_id, classifier));
}
} else
#endif /* BCM_TRIUMPH3_SUPPORT */
{
return BCM_E_UNAVAIL;
}
} else {
return BCM_E_PARAM;
}
return BCM_E_NONE;
}
/*
* Function:
* bcm_esw_cosq_classifier_mapping_multi_set
* Purpose:
* Set the mapping from port, classifier, and multiple internal priorities
* to multiple COS queues in a queue group.
* Parameters:
* unit - (IN) Unit number.
* port - (IN) GPORT ID
* classifier_id - (IN) Classifier ID
* queue_group - (IN) Queue group
* array_count - (IN) Number of elements in priority_array and
* cosq_array
* priority_array - (IN) Array of internal priorities
* cosq_array - (IN) Array of COS queues
* Returns:
* BCM_E_xxx
*/
int
bcm_esw_cosq_classifier_mapping_multi_set(
int unit,
bcm_gport_t port,
int classifier_id,
bcm_gport_t queue_group,
int array_count,
bcm_cos_t *priority_array,
bcm_cos_queue_t *cosq_array)
{
bcm_port_t local_port;
int sysportid;
if (array_count <= 0) {
return BCM_E_PARAM;
}
if (NULL == priority_array || NULL == cosq_array) {
return BCM_E_PARAM;
}
#ifdef BCM_TRIUMPH3_SUPPORT
if (_BCM_COSQ_CLASSIFIER_IS_FIELD(classifier_id)) {
if (soc_feature(unit, soc_feature_field_ingress_cosq_override)) {
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
BCM_IF_ERROR_RETURN
(bcm_kt2_cosq_field_classifier_map_set(unit,
classifier_id,
array_count,
priority_array,
cosq_array));
} else
#endif
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
BCM_IF_ERROR_RETURN
(bcm_th3_cosq_field_classifier_map_set(unit,
classifier_id,
array_count,
priority_array,
cosq_array));
} else
#endif
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
BCM_IF_ERROR_RETURN
(bcm_th_cosq_field_classifier_map_set(unit,
classifier_id,
array_count,
priority_array,
cosq_array));
} else
#endif
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
BCM_IF_ERROR_RETURN
(bcm_mn_cosq_field_classifier_map_set(unit,
classifier_id,
array_count,
priority_array,
cosq_array));
} else
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
BCM_IF_ERROR_RETURN
(bcm_hx5_cosq_field_classifier_map_set(unit,
classifier_id,
array_count,
priority_array,
cosq_array));
} else
#endif
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
BCM_IF_ERROR_RETURN
(bcm_td3_cosq_field_classifier_map_set(unit,
classifier_id,
array_count,
priority_array,
cosq_array));
} else
#endif
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
BCM_IF_ERROR_RETURN
(bcm_ap_cosq_field_classifier_map_set(unit,
classifier_id,
array_count,
priority_array,
cosq_array));
} else
#endif
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
BCM_IF_ERROR_RETURN
(bcm_td2_cosq_field_classifier_map_set(unit,
classifier_id,
array_count,
priority_array,
cosq_array));
} else
#endif
{
BCM_IF_ERROR_RETURN
(bcm_tr3_cosq_field_classifier_map_set(unit,
classifier_id,
array_count,
priority_array,
cosq_array));
}
} else {
return (BCM_E_UNAVAIL);
}
} else
#endif
{
if (BCM_GPORT_IS_SET(port)) {
BCM_IF_ERROR_RETURN(bcm_esw_port_local_get(unit, port,
&local_port));
} else if (SOC_PORT_VALID(unit, port)) {
local_port = port;
} else {
return BCM_E_PORT;
}
if (BCM_GPORT_IS_UCAST_QUEUE_GROUP(queue_group)) {
sysportid = BCM_GPORT_UCAST_QUEUE_GROUP_SYSPORTID_GET(queue_group);
if (sysportid != local_port) {
/* The port the queue_group was created on does not match
* the input parameter port.
*/
return BCM_E_PORT;
}
} else {
if (!BCM_GPORT_IS_UCAST_SUBSCRIBER_QUEUE_GROUP(queue_group)) {
return BCM_E_PARAM;
}
}
if (_BCM_COSQ_CLASSIFIER_IS_ENDPOINT(classifier_id)) {
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit) &&
soc_feature(unit, soc_feature_endpoint_queuing)) {
BCM_IF_ERROR_RETURN
(bcm_ap_cosq_endpoint_map_set(unit, local_port,
classifier_id, queue_group,
array_count, priority_array,
cosq_array));
} else
#endif /* BCM_TRIDENT2_SUPPORT */
#ifdef BCM_TRIDENT2_SUPPORT
if (soc_feature(unit, soc_feature_endpoint_queuing)) {
BCM_IF_ERROR_RETURN
(bcm_td2_cosq_endpoint_map_set(unit, local_port,
classifier_id, queue_group,
array_count, priority_array,
cosq_array));
} else
#endif /* BCM_TRIDENT2_SUPPORT */
{
return BCM_E_PARAM;
}
} else if (_BCM_COSQ_CLASSIFIER_IS_SERVICE(classifier_id)) {
#ifdef BCM_TRIUMPH3_SUPPORT
if (soc_feature(unit, soc_feature_service_queuing)) {
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
BCM_IF_ERROR_RETURN
(bcm_kt2_cosq_service_map_set(unit, local_port,
classifier_id, queue_group,
array_count, priority_array,
cosq_array));
} else
#endif
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
BCM_IF_ERROR_RETURN(
bcm_ap_cosq_service_map_set(unit, local_port,
classifier_id, queue_group,
array_count,
priority_array,
cosq_array));
} else
#endif /* BCM_APACHE_SUPPORT */
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TRIDENT2(unit)
|| (SOC_IS_TRIDENT2PLUS(unit) || SOC_IS_TITAN2PLUS(unit))) {
BCM_IF_ERROR_RETURN(
bcm_td2_cosq_service_map_set(unit, local_port,
classifier_id, queue_group,
array_count,
priority_array,
cosq_array));
} else
#endif /* BCM_TRIDENT2_SUPPORT */
{
BCM_IF_ERROR_RETURN
(bcm_tr3_cosq_service_map_set(unit, local_port,
classifier_id, queue_group,
array_count, priority_array,
cosq_array));
}
} else
#endif /* BCM_TRIUMPH3_SUPPORT */
{
return BCM_E_UNAVAIL;
}
} else {
return BCM_E_PARAM;
}
}
return (BCM_E_NONE);
}
/*
* Function:
* bcm_esw_cosq_classifier_mapping_set
* Purpose:
* Set the mapping from port, classifier, and internal priority to a COS
* queue in a queue group.
* Parameters:
* unit - (IN) Unit number.
* port - (IN) GPORT ID
* classifier_id - (IN) Classifier ID
* queue_group - (IN) Queue group
* priority - (IN) Internal priority
* cosq - (IN) COS queue in queue group
* Returns:
* BCM_E_xxx
*/
int
bcm_esw_cosq_classifier_mapping_set(
int unit,
bcm_gport_t port,
int classifier_id,
bcm_gport_t queue_group,
bcm_cos_t priority,
bcm_cos_queue_t cosq)
{
if (_BCM_COSQ_CLASSIFIER_IS_FIELD(classifier_id)) {
return (BCM_E_UNAVAIL);
}
return bcm_esw_cosq_classifier_mapping_multi_set(unit, port, classifier_id,
queue_group, 1, &priority, &cosq);
}
/*
* Function:
* bcm_esw_cosq_classifier_mapping_multi_get
* Purpose:
* Get the mapping from port, classifier, and multiple internal priorities
* to multiple COS queues in a queue group.
* Parameters:
* unit - (IN) Unit number.
* port - (IN) GPORT ID
* classifier_id - (IN) Classifier ID
* queue_group - (OUT) Queue group
* array_max - (IN) Size of priority_array and cosq_array
* priority_array - (IN) Array of internal priorities
* cosq_array - (OUT) Array of COS queues
* array_count - (OUT) Size of cosq_array
* Returns:
* BCM_E_xxx
*/
int
bcm_esw_cosq_classifier_mapping_multi_get(
int unit,
bcm_gport_t port,
int classifier_id,
bcm_gport_t *queue_group,
int array_max,
bcm_cos_t *priority_array,
bcm_cos_queue_t *cosq_array,
int *array_count)
{
bcm_port_t local_port;
#ifdef BCM_TRIUMPH3_SUPPORT
if (_BCM_COSQ_CLASSIFIER_IS_FIELD(classifier_id)) {
if (soc_feature(unit, soc_feature_field_ingress_cosq_override)) {
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
return (bcm_kt2_cosq_field_classifier_map_get(unit,
classifier_id,
array_max,
priority_array,
cosq_array,
array_count));
} else
#endif
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return (bcm_th3_cosq_field_classifier_map_get(unit,
classifier_id,
array_max,
priority_array,
cosq_array,
array_count));
} else
#endif
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
return (bcm_th_cosq_field_classifier_map_get(unit,
classifier_id,
array_max,
priority_array,
cosq_array,
array_count));
} else
#endif
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
return (bcm_mn_cosq_field_classifier_map_get(unit,
classifier_id,
array_max,
priority_array,
cosq_array,
array_count));
} else
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
return (bcm_hx5_cosq_field_classifier_map_get(unit,
classifier_id,
array_max,
priority_array,
cosq_array,
array_count));
} else
#endif
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
return (bcm_td3_cosq_field_classifier_map_get(unit,
classifier_id,
array_max,
priority_array,
cosq_array,
array_count));
} else
#endif
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
return (bcm_ap_cosq_field_classifier_map_get(unit,
classifier_id,
array_max,
priority_array,
cosq_array,
array_count));
} else
#endif
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
return (bcm_td2_cosq_field_classifier_map_get(unit,
classifier_id,
array_max,
priority_array,
cosq_array,
array_count));
} else
#endif
{
return (bcm_tr3_cosq_field_classifier_map_get(unit,
classifier_id,
array_max,
priority_array,
cosq_array,
array_count));
}
} else {
return (BCM_E_UNAVAIL);
}
} else
#endif
{
if (BCM_GPORT_IS_SET(port)) {
BCM_IF_ERROR_RETURN(bcm_esw_port_local_get(unit, port,
&local_port));
} else if (SOC_PORT_VALID(unit, port)) {
local_port = port;
} else {
return BCM_E_PORT;
}
if (NULL == queue_group) {
return BCM_E_PARAM;
}
if (array_max > 0) {
if (NULL == priority_array || NULL == cosq_array) {
return BCM_E_PARAM;
}
if (NULL == array_count) {
return BCM_E_PARAM;
}
}
if (_BCM_COSQ_CLASSIFIER_IS_ENDPOINT(classifier_id)) {
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit) &&
soc_feature(unit, soc_feature_endpoint_queuing)) {
BCM_IF_ERROR_RETURN
(bcm_ap_cosq_endpoint_map_get(unit, local_port,
classifier_id,
queue_group,
array_max,
priority_array,
cosq_array,
array_count));
} else
#endif /* BCM_APACHE_SUPPORT */
#ifdef BCM_TRIDENT2_SUPPORT
if (soc_feature(unit, soc_feature_endpoint_queuing)) {
BCM_IF_ERROR_RETURN
(bcm_td2_cosq_endpoint_map_get(unit, local_port,
classifier_id,
queue_group,
array_max,
priority_array,
cosq_array,
array_count));
} else
#endif /* BCM_TRIDENT2_SUPPORT */
{
return BCM_E_PARAM;
}
} else if (_BCM_COSQ_CLASSIFIER_IS_SERVICE(classifier_id)) {
#ifdef BCM_TRIUMPH3_SUPPORT
if (soc_feature(unit, soc_feature_service_queuing)) {
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
BCM_IF_ERROR_RETURN
(bcm_kt2_cosq_service_map_get(unit, local_port,
classifier_id,
queue_group,
array_max,
priority_array,
cosq_array,
array_count));
} else
#endif
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
BCM_IF_ERROR_RETURN(
bcm_ap_cosq_service_map_get(unit, local_port,
classifier_id,
queue_group,
array_max,
priority_array,
cosq_array, array_count));
} else
#endif /* BCM_APACHE_SUPPORT */
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TRIDENT2(unit)
|| (SOC_IS_TRIDENT2PLUS(unit) || SOC_IS_TITAN2PLUS(unit))) {
BCM_IF_ERROR_RETURN(
bcm_td2_cosq_service_map_get(unit, local_port,
classifier_id,
queue_group,
array_max,
priority_array,
cosq_array, array_count));
} else
#endif /* BCM_TRIDENT2_SUPPORT */
{
BCM_IF_ERROR_RETURN
(bcm_tr3_cosq_service_map_get(unit, local_port,
classifier_id,
queue_group,
array_max,
priority_array,
cosq_array,
array_count));
}
} else
#endif /* BCM_TRIUMPH3_SUPPORT */
{
return BCM_E_UNAVAIL;
}
} else {
return BCM_E_PARAM;
}
}
return (BCM_E_NONE);
}
/*
* Function:
* bcm_esw_cosq_classifier_mapping_get
* Purpose:
* Get the mapping from port, classifier, and internal priority to a COS
* queue in a queue group.
* Parameters:
* unit - (IN) Unit number.
* port - (IN) GPORT ID
* classifier_id - (IN) Classifier ID
* queue_group - (OUT) Queue group
* priority - (IN) Internal priority
* cosq - (OUT) COS queue in queue group
* Returns:
* BCM_E_xxx
*/
int
bcm_esw_cosq_classifier_mapping_get(
int unit,
bcm_gport_t port,
int classifier_id,
bcm_gport_t *queue_group,
bcm_cos_t priority,
bcm_cos_queue_t *cosq)
{
int array_count;
if (_BCM_COSQ_CLASSIFIER_IS_FIELD(classifier_id)) {
return (BCM_E_UNAVAIL);
}
return bcm_esw_cosq_classifier_mapping_multi_get(unit, port, classifier_id,
queue_group, 1, &priority, cosq, &array_count);
}
/*
* Function:
* bcm_esw_cosq_classifier_mapping_clear
* Purpose:
* Clear the mapping from port, classifier, and internal priorities
* to COS queues in a queue group.
* Parameters:
* unit - (IN) Unit number.
* port - (IN) GPORT ID
* classifier_id - (IN) Classifier ID
* Returns:
* BCM_E_xxx
*/
int
bcm_esw_cosq_classifier_mapping_clear(
int unit,
bcm_gport_t port,
int classifier_id)
{
bcm_port_t local_port;
#ifdef BCM_TRIUMPH3_SUPPORT
if (_BCM_COSQ_CLASSIFIER_IS_FIELD(classifier_id)) {
if (soc_feature(unit, soc_feature_field_ingress_cosq_override)) {
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
BCM_IF_ERROR_RETURN
(bcm_kt2_cosq_field_classifier_map_clear(unit,
classifier_id));
} else
#endif
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
BCM_IF_ERROR_RETURN
(bcm_th3_cosq_field_classifier_map_clear(unit,
classifier_id));
} else
#endif
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
BCM_IF_ERROR_RETURN
(bcm_th_cosq_field_classifier_map_clear(unit,
classifier_id));
} else
#endif
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
BCM_IF_ERROR_RETURN
(bcm_mn_cosq_field_classifier_map_clear(unit,
classifier_id));
} else
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
BCM_IF_ERROR_RETURN
(bcm_hx5_cosq_field_classifier_map_clear(unit,
classifier_id));
} else
#endif
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
BCM_IF_ERROR_RETURN
(bcm_td3_cosq_field_classifier_map_clear(unit,
classifier_id));
} else
#endif
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
BCM_IF_ERROR_RETURN
(bcm_ap_cosq_field_classifier_map_clear(unit,
classifier_id));
} else
#endif
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
BCM_IF_ERROR_RETURN
(bcm_td2_cosq_field_classifier_map_clear(unit,
classifier_id));
} else
#endif
{
BCM_IF_ERROR_RETURN
(bcm_tr3_cosq_field_classifier_map_clear(unit,
classifier_id));
}
} else {
return (BCM_E_UNAVAIL);
}
} else
#endif
{
if (BCM_GPORT_IS_SET(port)) {
BCM_IF_ERROR_RETURN(bcm_esw_port_local_get(unit, port,
&local_port));
} else if (SOC_PORT_VALID(unit, port)) {
local_port = port;
} else {
return BCM_E_PORT;
}
if (_BCM_COSQ_CLASSIFIER_IS_ENDPOINT(classifier_id)) {
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit) &&
soc_feature(unit, soc_feature_endpoint_queuing)) {
BCM_IF_ERROR_RETURN
(bcm_ap_cosq_endpoint_map_clear(unit, local_port,
classifier_id));
} else
#endif /* BCM_APACHE_SUPPORT */
#ifdef BCM_TRIDENT2_SUPPORT
if (soc_feature(unit, soc_feature_endpoint_queuing)) {
BCM_IF_ERROR_RETURN
(bcm_td2_cosq_endpoint_map_clear(unit, local_port,
classifier_id));
} else
#endif /* BCM_TRIDENT2_SUPPORT */
{
return BCM_E_PARAM;
}
} else if (_BCM_COSQ_CLASSIFIER_IS_SERVICE(classifier_id)) {
#ifdef BCM_TRIUMPH3_SUPPORT
if (soc_feature(unit, soc_feature_service_queuing)) {
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
BCM_IF_ERROR_RETURN
(bcm_kt2_cosq_service_map_clear(unit, local_port,
classifier_id));
} else
#endif
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
BCM_IF_ERROR_RETURN(
bcm_ap_cosq_service_map_clear(unit, local_port,
classifier_id));
} else
#endif /* BCM_APACHE_SUPPORT */
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TRIDENT2(unit)
|| (SOC_IS_TRIDENT2PLUS(unit) || SOC_IS_TITAN2PLUS(unit))) {
BCM_IF_ERROR_RETURN(
bcm_td2_cosq_service_map_clear(unit, local_port,
classifier_id));
} else
#endif /* BCM_TRIDENT2_SUPPORT */
{
BCM_IF_ERROR_RETURN
(bcm_tr3_cosq_service_map_clear(unit, local_port,
classifier_id));
}
} else
#endif /* BCM_TRIUMPH3_SUPPORT */
{
return BCM_E_UNAVAIL;
}
} else {
return BCM_E_PARAM;
}
}
return (BCM_E_NONE);
}
int
bcm_esw_cosq_classifier_id_get(
int unit,
bcm_cosq_classifier_t *classifier,
int array_count,
bcm_cos_t *priority_array,
bcm_cos_queue_t *cosq_array,
int *classifier_id)
{
int rv = BCM_E_UNAVAIL;
if ((NULL == priority_array)||(NULL == cosq_array)||
(NULL == classifier_id) ||(NULL == classifier)||
( 0 == array_count)){
return BCM_E_PARAM;
}
#ifdef BCM_TRIUMPH3_SUPPORT
if (classifier->flags & BCM_COSQ_CLASSIFIER_FIELD) {
if (SOC_IS_TRIUMPH3(unit)){
rv = bcm_tr3_cosq_classifier_id_get(unit, classifier, array_count,
priority_array, cosq_array, classifier_id);
}
}
#endif
return rv;
}
/*
* Function:
* bcm_esw_cosq_cpu_cosq_enable_set
* Purpose:
* To enable/disable Rx of packets on the specified CPU cosq.
* Parameters:
* unit - (IN) Unit number.
* cosq - (IN) CPU Cosq ID
* enable - (IN) Enable/Disable
* Returns:
* BCM_E_xxx
*/
int
bcm_esw_cosq_cpu_cosq_enable_set(
int unit,
bcm_cos_queue_t cosq,
int enable)
{
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
BCM_IF_ERROR_RETURN(
bcm_th3_cosq_cpu_cosq_enable_set(unit, cosq, enable));
} else
#endif /* BCM_TOMAHAWK3_SUPPORT */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
BCM_IF_ERROR_RETURN(
bcm_th_cosq_cpu_cosq_enable_set(unit, cosq, enable));
} else
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
BCM_IF_ERROR_RETURN(
bcm_mn_cosq_cpu_cosq_enable_set(unit, cosq, enable));
} else
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
BCM_IF_ERROR_RETURN
(bcm_hx5_cosq_cpu_cosq_enable_set(unit, cosq, enable));
} else
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
BCM_IF_ERROR_RETURN
(bcm_td3_cosq_cpu_cosq_enable_set(unit, cosq, enable));
} else
#endif /* BCM_TRIDENT3_SUPPORT */
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)){
BCM_IF_ERROR_RETURN(
bcm_ap_cosq_cpu_cosq_enable_set(unit, cosq, enable));
} else
#endif /*BCM_APACHE_SUPPORT*/
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
BCM_IF_ERROR_RETURN(
bcm_td2_cosq_cpu_cosq_enable_set(unit, cosq, enable));
} else
#endif /* BCM_TRIDENT2_SUPPORT */
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
BCM_IF_ERROR_RETURN(
bcm_tr3_cosq_cpu_cosq_enable_set(unit, cosq, enable));
} else
#endif /* BCM_TRIUMPH3_SUPPORT */
#ifdef BCM_TRIDENT_SUPPORT
if (SOC_IS_TD_TT(unit)) {
BCM_IF_ERROR_RETURN(
bcm_td_cosq_cpu_cosq_enable_set(unit, cosq, enable));
} else
#endif /* BCM_TRIDENT_SUPPORT */
{
return BCM_E_UNAVAIL;
}
return BCM_E_NONE;
}
/*
* Function:
* bcm_esw_cosq_cpu_cosq_enable_get
* Purpose:
* To get enable/disable status on Rx of packets on the specified CPU cosq.
* Parameters:
* unit - (IN) Unit number.
* cosq - (IN) CPU Cosq ID
* enable - (OUT) Enable/Disable
* Returns:
* BCM_E_xxx
*/
int
bcm_esw_cosq_cpu_cosq_enable_get(
int unit,
bcm_cos_queue_t cosq,
int *enable)
{
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
BCM_IF_ERROR_RETURN(
bcm_th3_cosq_cpu_cosq_enable_get(unit, cosq, enable));
} else
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit) && !SOC_IS_TOMAHAWK3(unit)) {
BCM_IF_ERROR_RETURN(
bcm_th_cosq_cpu_cosq_enable_get(unit, cosq, enable));
} else
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
BCM_IF_ERROR_RETURN(
bcm_mn_cosq_cpu_cosq_enable_get(unit, cosq, enable));
} else
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
BCM_IF_ERROR_RETURN
(bcm_hx5_cosq_cpu_cosq_enable_get(unit, cosq, enable));
} else
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
BCM_IF_ERROR_RETURN
(bcm_td3_cosq_cpu_cosq_enable_get(unit, cosq, enable));
} else
#endif /* BCM_TRIDENT3_SUPPORT */
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
BCM_IF_ERROR_RETURN(
bcm_ap_cosq_cpu_cosq_enable_get(unit, cosq, enable));
} else
#endif /* BCM_APACHE_SUPPORT*/
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
BCM_IF_ERROR_RETURN(
bcm_td2_cosq_cpu_cosq_enable_get(unit, cosq, enable));
} else
#endif /* BCM_TRIDENT2_SUPPORT */
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
BCM_IF_ERROR_RETURN(
bcm_tr3_cosq_cpu_cosq_enable_get(unit, cosq, enable));
} else
#endif /* BCM_TRIUMPH3_SUPPORT */
#ifdef BCM_TRIDENT_SUPPORT
if (SOC_IS_TD_TT(unit)) {
BCM_IF_ERROR_RETURN(
bcm_td_cosq_cpu_cosq_enable_get(unit, cosq, enable));
} else
#endif /* BCM_TRIDENT_SUPPORT */
{
return BCM_E_UNAVAIL;
}
return BCM_E_NONE;
}
int
bcm_esw_cosq_service_pool_set(
int unit,
bcm_service_pool_id_t id,
bcm_cosq_service_pool_t cosq_service_pool)
{
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
BCM_IF_ERROR_RETURN(
bcm_th3_cosq_service_pool_set(unit, id, cosq_service_pool));
} else
#endif /* BCM_TOMAHAWK3_SUPPORT */
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
BCM_IF_ERROR_RETURN(
bcm_td2_cosq_service_pool_set(unit, id, cosq_service_pool));
} else
#endif /* BCM_TRIDENT2_SUPPORT */
{
return BCM_E_UNAVAIL;
}
return BCM_E_NONE;
}
int
bcm_esw_cosq_service_pool_get(
int unit,
bcm_service_pool_id_t id,
bcm_cosq_service_pool_t *cosq_service_pool)
{
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
BCM_IF_ERROR_RETURN(
bcm_th3_cosq_service_pool_get(unit, id, cosq_service_pool));
} else
#endif /* BCM_TOMAHAWK3_SUPPORT */
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TD2_TT2(unit)) {
BCM_IF_ERROR_RETURN(
bcm_td2_cosq_service_pool_get(unit, id, cosq_service_pool));
} else
#endif /* BCM_TRIDENT2_SUPPORT */
{
return BCM_E_UNAVAIL;
}
return BCM_E_NONE;
}
/*
* Function:
* bcm_esw_cosq_pfc_class_mapping_set
* Purpose:
* Set PFC mapping for port. PFC class is mapped to cosq or scheduler node gports.
* Parameters:
* unit - (IN) unit number
* port - (IN) port number
* array_count - (IN) count of mapping
* mapping_array - (IN) mappings
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_pfc_class_mapping_set(
int unit,
bcm_gport_t port,
int array_count,
bcm_cosq_pfc_class_mapping_t *mapping_array)
{
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
BCM_IF_ERROR_RETURN(
bcm_th_cosq_pfc_class_mapping_set(unit, port,
array_count, mapping_array));
} else
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
BCM_IF_ERROR_RETURN(
_bcm_mn_cosq_pfc_class_mapping_set(unit, port,
array_count, mapping_array));
} else
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
BCM_IF_ERROR_RETURN(
bcm_hx5_cosq_pfc_class_mapping_set(unit, port,
array_count, mapping_array));
} else
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
BCM_IF_ERROR_RETURN(
bcm_td3_cosq_pfc_class_mapping_set(unit, port,
array_count, mapping_array));
} else
#endif /* BCM_TRIDENT3_SUPPORT */
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
BCM_IF_ERROR_RETURN(
_bcm_ap_cosq_pfc_class_mapping_set(unit, port,
array_count, mapping_array));
} else
#endif /* BCM_APACHE_SUPPORT */
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TITAN2X(unit)) {
BCM_IF_ERROR_RETURN(
bcm_td2_cosq_pfc_class_mapping_set(unit, port,
array_count, mapping_array));
} else
#endif /* BCM_TRIDENT2_SUPPORT */
#ifdef BCM_TRIDENT_SUPPORT
if (SOC_IS_TRIDENT(unit)) {
BCM_IF_ERROR_RETURN(
bcm_td_cosq_pfc_class_mapping_set(unit, port,
array_count, mapping_array));
} else
#endif /* BCM_TRIDENT_SUPPORT */
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
BCM_IF_ERROR_RETURN(
bcm_kt2_cosq_pfc_class_mapping_set(unit, port,
array_count, mapping_array));
} else
#endif /* BCM_KATANA2_SUPPORT */
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
BCM_IF_ERROR_RETURN(
bcm_tr3_cosq_pfc_class_mapping_set(unit, port,
array_count, mapping_array));
} else
#endif /* BCM_TRIUMPH3_SUPPORT */
{
return BCM_E_UNAVAIL;
}
return BCM_E_NONE;
}
/*
* Function:
* bcm_esw_cosq_pfc_class_mapping_get
* Purpose:
* Get PFC mapping of a port.
* Retrieves cosq or scheduler node gports associated to PFC classes.
* Parameters:
* unit - (IN) unit number
* port - (IN) port number
* array_max - (IN) max retrieve count
* mapping_array - (OUT) mappings
* array_count - (OUT) retrieved mapping count
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_pfc_class_mapping_get(
int unit,
bcm_gport_t port,
int array_max,
bcm_cosq_pfc_class_mapping_t *mapping_array,
int *array_count)
{
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
BCM_IF_ERROR_RETURN(
bcm_th_cosq_pfc_class_mapping_get(unit, port, array_max,
mapping_array, array_count));
} else
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
BCM_IF_ERROR_RETURN(
_bcm_mn_cosq_pfc_class_mapping_get(unit, port, array_max,
array_count, mapping_array));
} else
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
BCM_IF_ERROR_RETURN(
bcm_hx5_cosq_pfc_class_mapping_get(unit, port, array_max,
mapping_array,array_count));
} else
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
BCM_IF_ERROR_RETURN(
bcm_td3_cosq_pfc_class_mapping_get(unit, port, array_max,
mapping_array,array_count));
} else
#endif /* BCM_TRIDENT3_SUPPORT */
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
BCM_IF_ERROR_RETURN(
_bcm_ap_cosq_pfc_class_mapping_get(unit, port, array_max,
array_count, mapping_array));
} else
#endif
#ifdef BCM_TRIDENT2_SUPPORT
if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TITAN2X(unit)) {
BCM_IF_ERROR_RETURN(
bcm_td2_cosq_pfc_class_mapping_get(unit, port, array_max,
mapping_array, array_count));
} else
#endif /* BCM_TRIDENT2_SUPPORT */
#ifdef BCM_TRIDENT_SUPPORT
if (SOC_IS_TRIDENT(unit)) {
BCM_IF_ERROR_RETURN(
bcm_td_cosq_pfc_class_mapping_get(unit, port, array_max,
mapping_array, array_count));
} else
#endif /* BCM_TRIDENT_SUPPORT */
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
BCM_IF_ERROR_RETURN(
bcm_kt2_cosq_pfc_class_mapping_get(unit, port, array_max,
array_count, mapping_array));
} else
#endif
#ifdef BCM_TRIUMPH3_SUPPORT
if (SOC_IS_TRIUMPH3(unit)) {
BCM_IF_ERROR_RETURN(
bcm_tr3_cosq_pfc_class_mapping_get(unit, port, array_max,
mapping_array, array_count));
} else
#endif
{
return BCM_E_UNAVAIL;
}
return BCM_E_NONE;
}
/*
* Function:
* bcm_esw_cosq_safc_class_mapping_set
* Purpose:
* Set SAFC mapping for port. SAFC class
* is mapped to cosq or scheduler node gports.
* Parameters:
* unit - (IN) unit number
* port - (IN) port number
* array_count - (IN) count of mapping
* mapping_array - (IN) mappings
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_safc_class_mapping_set(
int unit,
bcm_gport_t port,
int array_count,
bcm_cosq_safc_class_mapping_t *mapping_array)
{
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
BCM_IF_ERROR_RETURN(
bcm_th_cosq_safc_class_mapping_set(unit, port,
array_count, mapping_array));
} else
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
BCM_IF_ERROR_RETURN(
bcm_hx5_cosq_safc_class_mapping_set(unit, port,
array_count, mapping_array));
} else
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
BCM_IF_ERROR_RETURN(
bcm_td3_cosq_safc_class_mapping_set(unit, port,
array_count, mapping_array));
} else
#endif /* BCM_TRIDENT3_SUPPORT */
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
BCM_IF_ERROR_RETURN(
bcm_kt2_cosq_safc_class_mapping_set(unit, port,
array_count, mapping_array));
} else
#endif
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
BCM_IF_ERROR_RETURN(
_bcm_mn_cosq_safc_class_mapping_set(unit, port,
array_count, mapping_array));
} else
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
BCM_IF_ERROR_RETURN(
_bcm_ap_cosq_safc_class_mapping_set(unit, port,
array_count, mapping_array));
} else
#endif
{
return BCM_E_UNAVAIL;
}
return BCM_E_NONE;
}
/*
* Function:
* bcm_esw_cosq_safc_class_mapping_get
* Purpose:
* Get SAFC mapping of a port.
* Retrieves cosq or scheduler node
* gports associated to SAFC classes.
* Parameters:
* unit - (IN) unit number
* port - (IN) port number
* array_max - (IN) max retrieve count
* mapping_array - (OUT) mappings
* array_count - (OUT) retrieved mapping count
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_safc_class_mapping_get(
int unit,
bcm_gport_t port,
int array_max,
bcm_cosq_safc_class_mapping_t *mapping_array,
int *array_count)
{
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
BCM_IF_ERROR_RETURN(
bcm_th_cosq_safc_class_mapping_get(unit, port, array_max,
mapping_array, array_count));
} else
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
BCM_IF_ERROR_RETURN(
bcm_hx5_cosq_safc_class_mapping_get(unit, port, array_max,
mapping_array, array_count));
} else
#endif /* BCM_TRIDENT3_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
BCM_IF_ERROR_RETURN(
bcm_td3_cosq_safc_class_mapping_get(unit, port, array_max,
mapping_array, array_count));
} else
#endif /* BCM_TRIDENT3_SUPPORT */
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
BCM_IF_ERROR_RETURN(
bcm_kt2_cosq_safc_class_mapping_get(unit, port, array_max,
array_count, mapping_array ));
} else
#endif
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
BCM_IF_ERROR_RETURN(
_bcm_mn_cosq_safc_class_mapping_get(unit, port, array_max,
mapping_array, array_count));
} else
#endif /* BCM_MONTEREY_SUPPORT */
#ifdef BCM_APACHE_SUPPORT
if (SOC_IS_APACHE(unit)) {
BCM_IF_ERROR_RETURN(
_bcm_ap_cosq_safc_class_mapping_get(unit, port, array_max,
mapping_array, array_count));
} else
#endif
{
return BCM_E_UNAVAIL;
}
return BCM_E_NONE;
}
/*
* Function:
* bcm_esw_cosq_pfc_deadlock_config_set
* Purpose:
* Setup PFC deadlock feature to monitor for the given priority with
* associated values.
* Parameters:
* unit - (IN) unit number
* priority - (IN) priority
* config - (IN) Config for a given priority
* Returns:
* BCM_E_XXX
*/
int bcm_esw_cosq_pfc_deadlock_config_set(
int unit,
int priority,
bcm_cosq_pfc_deadlock_config_t *config)
{
#ifdef BCM_TOMAHAWK3_SUPPORT
if(SOC_IS_TOMAHAWK3(unit)) {
return BCM_E_UNAVAIL;
}
#endif
if (soc_feature(unit, soc_feature_pfc_deadlock)) {
return _bcm_pfc_deadlock_config_set(unit, priority, config);
} else {
return BCM_E_UNAVAIL;
}
}
/*
* Function:
* bcm_esw_cosq_pfc_deadlock_config_get
* Purpose:
* Get config values for a given priority in PFC deadlock feature.
* Parameters:
* unit - (IN) unit number
* priority - (IN) priority
* config - (OUT) Config for a given priority
* Returns:
* BCM_E_XXX
*/
int bcm_esw_cosq_pfc_deadlock_config_get(
int unit,
int priority,
bcm_cosq_pfc_deadlock_config_t *config)
{
#ifdef BCM_TOMAHAWK3_SUPPORT
if(SOC_IS_TOMAHAWK3(unit)) {
return BCM_E_UNAVAIL;
}
#endif
if (soc_feature(unit, soc_feature_pfc_deadlock)) {
return _bcm_pfc_deadlock_config_get(unit, priority, config);
} else {
return BCM_E_UNAVAIL;
}
}
/*
* Function:
* bcm_esw_cosq_pfc_deadlock_info_get
* Purpose:
* Get bitmap of Enabled(Admin) and Current Deadlock ports status for a
* given priority in PFC deadlock feature.
* Parameters:
* unit - (IN) unit number
* priority - (IN) priority
* info - (OUT) Info for a given priority
* Returns:
* BCM_E_XXX
*/
int bcm_esw_cosq_pfc_deadlock_info_get(
int unit,
int priority,
bcm_cosq_pfc_deadlock_info_t *pfc_deadlock_info)
{
if (soc_feature(unit, soc_feature_pfc_deadlock)) {
#ifdef BCM_TOMAHAWK3_SUPPORT
if(SOC_IS_TOMAHAWK3(unit)) {
return _bcm_th3_pfc_deadlock_info_get(unit, priority, pfc_deadlock_info);
} else
#endif
{
return _bcm_pfc_deadlock_info_get(unit, priority, pfc_deadlock_info);
}
} else {
return BCM_E_UNAVAIL;
}
}
/*
* Function:
* bcm_esw_cosq_pfc_deadlock_queue_config_set
* Purpose:
* Enable or disable the given Port/Queue for PFC deadlock feature to
* monitor.
* Parameters:
* unit - (IN) unit number
* priority - (IN) priority
* config - (IN) Config for a given UC Queue Gport
* Returns:
* BCM_E_XXX
*/
int bcm_esw_cosq_pfc_deadlock_queue_config_set(
int unit,
bcm_gport_t gport,
bcm_cosq_pfc_deadlock_queue_config_t *q_config)
{
#ifdef BCM_TOMAHAWK3_SUPPORT
if(SOC_IS_TOMAHAWK3(unit)) {
return BCM_E_UNAVAIL;
}
#endif
if (soc_feature(unit, soc_feature_pfc_deadlock)) {
return _bcm_pfc_deadlock_queue_config_set(unit, gport, q_config);
} else {
return BCM_E_UNAVAIL;
}
}
/*
* Function:
* bcm_esw_cosq_pfc_deadlock_queue_config_get
* Purpose:
* Get the Enable or disable monitoring status for the given Port/Queue.
* Parameters:
* unit - (IN) unit number
* priority - (IN) priority
* config - (OUT) Config for a given UC Queue Gport
* Returns:
* BCM_E_XXX
*/
int bcm_esw_cosq_pfc_deadlock_queue_config_get(
int unit,
bcm_gport_t gport,
bcm_cosq_pfc_deadlock_queue_config_t *q_config)
{
#ifdef BCM_TOMAHAWK3_SUPPORT
if(SOC_IS_TOMAHAWK3(unit)) {
return BCM_E_UNAVAIL;
}
#endif
if (soc_feature(unit, soc_feature_pfc_deadlock)) {
return _bcm_pfc_deadlock_queue_config_get(unit, gport, q_config);
} else {
return BCM_E_UNAVAIL;
}
}
/*
* Function:
* bcm_esw_cosq_pfc_deadlock_queue_status_get
* Purpose:
* Get the current Deadlock status for the given Port/Queue.
* Parameters:
* unit - (IN) unit number
* priority - (IN) priority
* deadlock_status - (OUT) Deatlock status for the given UC Queue Gport
* Returns:
* BCM_E_XXX
*/
int bcm_esw_cosq_pfc_deadlock_queue_status_get(
int unit,
bcm_gport_t gport,
uint8 *deadlock_status)
{
if (soc_feature(unit, soc_feature_pfc_deadlock)) {
#ifdef BCM_TOMAHAWK3_SUPPORT
if(SOC_IS_TOMAHAWK3(unit)) {
return _bcm_th3_pfc_deadlock_port_status_get
(unit, gport, deadlock_status);
}
#endif
return _bcm_pfc_deadlock_queue_status_get(unit, gport, deadlock_status);
} else {
return BCM_E_UNAVAIL;
}
}
/*
* Function:
* bcmi_esw_cosq_handle_interrupt
* Purpose:
* Internal interrupt event callback function to invoke registered callback
* function (by bcm_esw_cosq_event_register).
* Parameters:
* unit - (IN) unit number
* event - (IN) event which trigger the interrupt.
* port - (IN) port which event happened. If the event is
* system wise or not port related, port = -1.
* cosq - (IN) cosq which event happened. If the event is
* system wise or not cosq related, cosq = -1.
* Returns:
* BCM_E_XXX
*/
int
bcmi_esw_cosq_handle_interrupt(int unit,
bcm_cosq_event_type_t event,
bcm_port_t port,
bcm_cos_queue_t cosq)
{
cosq_event_handler_t *e_handler;
bcm_gport_t gport;
uint8 do_cb = 0, pbmp_valid, qbmp_valid, port_match, cosq_match;
int rv = BCM_E_NONE;
COSQ_EVENT_LOCK(unit);
for (e_handler = cosq_event_handler_list[unit];
e_handler != NULL;
e_handler = e_handler->next) {
if (BCM_COSQ_EVENT_TYPE_GET(e_handler->event_types, event)){
pbmp_valid = 0;
qbmp_valid = 0;
port_match = 0;
cosq_match = 0;
if (port != -1) {
pbmp_valid = !SHR_BITNULL_RANGE(e_handler->pbmp, 0,
SOC_MAX_NUM_PORTS);
port_match = SHR_BITGET(e_handler->pbmp, port) ? 1 : 0;
}
if (cosq != -1) {
qbmp_valid = !SHR_BITNULL_RANGE(e_handler->qbmp, 0,
BCM_COS_COUNT);
cosq_match = SHR_BITGET(e_handler->qbmp, cosq) ? 1 : 0;
}
if (port == -1) {
gport = BCM_GPORT_INVALID;
} else {
rv = bcm_esw_port_gport_get(unit, port, &gport);
if (BCM_FAILURE (rv)) {
COSQ_EVENT_UNLOCK(unit);
return rv;
}
}
if (pbmp_valid && qbmp_valid) {
/* If pbmp and qbmp are specified, invoke cb
* when port/cosq both matched */
if (port_match && cosq_match) {
do_cb = 1;
}
} else if (pbmp_valid || qbmp_valid) {
if (pbmp_valid && port_match) {
do_cb = 1;
}
if (qbmp_valid && cosq_match) {
do_cb = 1;
}
} else {
do_cb = 1;
}
if (do_cb){
if (e_handler->cb != NULL) {
e_handler->cb(unit, event, gport, cosq,
e_handler->user_data);
}
}
}
}
COSQ_EVENT_UNLOCK(unit);
return BCM_E_NONE;
}
STATIC int
bcmi_esw_cosq_event_mask_set(int unit, bcm_cosq_event_type_t event_type,
int val)
{
/* Interrupt mask definitions are device specific. */
#ifdef BCM_GREYHOUND2_SUPPORT
if (SOC_IS_GREYHOUND2(unit)) {
return bcmi_gh2_cosq_event_mask_set(unit, event_type, val);
}
#endif
return BCM_E_UNAVAIL;
}
STATIC int
bcmi_esw_cosq_events_validate(int unit, bcm_cosq_event_types_t event_types)
{
/* Event support validation(checking) is device specific.*/
#ifdef BCM_GREYHOUND2_SUPPORT
if (SOC_IS_GREYHOUND2(unit)) {
return bcmi_gh2_cosq_events_validate(unit, event_types);
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_pfc_deadlock_callback_register
* Purpose:
* Register pfc deadlock recovery callback in PFC deadlock feature.
* Parameters:
* unit - (IN) unit number
* callback - (IN) callback function
* userdata - (IN) user data
* Returns:
* BCM_E_XXX
*/
int bcm_esw_cosq_pfc_deadlock_recovery_event_register(
int unit,
bcm_cosq_pfc_deadlock_recovery_event_cb_t callback,
void *userdata)
{
if (soc_feature(unit, soc_feature_pfc_deadlock)) {
return _bcm_cosq_pfc_deadlock_recovery_event_register(unit, callback, userdata);
} else {
return BCM_E_UNAVAIL;
}
}
/*
* Function:
* bcm_esw_cosq_pfc_deadlock_recovery_start
* Purpose:
* Start pfc deadlock recovery.
* Parameters:
* unit - (IN) unit number
* port - (IN) port number
* pri - (IN) priority
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_pfc_deadlock_recovery_start(int unit, bcm_port_t port,
bcm_cos_t pri)
{
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
if (soc_property_get(unit, spn_PFC_DEADLOCK_SEQ_CONTROL, 0)) {
return bcm_th3_pfc_deadlock_recovery_start(unit, port, pri);
}
}
#endif
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
if (soc_property_get(unit, spn_PFC_DEADLOCK_SEQ_CONTROL, 0)) {
return bcm_th_pfc_deadlock_recovery_start(unit, port, pri);
}
}
#endif
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
if (soc_property_get(unit, spn_PFC_DEADLOCK_SEQ_CONTROL, 0)) {
return bcm_hx5_pfc_deadlock_recovery_start(unit, port, pri);
}
}
#endif
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
if (soc_property_get(unit, spn_PFC_DEADLOCK_SEQ_CONTROL, 0)) {
return bcm_td3_pfc_deadlock_recovery_start(unit, port, pri);
}
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_pfc_deadlock_recovery_exit
* Purpose:
* Exit pfc deadlock recovery.
* Parameters:
* unit - (IN) unit number
* port - (IN) port number
* pri - (IN) priority
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_pfc_deadlock_recovery_exit(int unit, bcm_port_t port,
bcm_cos_t pri)
{
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
if (soc_property_get(unit, spn_PFC_DEADLOCK_SEQ_CONTROL, 0)) {
return bcm_th3_pfc_deadlock_recovery_exit(unit, port, pri);
}
}
#endif
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
if (soc_property_get(unit, spn_PFC_DEADLOCK_SEQ_CONTROL, 0)) {
return bcm_th_pfc_deadlock_recovery_exit(unit, port, pri);
}
}
#endif
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
if (soc_property_get(unit, spn_PFC_DEADLOCK_SEQ_CONTROL, 0)) {
return bcm_hx5_pfc_deadlock_recovery_exit(unit, port, pri);
}
}
#endif
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
if (soc_property_get(unit, spn_PFC_DEADLOCK_SEQ_CONTROL, 0)) {
return bcm_td3_pfc_deadlock_recovery_exit(unit, port, pri);
}
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_pfc_deadlock_callback_unregister
* Purpose:
* Unregister pfc deadlock recovery callback in PFC deadlock feature.
* Parameters:
* unit - (IN) unit number
* callback - (IN) callback function
* userdata - (IN) user data
* Returns:
* BCM_E_XXX
*/
int bcm_esw_cosq_pfc_deadlock_recovery_event_unregister(
int unit,
bcm_cosq_pfc_deadlock_recovery_event_cb_t callback,
void *userdata)
{
if (soc_feature(unit, soc_feature_pfc_deadlock)) {
return _bcm_cosq_pfc_deadlock_recovery_event_unregister(unit, callback, userdata);
} else {
return BCM_E_UNAVAIL;
}
}
/*
* Function:
* bcm_esw_cosq_buffer_id_multi_get
* Purpose:
* Get mutliple buffer ids associated with a specified port.
* Parameters:
* unit - (IN) BCM device number.
* gport - (IN) Port
* cosq - (IN) Reserved field
* direction - (IN) Specify ingress or egress direction
* array_max - (IN) number of entries to be retrieved
* buf_id_array - (OUT) Buffer id array
* array_count - (OUT) Actural buffer id count in buf_id_array
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_buffer_id_multi_get(int unit,
bcm_gport_t gport,
bcm_cos_queue_t cosq,
bcm_cosq_dir_t direction,
int array_max,
bcm_cosq_buffer_id_t *buf_id_array,
int *array_count)
{
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
return bcm_th3_cosq_buffer_id_multi_get(unit, gport, cosq, direction,
array_max, buf_id_array, array_count);
}
#endif
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
return bcm_th_cosq_buffer_id_multi_get(unit, gport, 0, direction,
array_max, buf_id_array, array_count);
}
#endif
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
return bcm_hx5_cosq_buffer_id_multi_get(unit, gport, 0, direction,
array_max, buf_id_array, array_count);
} else
#endif
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit)) {
return bcm_td3_cosq_buffer_id_multi_get(unit, gport, 0, direction,
array_max, buf_id_array, array_count);
}
#endif
return BCM_E_UNAVAIL;
}
STATIC int
bcmi_esw_cosq_event_unregister_all(int unit)
{
cosq_event_handler_t *e_handler;
cosq_event_handler_t *e_handler_to_delete;
COSQ_EVENT_LOCK(unit);
e_handler = cosq_event_handler_list[unit];
while (e_handler != NULL) {
e_handler_to_delete = e_handler;
e_handler = e_handler->next;
sal_free(e_handler_to_delete);
}
cosq_event_handler_list[unit] = NULL;
COSQ_EVENT_UNLOCK(unit);
return BCM_E_NONE;
}
STATIC int
bcmi_esw_cosq_event_deinit(int unit)
{
if (cosq_event_handler_list[unit] != NULL) {
bcmi_esw_cosq_event_unregister_all(unit);
}
sal_memset(&cosq_event_handler_count[unit], 0,
sizeof(int) * bcmCosqEventCount);
if (cosq_event_lock[unit] != NULL) {
sal_mutex_destroy(cosq_event_lock[unit]);
cosq_event_lock[unit] = NULL;
}
return BCM_E_NONE;
}
STATIC int
bcmi_esw_cosq_event_init(int unit)
{
int i;
if (cosq_event_initialized == 0) {
for (i = 0; i < SOC_MAX_NUM_DEVICES; i ++) {
cosq_event_lock[i] = NULL;
cosq_event_handler_list[i] = NULL;
sal_memset(&cosq_event_handler_count[i], 0,
sizeof(int) * bcmCosqEventCount);
}
cosq_event_initialized = 1;
} else {
BCM_IF_ERROR_RETURN(bcmi_esw_cosq_event_deinit(unit));
}
if (cosq_event_lock[unit] == NULL) {
cosq_event_lock[unit] = sal_mutex_create("cosq event lock");
if (cosq_event_lock[unit] == NULL) {
return BCM_E_MEMORY;
}
}
return BCM_E_NONE;
}
/*
* Function:
* bcm_esw_cosq_event_register
* Purpose:
* The callback function registration by specifying port or traffic class to
* handle the COSQ events.
* Parameters:
* unit - (IN) unit number
* event_types - (IN) The set of Cosq events for which the specified
* callback should be invoked.
* port - (IN) gport id
* cosq - (IN) cos queue
* cb - (IN) callback function
* user_data - (IN) Pinter to user data to supply in the callback.
* Returns:
* BCM_E_XXX
* Notes:
* If the event is not on port or traffic class basis, the gport and cosq
* value should be -1.
* If user do not want to register the event on specific port or queue basis,
* The gport or cosq value should assign to -1.
*/
int
bcm_esw_cosq_event_register(
int unit,
bcm_cosq_event_types_t event_types,
bcm_gport_t port,
bcm_cos_queue_t cosq,
bcm_cosq_event_cb cb,
void *user_data)
{
cosq_event_handler_t *e_handler;
cosq_event_handler_t *previous = NULL;
bcm_cosq_event_type_t e_type;
int result;
int rv = BCM_E_NONE;
bcm_port_t lport;
if (cb == NULL) {
return BCM_E_PARAM;
}
SHR_BITTEST_RANGE(event_types.w, 0, bcmCosqEventCount, result);
if (result == 0) {
return BCM_E_PARAM;
}
BCM_IF_ERROR_RETURN(bcmi_esw_cosq_events_validate(unit, event_types));
if (port != BCM_GPORT_INVALID) {
BCM_IF_ERROR_RETURN(
_bcm_esw_port_gport_validate(unit, port, &lport));
}
BCM_IF_ERROR_RETURN(_bcm_esw_cosq_num_validate(cosq, NUM_COS(unit)));
COSQ_EVENT_LOCK(unit);
for (e_handler = cosq_event_handler_list[unit];
e_handler != NULL;
e_handler = e_handler->next) {
if (e_handler->cb == cb) {
break;
}
previous = e_handler;
}
if (e_handler == NULL) {
/* This handler hasn't been registered yet */
e_handler = sal_alloc(sizeof(*e_handler), "Cosq event handler");
if (e_handler == NULL) {
COSQ_EVENT_UNLOCK(unit);
return BCM_E_MEMORY;
}
sal_memset(e_handler, 0, sizeof(*e_handler));
e_handler->next = NULL;
e_handler->cb = cb;
if (previous != NULL) {
previous->next = e_handler;
} else {
cosq_event_handler_list[unit] = e_handler;
}
}
for (e_type = 0; e_type < bcmCosqEventCount; ++e_type) {
if (BCM_COSQ_EVENT_TYPE_GET(event_types, e_type)) {
if (!BCM_COSQ_EVENT_TYPE_GET(e_handler->event_types, e_type)) {
/* This handler isn't handling this event yet */
BCM_COSQ_EVENT_TYPE_SET(e_handler->event_types, e_type);
if (cosq_event_handler_count[unit][e_type] == 0) {
rv = bcmi_esw_cosq_event_mask_set(unit, e_type, 1);
if (BCM_FAILURE(rv)) {
COSQ_EVENT_UNLOCK(unit);
return rv;
}
}
cosq_event_handler_count[unit][e_type] += 1;
}
}
}
e_handler->user_data = user_data;
if (port != BCM_GPORT_INVALID) {
SHR_BITSET(e_handler->pbmp, lport);
} else {
/* clear bitmap */
SHR_BITCLR_RANGE(e_handler->pbmp, 0, SOC_MAX_NUM_PORTS);
}
if (cosq != BCM_COS_INVALID) {
SHR_BITSET(e_handler->qbmp, cosq);
} else {
/* clear bitmap */
SHR_BITCLR_RANGE(e_handler->qbmp, 0, BCM_COS_COUNT);
}
COSQ_EVENT_UNLOCK(unit);
return rv;
}
/*
* Function:
* bcm_esw_cosq_event_unregister
* Purpose:
* The callback function unregistration of COSQ events by specifying port or
* traffic class.
* Parameters:
* unit - (IN) unit number
* event_types - (IN) The set of Cosq events for which the specified
* callback should be invoked.
* port - (IN) gport id
* cosq - (IN) cos queue
* cb - (IN) callback function
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_event_unregister(
int unit,
bcm_cosq_event_types_t event_types,
bcm_gport_t port,
bcm_cos_queue_t cosq,
bcm_cosq_event_cb cb)
{
cosq_event_handler_t *e_handler;
cosq_event_handler_t *previous = NULL;
bcm_cosq_event_type_t e_type;
int result;
int rv = BCM_E_NONE;
bcm_port_t lport;
uint8 pbmp_valid = 0, qbmp_valid = 0;
if (cb == NULL) {
return BCM_E_PARAM;
}
SHR_BITTEST_RANGE(event_types.w, 0, bcmCosqEventCount, result);
if (result == 0) {
return BCM_E_PARAM;
}
if (port != BCM_GPORT_INVALID) {
BCM_IF_ERROR_RETURN(
_bcm_esw_port_gport_validate(unit, port, &lport));
}
BCM_IF_ERROR_RETURN(_bcm_esw_cosq_num_validate(cosq, NUM_COS(unit)));
COSQ_EVENT_LOCK(unit);
for (e_handler = cosq_event_handler_list[unit];
e_handler != NULL;
e_handler = e_handler->next) {
/* Find the e_handler by specified cb */
if (e_handler->cb == cb) {
break;
}
previous = e_handler;
}
if (e_handler == NULL) {
/* Could not find the registed e_handler */
COSQ_EVENT_UNLOCK(unit);
return BCM_E_NOT_FOUND;
}
for (e_type = 0; e_type < bcmCosqEventCount; ++e_type) {
if (BCM_COSQ_EVENT_TYPE_GET(event_types, e_type)) {
/* Iterate the specified events */
if ((BCM_COSQ_EVENT_TYPE_GET(e_handler->event_types, e_type)) &&
(cosq_event_handler_count[unit][e_type] > 0)) {
/* Check if the event was among the registered events. */
cosq_event_handler_count[unit][e_type] -= 1;
BCM_COSQ_EVENT_TYPE_CLEAR(e_handler->event_types, e_type);
/* Clear event mask when event is not associated with others.*/
if (cosq_event_handler_count[unit][e_type] == 0) {
rv = bcmi_esw_cosq_event_mask_set(unit, e_type, 0);
if (BCM_FAILURE(rv)) {
COSQ_EVENT_UNLOCK(unit);
return rv;
}
}
}
}
}
SHR_BITTEST_RANGE(e_handler->event_types.w, 0, bcmCosqEventCount, result);
if (0 == result) {
/* Free the handler if no more events for this handler to handle */
if (previous != NULL) {
previous->next = e_handler->next;
} else {
cosq_event_handler_list[unit] = e_handler->next;
}
sal_free(e_handler);
} else {
pbmp_valid = !SHR_BITNULL_RANGE(e_handler->pbmp, 0,
SOC_MAX_NUM_PORTS);
/* Ignore events associated with certain port */
if (port != BCM_GPORT_INVALID) {
if (!pbmp_valid) {
/* The orginal registered to ignore port case.
set bitmaps to 1 */
SHR_BITSET_RANGE(e_handler->pbmp, 0, SOC_MAX_NUM_PORTS);
}
SHR_BITCLR(e_handler->pbmp, lport);
}
qbmp_valid = !SHR_BITNULL_RANGE(e_handler->qbmp, 0,
BCM_COS_COUNT);
/* Ignore events associated with certian cosq */
if (cosq != BCM_COS_INVALID) {
if (!qbmp_valid) {
/* The orginal registered to ignore cosq case.
set bitmaps to 1 */
SHR_BITSET_RANGE(e_handler->qbmp, 0, BCM_COS_COUNT);
}
SHR_BITCLR(e_handler->qbmp, cosq);
}
}
COSQ_EVENT_UNLOCK(unit);
return BCM_E_NONE;
}
/*
* Function:
* bcm_esw_cosq_tas_control_get
* Purpose:
* Get various configurations for TAS.
* Parameters:
* unit - (IN) unit number
* port - (IN) gport id
* type - (IN) tas control type defined in bcm_cos_tas_control_t
* arg - (OUT) tas control value
* Returns:
* BCM_E_XXX
* Notes:
* Most of the TAS configurations are on port basis. For some configuration
* which is on system basis, the gport should assign to -1.
*/
int
bcm_esw_cosq_tas_control_get(
int unit,
bcm_gport_t port,
bcm_cosq_tas_control_t type,
int *arg)
{
#ifdef BCM_TAS_SUPPORT
if (soc_feature(unit, soc_feature_tas)) {
return bcmi_esw_tas_control_get(unit, port, type, arg);
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_tas_control_set
* Purpose:
* Set various configurations for TAS.
* Parameters:
* unit - (IN) unit number
* port - (IN) gport id
* type - (IN) tas control type defined in bcm_cos_tas_control_t
* arg - (IN) tas control value
* Returns:
* BCM_E_XXX
* Notes:
* Most of the TAS configurations are on port basis. For some configuration
* which is on system basis, the gport should assign to -1.
*/
int
bcm_esw_cosq_tas_control_set(
int unit,
bcm_gport_t port,
bcm_cosq_tas_control_t type,
int arg)
{
#ifdef BCM_TAS_SUPPORT
if (soc_feature(unit, soc_feature_tas)) {
return bcmi_esw_tas_control_set(unit, port, type, arg);
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_tas_status_get
* Purpose:
* Get TAS status by specifying the type.
* Parameters:
* unit - (IN) unit number
* port - (IN) gport id
* type - (IN) tas status type defined in bcm_cos_tas_status_t
* arg - (OUT) tas status value
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_tas_status_get(
int unit,
bcm_gport_t port,
bcm_cosq_tas_status_t type,
int *arg)
{
#ifdef BCM_TAS_SUPPORT
if (soc_feature(unit, soc_feature_tas)) {
return bcmi_esw_tas_status_get(unit, port, type, arg);
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_tas_profile_commit
* Purpose:
* Commit the profile to indicate the profile is ready to write to hardware.
* Parameters:
* unit - (IN) unit number
* port - (IN) gport id
* pid - (IN) profile id
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_tas_profile_commit(
int unit,
bcm_gport_t port,
bcm_cosq_tas_profile_id_t pid)
{
#ifdef BCM_TAS_SUPPORT
if (soc_feature(unit, soc_feature_tas)) {
return bcmi_esw_tas_profile_commit(unit, port, pid);
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_tas_profile_create
* Purpose:
* Create a profile by specifying the profile settings including calendar
* table, ptp time information for PTP mode.
* A profile id will be assigned along with the settings.
* Parameters:
* unit - (IN) unit number
* port - (IN) gport id
* profile - (IN) Pointer to profile structure which specifies
* entries in calendar table, ptp time information
* for PTP mode
* pid - (OUT) profile id
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_tas_profile_create(
int unit,
bcm_gport_t port,
bcm_cosq_tas_profile_t *profile,
bcm_cosq_tas_profile_id_t *pid)
{
#ifdef BCM_TAS_SUPPORT
if (soc_feature(unit, soc_feature_tas)) {
return bcmi_esw_tas_profile_create(unit, port, profile, pid);
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_tas_profile_get
* Purpose:
* Get the profile information by specifying the profile id.
* Parameters:
* unit - (IN) unit number
* port - (IN) gport id
* pid - (IN) profile id
* profile - (OUT) pointer to profile structure
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_tas_profile_get(
int unit,
bcm_gport_t port,
bcm_cosq_tas_profile_id_t pid,
bcm_cosq_tas_profile_t *profile)
{
#ifdef BCM_TAS_SUPPORT
if (soc_feature(unit, soc_feature_tas)) {
return bcmi_esw_tas_profile_get(unit, port, pid, profile);
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_tas_profile_set
* Purpose:
* Modify the profile information
* NOTE:
* This API is used to modify the profile if needed before doing commit.
* Parameters:
* unit - (IN) unit number
* port - (IN) gport id
* pid - (IN) profile id
* profile - (IN) pointer to profile structure
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_tas_profile_set(
int unit,
bcm_gport_t port,
bcm_cosq_tas_profile_id_t pid,
bcm_cosq_tas_profile_t *profile)
{
#ifdef BCM_TAS_SUPPORT
if (soc_feature(unit, soc_feature_tas)) {
return bcmi_esw_tas_profile_set(unit, port, pid, profile);
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_tas_profile_traverse
* Purpose:
* Traverse the set of profiles associated with the specified port.
* Parameters:
* unit - (IN) unit number
* port - (IN) gport id
* cb - (IN) A pointer to callback function to call
* for each profile in the specified gport.
* user_data - (IN) Pointer to user data to supply in the callback
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_tas_profile_traverse(
int unit,
bcm_gport_t port,
bcm_cosq_tas_profile_traverse_cb cb,
void *user_data)
{
#ifdef BCM_TAS_SUPPORT
if (soc_feature(unit, soc_feature_tas)) {
return bcmi_esw_tas_profile_traverse(unit, port, cb, user_data);
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_tas_profile_destroy
* Purpose:
* Destroy the profile and associated resources.
* Parameters:
* unit - (IN) unit number
* port - (IN) gport id
* pid - (IN) profile id
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_tas_profile_destroy(
int unit,
bcm_gport_t port,
bcm_cosq_tas_profile_id_t pid)
{
#ifdef BCM_TAS_SUPPORT
if (soc_feature(unit, soc_feature_tas)) {
return bcmi_esw_tas_profile_destroy(unit, port, pid);
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_tas_profile_destroy_all
* Purpose:
* Destroy all the profile associated with the port.
* Parameters:
* unit - (IN) unit number
* port - (IN) gport id
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_tas_profile_destroy_all(
int unit,
bcm_gport_t port)
{
#ifdef BCM_TAS_SUPPORT
if (soc_feature(unit, soc_feature_tas)) {
return bcmi_esw_tas_profile_destroy_all(unit, port);
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_tas_profile_status_get
* Purpose:
* Get the profile status like profile state, config change time and
* entries in the hardware calendar table.
* Parameters:
* unit - (IN) unit number
* port - (IN) gport id
* pid - (IN) profile id
* status - (OUT) pointer to profile status structure
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_tas_profile_status_get(
int unit,
bcm_gport_t port,
bcm_cosq_tas_profile_id_t pid,
bcm_cosq_tas_profile_status_t *status)
{
#ifdef BCM_TAS_SUPPORT
if (soc_feature(unit, soc_feature_tas)) {
return bcmi_esw_tas_profile_status_get(unit, port, pid, status);
}
#endif
return BCM_E_UNAVAIL;
}
#if defined(INCLUDE_TCB)
#if defined (BCM_TCB_SUPPORT)
_bcm_cosq_tcb_unit_ctrl_t *_bcm_cosq_tcb_unit_control[BCM_MAX_NUM_UNITS];
#endif
/*
* Function:
* bcm_esw_cosq_tcb_config_set
* Purpose:
* Set TCB instance config attributes.
* Parameters:
* unit - (IN) BCM device number.
* buffer_id - (IN) TCB buffer id.
* config - (IN) TCB config information
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_tcb_config_set(int unit,
bcm_cosq_buffer_id_t buffer_id,
bcm_cosq_tcb_config_t *config)
{
#ifdef BCM_TCB_SUPPORT
int rv = BCM_E_NONE;
if (soc_feature(unit, soc_feature_tcb)) {
TCB_INIT(unit);
TCB_LOCK(unit);
#ifdef BCM_TOMAHAWK2_SUPPORT
if (SOC_IS_TOMAHAWK2(unit)) {
rv = bcm_th2_cosq_tcb_config_set(unit, buffer_id, config);
}
#endif
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
rv = bcm_hx5_cosq_tcb_config_set(unit, buffer_id, config);
}
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit) && !SOC_IS_HELIX5(unit)) {
rv = bcm_td3_cosq_tcb_config_set(unit, buffer_id, config);
}
#endif
TCB_UNLOCK(unit);
return rv;
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_tcb_config_get
* Purpose:
* Get TCB instance control status.
* Parameters:
* unit - (IN) BCM device number.
* buffer_id - (IN) TCB buffer id.
* config - (OUT) TCB config information
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_tcb_config_get(int unit,
bcm_cosq_buffer_id_t buffer_id,
bcm_cosq_tcb_config_t *config)
{
#ifdef BCM_TCB_SUPPORT
int rv = BCM_E_NONE;
if (soc_feature(unit, soc_feature_tcb)) {
TCB_INIT(unit);
TCB_LOCK(unit);
#ifdef BCM_TOMAHAWK2_SUPPORT
if (SOC_IS_TOMAHAWK2(unit)) {
rv = bcm_th2_cosq_tcb_config_get(unit, buffer_id, config);
}
#endif
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
rv = bcm_hx5_cosq_tcb_config_get(unit, buffer_id, config);
}
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit) && !SOC_IS_HELIX5(unit)) {
rv = bcm_td3_cosq_tcb_config_get(unit, buffer_id, config);
}
#endif
TCB_UNLOCK(unit);
return rv;
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_tcb_gport_threshold_mapping_set
* Purpose:
* Set threshold profile for a UCQ or a port.
* Parameters:
* unit - (IN) unit number
* id - (IN) Integrated cosq index
* index - (IN) Threshold profile index
* Returns:
* BCM_E_XXX
* Notes:
* When gport is a port, SDK will attach all Ucqs in this port to one threshold profile.
*/
int
bcm_esw_cosq_tcb_gport_threshold_mapping_set(int unit,
bcm_cosq_object_id_t *id,
int index)
{
#ifdef BCM_TCB_SUPPORT
int rv = BCM_E_NONE;
if (soc_feature(unit, soc_feature_tcb)) {
TCB_INIT(unit);
TCB_LOCK(unit);
#ifdef BCM_TOMAHAWK2_SUPPORT
if (SOC_IS_TOMAHAWK2(unit)) {
rv = bcm_th2_cosq_tcb_gport_threshold_mapping_set(unit,
id->port, id->cosq, id->buffer, index);
}
#endif
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
rv = bcm_hx5_cosq_tcb_gport_threshold_mapping_set(unit,
id->port, id->cosq, id->buffer, index);
}
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit) && !SOC_IS_HELIX5(unit)) {
rv = bcm_td3_cosq_tcb_gport_threshold_mapping_set(unit,
id->port, id->cosq, id->buffer, index);
}
#endif
TCB_UNLOCK(unit);
return rv;
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_tcb_gport_threshold_mapping_get
* Purpose:
* Set threshold profile for a UCQ or a port.
* Parameters:
* unit - (IN) unit number
* id - (IN) Integrated cosq index
* index - (OUT) Threshold profile index
* Returns:
* BCM_E_XXX
* Notes:
* When gport is a port, SDK will return the threshold profile index of the first Ucq in this
* port.
*/
int
bcm_esw_cosq_tcb_gport_threshold_mapping_get(int unit,
bcm_cosq_object_id_t *id,
int *index)
{
#ifdef BCM_TCB_SUPPORT
int rv = BCM_E_NONE;
if (soc_feature(unit, soc_feature_tcb)) {
TCB_INIT(unit);
TCB_LOCK(unit);
#ifdef BCM_TOMAHAWK2_SUPPORT
if (SOC_IS_TOMAHAWK2(unit)) {
rv = bcm_th2_cosq_tcb_gport_threshold_mapping_get(unit,
id->port, id->cosq, id->buffer, index);
}
#endif
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
rv = bcm_hx5_cosq_tcb_gport_threshold_mapping_get(unit,
id->port, id->cosq, id->buffer, index);
}
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit) && !SOC_IS_HELIX5(unit)) {
rv = bcm_td3_cosq_tcb_gport_threshold_mapping_get(unit,
id->port, id->cosq, id->buffer, index);
}
#endif
TCB_UNLOCK(unit);
return rv;
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_tcb_threshold_profile_create
* Purpose:
* Create a threshold profile for a specified TCB buffer.
* Parameters:
* unit - (IN) BCM device number.
* flags - (IN) BCM_COSQ_TCB_THRESHOLD_PROFILE_WITH_ID: Index arg is given
* BCM_COSQ_TCB_THRESHOLD_PROFILE_REPLACE: Replace existing profile
* buffer_id - (IN) TCB buffer id.
* threshold - (IN) Threshold profile
* index - (INOUT) profile index
* Returns:
* BCM_E_XXX
* Notes:
* If user do not specify index, SDK will alloc a profile index and return to user.
* With BCM_COSQ_TCB_THRESHOLD_PROFILE_REPLACE flag user could directly update a
* existing threshold profile to new values.
*/
int
bcm_esw_cosq_tcb_threshold_profile_create(int unit,
int flags,
bcm_cosq_buffer_id_t buffer_id,
bcm_cosq_tcb_threshold_profile_t *threshold,
int *index)
{
#ifdef BCM_TCB_SUPPORT
int rv = BCM_E_NONE;
if (soc_feature(unit, soc_feature_tcb)) {
TCB_INIT(unit);
TCB_LOCK(unit);
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
rv = bcm_hx5_cosq_tcb_threshold_profile_create(unit, flags, buffer_id,
threshold, index);
}
#endif
#if defined (BCM_TOMAHAWK2_SUPPORT) || defined (BCM_TRIDENT3_SUPPORT)
if ((SOC_IS_TOMAHAWK2(unit) || SOC_IS_TRIDENT3X(unit)) && !SOC_IS_HELIX5(unit)) {
rv = bcm_th2_cosq_tcb_threshold_profile_create(unit, flags, buffer_id,
threshold, index);
}
#endif
TCB_UNLOCK(unit);
return rv;
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_tcb_threshold_profile_get
* Purpose:
* Get a threshold profile for a specified TCB buffer.
* Parameters:
* unit - (IN) BCM device number.
* buffer_id - (IN) TCB buffer id.
* index - (IN) profile index
* threshold - (OUT) Threshold profile
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_tcb_threshold_profile_get(int unit,
bcm_cosq_buffer_id_t buffer_id,
int index,
bcm_cosq_tcb_threshold_profile_t *threshold)
{
#ifdef BCM_TCB_SUPPORT
int rv = BCM_E_NONE;
if (soc_feature(unit, soc_feature_tcb)) {
TCB_INIT(unit);
TCB_LOCK(unit);
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
rv = bcm_hx5_cosq_tcb_threshold_profile_get(unit, buffer_id, index,
threshold);
} else
#endif /* BCM_HELIX5_SUPPORT */
#if defined (BCM_TOMAHAWK2_SUPPORT) || defined (BCM_TRIDENT3_SUPPORT)
if ((SOC_IS_TOMAHAWK2(unit) || SOC_IS_TRIDENT3X(unit)) && !SOC_IS_HELIX5(unit)) {
rv = bcm_th2_cosq_tcb_threshold_profile_get(unit, buffer_id, index,
threshold);
}
#endif
TCB_UNLOCK(unit);
return rv;
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_tcb_threshold_profile_destroy
* Purpose:
* Destory a existing threshold profile for a specified TCB buffer.
* Parameters:
* unit - (IN) BCM device number.
* buffer_id - (IN) TCB buffer id.
* index - (IN) profile index
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_tcb_threshold_profile_destroy(int unit,
bcm_cosq_buffer_id_t buffer_id,
int index)
{
#ifdef BCM_TCB_SUPPORT
int rv = BCM_E_NONE;
if (soc_feature(unit, soc_feature_tcb)) {
TCB_INIT(unit);
TCB_LOCK(unit);
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
rv = bcm_hx5_cosq_tcb_threshold_profile_destroy(unit, buffer_id, index);
} else
#endif /* BCM_HELIX5_SUPPORT */
#if defined (BCM_TOMAHAWK2_SUPPORT) || defined (BCM_TRIDENT3_SUPPORT)
if ((SOC_IS_TOMAHAWK2(unit) || SOC_IS_TRIDENT3X(unit)) && !SOC_IS_HELIX5(unit)) {
rv = bcm_th2_cosq_tcb_threshold_profile_destroy(unit, buffer_id, index);
}
#endif
TCB_UNLOCK(unit);
return rv;
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_tcb_buffer_multi_get
* Purpose:
* Get packet records in a specified TCB buffer.
* Parameters:
* unit - (IN) BCM device number.
* buffer_id - (IN) buffer id
* array_max - (IN) Number of entries to be retrieved
* buffer_array - (OUT) Pakcet record array
* array_count - (OUT) Number of packet records returned in buffer_array
* Returns:
* BCM_E_XXX
* Notes:
* When array_max is 0, buffer_array is NULL, array_count will return actural packet record
* count in the TCB buffer.
*/
int
bcm_esw_cosq_tcb_buffer_multi_get(int unit,
bcm_cosq_buffer_id_t buffer_id,
int array_max,
bcm_cosq_tcb_buffer_t *buffer_array,
int *array_count)
{
#ifdef BCM_TCB_SUPPORT
int rv = BCM_E_NONE;
if (soc_feature(unit, soc_feature_tcb)) {
TCB_INIT(unit);
TCB_LOCK(unit);
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
rv = bcm_hx5_cosq_tcb_buffer_multi_get(unit, buffer_id, array_max,
buffer_array, array_count);
}
#endif /* BCM_HELIX5_SUPPORT */
#if defined (BCM_TOMAHAWK2_SUPPORT) || defined (BCM_TRIDENT3_SUPPORT)
if ((SOC_IS_TOMAHAWK2(unit) || SOC_IS_TRIDENT3X(unit)) && !SOC_IS_HELIX5(unit)) {
rv = bcm_th2_cosq_tcb_buffer_multi_get(unit, buffer_id, array_max,
buffer_array, array_count);
}
#endif
TCB_UNLOCK(unit);
return rv;
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_tcb_event_multi_get
* Purpose:
* Get drop event records in a specified TCB buffer.
* Parameters:
* unit - (IN) BCM device number.
* buffer_id - (IN) buffer id
* array_max - (IN) Number of entries to be retrieved
* event_array - (OUT) Drop event record array
* array_count - (OUT) Number of drop event records returned in event_array
* overflow_count - (OUT) Drop event count exceed the event buffer.
* Returns:
* BCM_E_XXX
* Notes:
* When array_max is 0, event_array is NULL, array_count will return actural drop event
* record count in the TCB buffer.
*/
int
bcm_esw_cosq_tcb_event_multi_get(int unit,
bcm_cosq_buffer_id_t buffer_id,
int array_max,
bcm_cosq_tcb_event_t *event_array,
int *array_count,
int *overflow_count)
{
#ifdef BCM_TCB_SUPPORT
int rv = BCM_E_NONE;
if (soc_feature(unit, soc_feature_tcb)) {
TCB_INIT(unit);
TCB_LOCK(unit);
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
rv = bcm_hx5_cosq_tcb_event_multi_get(unit, buffer_id, array_max,
event_array, array_count,
overflow_count);
}
#endif /* BCM_HELIX5_SUPPORT */
#if defined (BCM_TOMAHAWK2_SUPPORT) || defined (BCM_TRIDENT3_SUPPORT)
if ((SOC_IS_TOMAHAWK2(unit) || SOC_IS_TRIDENT3X(unit)) && !SOC_IS_HELIX5(unit)) {
rv = bcm_th2_cosq_tcb_event_multi_get(unit, buffer_id, array_max,
event_array, array_count,
overflow_count);
}
#endif
TCB_UNLOCK(unit);
return rv;
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_tcb_control_set
* Purpose:
* Set TCB instance control status.
* Parameters:
* unit - (IN) BCM device number.
* buffer_id - (IN) TCB buffer id.
* type - (IN) Control type
* arg - (OUT) argument.
* Returns:
* BCM_E_XXX
* Notes:
* When control type is bcmCosqTcbControlFreeze, if buffer_id is -1, this API will freeze all
* TCB instance at a once.
*/
int
bcm_esw_cosq_tcb_control_set(int unit,
bcm_cosq_buffer_id_t buffer_id,
bcm_cosq_tcb_control_t type,
int arg)
{
#ifdef BCM_TCB_SUPPORT
int rv = BCM_E_NONE;
if (soc_feature(unit, soc_feature_tcb)) {
TCB_INIT(unit);
if (type == bcmCosqTcbControlEnable) {
TCB_LOCK(unit);
#ifdef BCM_TOMAHAWK2_SUPPORT
if (SOC_IS_TOMAHAWK2(unit)) {
rv = bcm_th2_cosq_tcb_enable(unit, buffer_id, arg);
}
#endif
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
rv = bcm_hx5_cosq_tcb_enable(unit, buffer_id, arg);
}
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit) && !SOC_IS_HELIX5(unit)) {
rv = bcm_td3_cosq_tcb_enable(unit, buffer_id, arg);
}
#endif
TCB_UNLOCK(unit);
return rv;
} else if (type == bcmCosqTcbControlFreeze) {
TCB_LOCK(unit);
#ifdef BCM_TOMAHAWK2_SUPPORT
if (SOC_IS_TOMAHAWK2(unit)) {
rv = bcm_th2_cosq_tcb_freeze(unit, buffer_id, arg);
}
#endif
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
rv = bcm_hx5_cosq_tcb_freeze(unit, buffer_id, arg);
}
#endif /* BCM_HELIX5_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit) && !SOC_IS_HELIX5(unit)) {
rv = bcm_td3_cosq_tcb_freeze(unit, buffer_id, arg);
}
#endif
TCB_UNLOCK(unit);
return rv;
} else {
return BCM_E_PARAM;
}
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_tcb_control_get
* Purpose:
* Get TCB instance control status.
* Parameters:
* unit - (IN) BCM device number.
* buffer_id - (IN) TCB buffer id.
* type - (IN) Control type
* arg - (OUT) argument.
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_tcb_control_get(int unit,
bcm_cosq_buffer_id_t buffer_id,
bcm_cosq_tcb_control_t type,
int *arg)
{
#ifdef BCM_TCB_SUPPORT
int rv = BCM_E_NONE;
if (soc_feature(unit, soc_feature_tcb)) {
#if defined (BCM_TOMAHAWK2_SUPPORT) || defined (BCM_TRIDENT3_SUPPORT)
TCB_INIT(unit);
TCB_LOCK(unit);
rv = bcm_th2_cosq_tcb_control_get(unit, buffer_id, type, arg);
TCB_UNLOCK(unit);
return rv;
#endif
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_tcb_cb_register
* Purpose:
* Register a callback for handling TCB freeze events.
* Parameters:
* unit - (IN) BCM device number.
* fn - (IN) A pointer to the callback function to call for TCB freeze events.
* user_data - (IN) Pointer to user data to supply in the callback
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_tcb_cb_register(int unit, bcm_cosq_tcb_callback_t fn, void *user_data)
{
#ifdef BCM_TCB_SUPPORT
int rv = BCM_E_NONE;
_bcm_cosq_tcb_unit_ctrl_t *tcb_unit_info;
tcb_unit_info = TCB_UNIT_CONTROL(unit);
if (soc_feature(unit, soc_feature_tcb)) {
TCB_INIT(unit);
TCB_LOCK(unit);
if(NULL == tcb_unit_info->tcb_evt_cb) {
tcb_unit_info->tcb_evt_cb = fn;
tcb_unit_info->tcb_evt_user_data = user_data;
} else {
/* Callback function is already registered */
rv = BCM_E_EXISTS;
}
TCB_UNLOCK(unit);
return rv;
}
#endif
return BCM_E_UNAVAIL;
}
/*
* Function:
* bcm_esw_cosq_tcb_cb_unregister
* Purpose:
* Unregister a callback for handling TCB freeze events.
* Parameters:
* unit - (IN) BCM device number.
* fn - (IN) A pointer to the callback function to unregister from TCB freeze events
* Returns:
* BCM_E_XXX
*/
int
bcm_esw_cosq_tcb_cb_unregister(int unit, bcm_cosq_tcb_callback_t fn)
{
#ifdef BCM_TCB_SUPPORT
int rv = BCM_E_NONE;
_bcm_cosq_tcb_unit_ctrl_t *tcb_unit_info;
tcb_unit_info = TCB_UNIT_CONTROL(unit);
if (soc_feature(unit, soc_feature_tcb)) {
TCB_INIT(unit);
TCB_LOCK(unit);
if(fn == tcb_unit_info->tcb_evt_cb) {
tcb_unit_info->tcb_evt_cb = NULL;
tcb_unit_info->tcb_evt_user_data = NULL;
} else {
/* Callback function is not registered */
rv = BCM_E_NOT_FOUND;
}
TCB_UNLOCK(unit);
return rv;
}
#endif
return BCM_E_UNAVAIL;
}
int
_bcm_cosq_tcb_uc_queue_resolve(int unit, bcm_cosq_buffer_id_t buffer_id, int queue,
bcm_gport_t *uc_gport)
{
#ifdef BCM_TCB_SUPPORT
int rv = BCM_E_UNAVAIL;
#ifdef BCM_TOMAHAWK2_SUPPORT
if (SOC_IS_TOMAHAWK2(unit)) {
rv = bcm_th2_cosq_tcb_uc_queue_resolve(unit, buffer_id, queue, uc_gport);
}
#endif
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
rv = bcm_hx5_cosq_tcb_uc_queue_resolve(unit, buffer_id, queue, uc_gport);
}
#endif
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit) && !SOC_IS_HELIX5(unit)) {
rv = bcm_td3_cosq_tcb_uc_queue_resolve(unit, buffer_id, queue, uc_gport);
}
#endif
return rv;
#endif
return BCM_E_UNAVAIL;
}
#endif /* INCLUDE_TCB && BCM_TCB_SUPPORT */
int
_bcm_esw_cosq_num_get(
int unit,
int *num_cos)
{
#ifdef BCM_TRIDENT_SUPPORT
int index, cosq;
cpu_cos_map_entry_t cpu_cos_map_entry;
if (SOC_IS_TD_TT(unit)) {
index = soc_mem_index_count(unit, CPU_COS_MAPm) - _BCM_CPU_COS_MAPS_RSVD +
(BCM_PRIO_MAX - BCM_PRIO_MIN + 1);
/* Read the entry */
SOC_IF_ERROR_RETURN
(READ_CPU_COS_MAPm(unit, MEM_BLOCK_ANY, index, &cpu_cos_map_entry));
cosq = soc_mem_field32_get(unit, CPU_COS_MAPm, &cpu_cos_map_entry, COSf);
*num_cos = cosq + 1;
}
#endif
return BCM_E_NONE;
}
#ifndef BCM_SW_STATE_DUMP_DISABLE
/*
* Function:
* _bcm_cosq_sw_dump
* Purpose:
* Displays COS Queue information maintained by software.
* Parameters:
* unit - Device unit number
* Returns:
* None
*/
void
_bcm_cosq_sw_dump(int unit)
{
mbcm_driver[unit]->mbcm_cosq_sw_dump(unit);
}
#endif /* BCM_SW_STATE_DUMP_DISABLE */
int bcm_esw_cosq_burst_monitor_dma_config_set(int unit,
uint32 host_mem_size,
uint32 **host_mem_add)
{
int result = BCM_E_UNAVAIL;
/* Take lock */
COSQ_EVENT_LOCK(unit);
/* QCM app microburst APIs. */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
result = bcm_th_cosq_burst_monitor_dma_config_set(unit, host_mem_size,
host_mem_add);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3(unit)) {
result = bcm_td3_cosq_burst_monitor_dma_config_set(unit, host_mem_size,
host_mem_add);
}
#endif
/* Release lock */
COSQ_EVENT_UNLOCK(unit);
return result;
}
int bcm_esw_cosq_burst_monitor_dma_config_get(int unit,
uint32 *host_mem_size,
uint32 **host_mem_add)
{
int result = BCM_E_UNAVAIL;
/* Take lock */
COSQ_EVENT_LOCK(unit);
/* QCM app microburst APIs. */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
result = bcm_th_cosq_burst_monitor_dma_config_get(unit, host_mem_size,
host_mem_add);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3(unit)) {
result = bcm_td3_cosq_burst_monitor_dma_config_get(unit, host_mem_size,
host_mem_add);
}
#endif /* BCM_TRIDENT3_SUPPORT */
/* Release lock */
COSQ_EVENT_UNLOCK(unit);
return result;
}
int bcm_esw_cosq_burst_monitor_set(int unit, int num_gports,
bcm_gport_t *gport_list)
{
int result = BCM_E_UNAVAIL;
/* Take lock */
COSQ_EVENT_LOCK(unit);
/* QCM app microburst APIs. */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
result = bcm_th_cosq_burst_monitor_set(unit, num_gports,
gport_list);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3(unit)) {
result = bcm_td3_cosq_burst_monitor_set(unit, num_gports,
gport_list);
}
#endif
/* Release lock */
COSQ_EVENT_UNLOCK(unit);
return result;
}
int bcm_esw_cosq_burst_monitor_get(int unit, int max_gports,
bcm_gport_t *gport_list, int *num_gports)
{
int result = BCM_E_UNAVAIL;
/* Take lock */
COSQ_EVENT_LOCK(unit);
/* QCM app microburst APIs. */
#ifdef BCM_TOMAHAWK_SUPPORT
if (SOC_IS_TOMAHAWKX(unit)) {
result = bcm_th_cosq_burst_monitor_get(unit, max_gports,
gport_list, num_gports);
}
#endif /* BCM_TOMAHAWK_SUPPORT */
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3(unit)) {
result = bcm_td3_cosq_burst_monitor_get(unit, max_gports,
gport_list, num_gports);
}
#endif
/* Release lock */
COSQ_EVENT_UNLOCK(unit);
return result;
}
/*
* Function:
* bcm_esw_cosq_gport_info_get
* Purpose:
* Get cosq gport info.
* Parameters:
* unit - (IN) unit number
* gport - (IN) priority
* info - (OUT) Info of the given cosq gport
* Returns:
* BCM_E_XXX
*/
int bcm_esw_cosq_gport_info_get(
int unit,
bcm_gport_t gport,
bcm_cosq_gport_level_info_t *info)
{
int rv = BCM_E_UNAVAIL;
#ifdef BCM_HELIX5_SUPPORT
if (SOC_IS_HELIX5(unit)) {
rv = bcm_hx5_cosq_gport_info_get(unit, gport, info);
}
#endif
return rv;
}
int
bcm_esw_obm_cb_register(int unit,
bcm_obm_callback_fn fn,
void *fn_data)
{
int rv = BCM_E_UNAVAIL;
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
rv = _soc_monterey_obm_cb_register(unit ,fn, fn_data);
}
#endif
return rv;
}
int
bcm_esw_obm_cb_unregister(int unit,
bcm_obm_callback_fn fn,
void *fn_data)
{
int rv = BCM_E_UNAVAIL;
#ifdef BCM_MONTEREY_SUPPORT
if (SOC_IS_MONTEREY(unit)) {
rv = _soc_monterey_obm_cb_unregister(unit,fn, fn_data);
}
#endif
return rv;
}
| 32.83786 | 134 | 0.576749 |
97f608fac1a8360454c304fa3609264c62e5ba80 | 1,192 | h | C | MyoSphero/Frameworks/RobotKit.framework/Frameworks/RobotCommandKit.framework/Headers/RKCalibrateCommand.h | smngreenberg/myo-sphero-ios | 537cf1bbf8260e2d2b117c38eb614ccdbc1a32b5 | [
"BSD-3-Clause"
] | 12 | 2015-03-02T19:09:49.000Z | 2021-08-17T18:17:54.000Z | MyoSphero/Frameworks/RobotKit.framework/Frameworks/RobotCommandKit.framework/Headers/RKCalibrateCommand.h | smngreenberg/myo-sphero-ios | 537cf1bbf8260e2d2b117c38eb614ccdbc1a32b5 | [
"BSD-3-Clause"
] | 5 | 2015-03-15T14:25:11.000Z | 2015-05-29T21:12:38.000Z | MyoSphero/Frameworks/RobotKit.framework/Frameworks/RobotCommandKit.framework/Headers/RKCalibrateCommand.h | smngreenberg/myo-sphero-ios | 537cf1bbf8260e2d2b117c38eb614ccdbc1a32b5 | [
"BSD-3-Clause"
] | 14 | 2015-03-02T19:09:51.000Z | 2020-05-22T09:41:43.000Z | //
// RKCalibrateCommand.h
// RobotCommandKit
//
// Created by Brian Smith on 6/15/11.
// Imported to RobotCommandKit by Hunter Lang on 12/12/13.
// Copyright 2011 Orbotix Inc. All rights reserved.
//
/*! @file */
#import <Foundation/Foundation.h>
#import "RKDeviceCommand.h"
/*!
* @brief Class to encapsulate a calibrate command and it's parameters.
*
* Class that encapsulates a calibrate command used to set the 0° heading. Client code can
* use this along with RKBackLEDOutputCommand and RKRollCommand to aim Sphero so sending a roll
* command with 0° moves it in a user desired direction.
*
*/
__deprecated_msg("replaced by RKSetHeadingCommand")
@interface RKCalibrateCommand : RKDeviceCommand
/*!
* The angle that will be added to the current heading when setting
* the new 0° point. The value is in degrees.
*/
@property ( nonatomic, readonly ) float heading;
/*!
* Initializer for a RKCalibrateCommand object.
* @param heading Typically this should be 0.0, but setting it will add to the current heading
* when setting the new 0° point. The value is in degrees.
* @return The initialized object.
*/
- (instancetype) initWithHeading:(float) heading;
@end
| 29.073171 | 95 | 0.734899 |
5a28b01627d5aa3795a988a2ce3d7d5c09c9d81e | 2,267 | h | C | wpimath/src/test/native/include/drake/common/unused.h | gcjurgiel/allwpilib | 99f3a64dff0eba07be9b2e6c53753aafa0c852d8 | [
"BSD-3-Clause"
] | 2 | 2021-02-25T02:01:02.000Z | 2021-03-17T04:52:04.000Z | wpimath/src/test/native/include/drake/common/unused.h | gcjurgiel/allwpilib | 99f3a64dff0eba07be9b2e6c53753aafa0c852d8 | [
"BSD-3-Clause"
] | 2 | 2020-07-11T23:47:55.000Z | 2020-07-16T16:09:06.000Z | wpimath/src/test/native/include/drake/common/unused.h | gcjurgiel/allwpilib | 99f3a64dff0eba07be9b2e6c53753aafa0c852d8 | [
"BSD-3-Clause"
] | 1 | 2022-02-16T16:13:24.000Z | 2022-02-16T16:13:24.000Z | #pragma once
namespace drake {
/// Documents the argument(s) as unused, placating GCC's -Wunused-parameter
/// warning. This can be called within function bodies to mark that certain
/// parameters are unused.
///
/// When possible, removing the unused parameter is better than placating the
/// warning. However, in some cases the parameter is part of a virtual API or
/// template concept that is used elsewhere, so we can't remove it. In those
/// cases, this function might be an appropriate work-around.
///
/// Here's rough advice on how to fix Wunused-parameter warnings:
///
/// (1) If the parameter can be removed entirely, prefer that as the first
/// choice. (This may not be possible if, e.g., a method must match some
/// virtual API or template concept.)
///
/// (2) Unless the parameter name has acute value, prefer to omit the name of
/// the parameter, leaving only the type, e.g.
/// @code
/// void Print(const State& state) override { /* No state to print. */ }
/// @endcode
/// changes to
/// @code
/// void Print(const State&) override { /* No state to print. */}
/// @endcode
/// This no longer triggers the warning and further makes it clear that a
/// parameter required by the API is definitively unused in the function.
///
/// This is an especially good solution in the context of method
/// definitions (vs declarations); the parameter name used in a definition
/// is entirely irrelevant to Doxygen and most readers.
///
/// (3) When leaving the parameter name intact has acute value, it is
/// acceptable to keep the name and mark it `unused`. For example, when
/// the name appears as part of a virtual method's base class declaration,
/// the name is used by Doxygen to document the method, e.g.,
/// @code
/// /** Sets the default State of a System. This default implementation is to
/// set all zeros. Subclasses may override to use non-zero defaults. The
/// custom defaults may be based on the given @p context, when relevant. */
/// virtual void SetDefault(const Context<T>& context, State<T>* state) const {
/// unused(context);
/// state->SetZero();
/// }
/// @endcode
///
template <typename ... Args>
void unused(const Args& ...) {}
} // namespace drake
| 41.981481 | 80 | 0.685487 |
f6c90e9fe3eaaa04a68348d666d071a6c52afb4e | 4,933 | h | C | apps/examples/ocf_mylight/ocf_mylight.h | kimvsparrow/TizenRT-RA8875 | 8970ce0673296ee8967fc69d8b79e015ca4b7f98 | [
"Apache-2.0"
] | 2 | 2018-03-30T06:19:59.000Z | 2021-12-19T05:47:08.000Z | apps/examples/ocf_mylight/ocf_mylight.h | kimvsparrow/TizenRT-RA8875 | 8970ce0673296ee8967fc69d8b79e015ca4b7f98 | [
"Apache-2.0"
] | null | null | null | apps/examples/ocf_mylight/ocf_mylight.h | kimvsparrow/TizenRT-RA8875 | 8970ce0673296ee8967fc69d8b79e015ca4b7f98 | [
"Apache-2.0"
] | 2 | 2018-09-27T04:42:21.000Z | 2020-07-23T14:00:03.000Z | /****************************************************************************
*
* Copyright 2017 Samsung Electronics All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/
#ifndef __OCF_MYLIGHT_H__
#define __OCF_MYLIGHT_H__
#include <iotivity_config.h>
#include <platform_features.h>
#include <ocstack.h>
#include <logger.h>
#include <ocpayload.h>
#define SVR_DB_PATH "/mnt/oic_svr_db.dat"
#define SVR_JSON_PATH "/mnt/oic_svr_db.json"
#define DEVICE_DB_PATH "/mnt/device_properties.dat"
#define INTROSPECTION_DB_PATH "/mnt/introspection.dat"
#define INTROSPECTION_JSON_PATH "/mnt/introspection.json"
#define SETUP_INFO_PATH "/mnt/setup_info.dat"
#define _UNUSED_ __attribute__((unused))
#define DBG(fmt, args...) fprintf(stdout, "\e[1;32m<%s:%d> " fmt "\e[0m\n", \
__FILE__, __LINE__, ##args)
#define MSG(fmt, args...) fprintf(stdout, "\e[1;34m" fmt "\e[0m\n", ##args)
struct ocf_ops {
OCEntityHandler get;
OCEntityHandler put;
OCEntityHandler post;
OCEntityHandler del;
OCEntityHandler register_observe;
OCEntityHandler deregister_observe;
};
struct ocf_dev_ops {
OCDeviceEntityHandler get;
OCDeviceEntityHandler put;
OCDeviceEntityHandler post;
OCDeviceEntityHandler del;
};
OCEntityHandlerResult ocf_mylight_handler(OCEntityHandlerFlag flag,
OCEntityHandlerRequest *req, void *user_data);
OCEntityHandlerResult ocf_mylight_dev_handler(OCEntityHandlerFlag flag,
OCEntityHandlerRequest *req, char *uri, void *user_data);
void ocf_mylight_verbose_payload(const char *indent, OCPayload *payload);
void ocf_mylight_verbose_response(OCEntityHandlerResponse *resp);
void ocf_mylight_verbose_request(OCEntityHandlerFlag flag,
OCEntityHandlerRequest *req);
int ocf_mylight_get_quit_flag(void);
void ocf_mylight_set_quit_flag(int with_reboot);
int ocf_mylight_playform_init(void);
const char *ocf_mylight_device_get_name(void);
int ocf_mylight_device_set_name(const char *name);
int ocf_mylight_device_init(void);
int ocf_mylight_light_init(void);
void ocf_mylight_light_exit(void);
int ocf_mylight_light_get_handle(OCResourceHandle *handle);
const char *ocf_mylight_light_peek_uri(void);
int ocf_mylight_light_set_status(bool status);
int ocf_mylight_light_get_status(bool *status);
#ifdef CONFIG_EXAMPLES_OCFMYLIGHT_DIMMER
int ocf_mylight_dimm_init(void);
void ocf_mylight_dimm_exit(void);
int ocf_mylight_dimm_get_handle(OCResourceHandle *handle);
const char *ocf_mylight_dimm_peek_uri(void);
int ocf_mylight_dimm_set_level(int64_t value);
int ocf_mylight_dimm_get_level(int64_t *value);
#endif
int ocf_mylight_security_init(void);
void ocf_mylight_security_free(void);
int ocf_mylight_notify_init(void);
void ocf_mylight_notify_exit(void);
int ocf_mylight_notify_add(unsigned int rsrc_id, OCObservationId obs_id);
int ocf_mylight_notify_del(unsigned int rsrc_id, OCObservationId obs_id);
int ocf_mylight_notify_emit(unsigned int rsrc_id);
int ocf_mylight_userinput_init(void);
void ocf_mylight_remove_db(void);
void ocf_mylight_recovery_default(void);
int ocf_mylight_reset_svr(void);
int ocf_mylight_reset_introspection(void);
const char *ocf_mylight_setup_get_name(void);
const char *ocf_mylight_setup_get_wifi_ssid(void);
const char *ocf_mylight_setup_get_wifi_pwd(void);
int ocf_mylight_setup_get_wifi_security(void);
const OCUUIdentity *ocf_mylight_setup_get_uuid(void);
int ocf_mylight_setup_set_name(const char *name, size_t len);
int ocf_mylight_setup_set_wifi_ssid(const char *ssid, size_t len);
int ocf_mylight_setup_set_wifi_pwd(const char *pwd, size_t len);
int ocf_mylight_setup_set_wifi_security(int security);
int ocf_mylight_setup_set_failback_time(time_t value);
time_t ocf_mylight_setup_get_failback_time(void);
const char *ocf_mylight_setup_get_timezone(void);
int ocf_mylight_setup_set_timezone(const char *zone, size_t len);
void ocf_mylight_setup_reset(void);
int ocf_mylight_setup_load(void);
int ocf_mylight_setup_save(void);
int ocf_mylight_wifi_init(void);
int ocf_mylight_wifi_scan(void);
int ocf_mylight_wifi_connect(void);
int ocf_mylight_ntp_init(void);
#ifdef CONFIG_LIBC_LOCALTIME
int ocf_mylight_tz_setup(const char *tzname, unsigned char *data,
unsigned int len);
int ocf_mylight_tz_select(const char *tzname);
#endif
/**
* Prototype of json2cbor.c function
*/
void ConvertJSONFileToCBORFile(const char *jsonFileName,
const char *cborFileName);
#endif
| 34.739437 | 78 | 0.793837 |
f5cf88048118e5f7c5fdfdae3574a4de65be93e7 | 1,413 | h | C | sdk-6.5.20/include/soc/dfe/fe3200/fe3200_config_imp_defs.h | copslock/broadcom_cpri | 8e2767676e26faae270cf485591902a4c50cf0c5 | [
"Spencer-94"
] | null | null | null | sdk-6.5.20/include/soc/dfe/fe3200/fe3200_config_imp_defs.h | copslock/broadcom_cpri | 8e2767676e26faae270cf485591902a4c50cf0c5 | [
"Spencer-94"
] | null | null | null | sdk-6.5.20/include/soc/dfe/fe3200/fe3200_config_imp_defs.h | copslock/broadcom_cpri | 8e2767676e26faae270cf485591902a4c50cf0c5 | [
"Spencer-94"
] | null | null | null | /*
*
*
* This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
*
* Copyright 2007-2020 Broadcom Inc. All rights reserved.
* This file is auto-generated by autoCoder
* DO NOT EDIT THIS FILE!
*/
#ifndef FE3200_CONFIG_IMP_DEFS
#define FE3200_CONFIG_IMP_DEFS
#include <soc/defs.h>
#ifdef BCM_88950_A0
#define SOC_FE3200_GET(dfe_define) SOC_FE3200_##dfe_define
#define SOC_FE3200_RTP_REACHABILTY_GEN_RATE_PER_LINK (50000)
#define SOC_FE3200_RTP_REACHABILTY_WATCHDOG_RATE (100000)
#define SOC_FE3200_MDIO_INT_DIVIDEND_DEFAULT (1)
#define SOC_FE3200_MDIO_INT_FREQ_DEFAULT (10)
#define SOC_FE3200_MDIO_INT_OUT_DELAY_DEFAULT (0x9)
#define SOC_FE3200_FABRIC_CLOCK_FREQ_IN_DEFAULT (0)
#define SOC_FE3200_FABRIC_CLOCK_FREQ_OUT_DEFAULT (0)
#define SOC_FE3200_LCPLL_CONTROL1_125_VAL (-1)
#define SOC_FE3200_LCPLL_CONTROL1_156_25_VAL (-1)
#define SOC_FE3200_LCPLL_CONTROL3_125_VAL (-1)
#define SOC_FE3200_LCPLL_CONTROL3_156_25_VAL (-1)
#define SOC_FE3200_FIFO_DMA_NOF_CHANNELS (4)
int soc_fe3200_implementation_defines_init(int unit);
int soc_fe3200_implementation_defines_deinit(int unit);
#else
#define SOC_FE3200_GET(dfe_define) 0
#endif
#endif
| 34.463415 | 134 | 0.723284 |
67404d615a5b53f1f757afff36dfc1483a9f4838 | 694 | h | C | include/cros_service.h | ProfFan/cros | 25a0721bcd30c1dd3c02ada08c4bd067ceb4142d | [
"BSD-3-Clause"
] | 35 | 2016-03-08T18:15:55.000Z | 2021-11-20T11:13:27.000Z | include/cros_service.h | ProfFan/cros | 25a0721bcd30c1dd3c02ada08c4bd067ceb4142d | [
"BSD-3-Clause"
] | 11 | 2016-03-03T10:31:18.000Z | 2020-05-05T15:36:59.000Z | include/cros_service.h | ProfFan/cros | 25a0721bcd30c1dd3c02ada08c4bd067ceb4142d | [
"BSD-3-Clause"
] | 25 | 2016-03-08T15:54:23.000Z | 2021-11-23T09:50:11.000Z | #ifndef _CROS_SERVICE_H_
#define _CROS_SERVICE_H_
#include "cros_node.h"
#include "cros_message.h"
#include "cros_err_codes.h"
/*! \defgroup cros_service cROS TCPROS
*
* Implementation of the TCPROS protocol for service message exchanges
*/
/*! \addtogroup cros_service
* @{
*/
struct cRosService
{
cRosMessage *request;
cRosMessage *response;
char* md5sum;
};
typedef struct cRosService cRosService;
cRosService * cRosServiceNew();
cRosErrCodePack cRosServiceInit(cRosService* service);
cRosErrCodePack cRosServiceBuild(cRosService* service, const char* filepath);
void cRosServiceRelease(cRosService* service);
void cRosServiceFree(cRosService* service);
/*! @}*/
#endif
| 19.828571 | 77 | 0.769452 |
916ecf3f6beece0b176e3b0c889ef2f98b31223f | 673 | h | C | include/io.h | goforbroke1006/gfb-stdgo | 2c897bea3cc5ee644e78114e2e94f9c6cf269047 | [
"MIT"
] | null | null | null | include/io.h | goforbroke1006/gfb-stdgo | 2c897bea3cc5ee644e78114e2e94f9c6cf269047 | [
"MIT"
] | 1 | 2019-03-04T09:24:36.000Z | 2019-03-04T09:24:36.000Z | include/io.h | goforbroke1006/gfb-stdgo | 2c897bea3cc5ee644e78114e2e94f9c6cf269047 | [
"MIT"
] | null | null | null | //
// Created by goforbroke on 07.02.19.
//
#ifndef GFB_STDGO_IO_H
#define GFB_STDGO_IO_H
#include <string>
#include <exception>
#include <stdexcept>
#include <fstream>
#include <sstream>
#include <vector>
namespace gfb {
namespace stdgo {
namespace io {
class Reader {
public:
virtual void Read(std::string &p) const = 0;
virtual void Read(std::vector<char> p) const = 0;
};
namespace ioutil {
std::string ReadAll(const Reader &r);
std::string ReadFile(const std::string &filename);
}
}
}
}
#endif //GFB_STDGO_IO_H
| 18.189189 | 66 | 0.555721 |
f47b7966ba5592957fe8088a86efeb9aa5210aed | 516 | h | C | moai/src/aku/AKU-luaext.h | jjimenezg93/ai-pathfinding | e32ae8be30d3df21c7e64be987134049b585f1e6 | [
"MIT"
] | null | null | null | moai/src/aku/AKU-luaext.h | jjimenezg93/ai-pathfinding | e32ae8be30d3df21c7e64be987134049b585f1e6 | [
"MIT"
] | null | null | null | moai/src/aku/AKU-luaext.h | jjimenezg93/ai-pathfinding | e32ae8be30d3df21c7e64be987134049b585f1e6 | [
"MIT"
] | null | null | null | //----------------------------------------------------------------//
// Copyright (c) 2010-2011 Zipline Games, Inc.
// All Rights Reserved.
// http://getmoai.com
//----------------------------------------------------------------//
#ifndef AKU_MOAIEXT_LUAEXT_H
#define AKU_MOAIEXT_LUAEXT_H
#include <aku/AKU.h>
AKU_API void AKUExtLoadLuacrypto ();
AKU_API void AKUExtLoadLuacurl ();
AKU_API void AKUExtLoadLuafilesystem ();
AKU_API void AKUExtLoadLuasocket ();
AKU_API void AKUExtLoadLuasql ();
#endif
| 27.157895 | 68 | 0.550388 |
734b21f517e24618347d90717737e88fb856babd | 7,018 | h | C | scope/testrunner.h | zweger/scope | e07f3d4b636a9807bc3bd67109473f0934716d54 | [
"BSL-1.0"
] | 1 | 2020-10-16T10:09:58.000Z | 2020-10-16T10:09:58.000Z | scope/testrunner.h | zweger/scope | e07f3d4b636a9807bc3bd67109473f0934716d54 | [
"BSL-1.0"
] | 14 | 2015-04-11T01:36:28.000Z | 2021-04-02T20:23:53.000Z | scope/testrunner.h | zweger/scope | e07f3d4b636a9807bc3bd67109473f0934716d54 | [
"BSL-1.0"
] | 2 | 2017-08-20T22:43:45.000Z | 2018-11-05T21:52:46.000Z | /*
© 2009–2016, Jon Stewart
Released under the terms of the Boost license (http://www.boost.org/LICENSE_1_0.txt). See License.txt for details.
*/
#pragma once
#include <cassert>
#include <csignal>
#include <iostream>
#include <memory>
#include <map>
#include <regex>
#include <thread>
#include <mutex>
#include "tclap/CmdLine.h"
#include "test.h"
namespace scope {
void runFunction(scope::TestFunction test, const char* testname, bool shouldFail, MessageList& messages) {
try {
test();
if (shouldFail) {
std::string msg(testname);
msg.append(": marked for failure but did not throw scope::TestFailure.");
messages.push_back(msg);
}
}
catch (const TestFailure& fail) {
if (!shouldFail) {
std::ostringstream buf;
buf << fail.File << ":" << fail.Line << ": " << testname << ": " << fail.what();
messages.push_back(buf.str());
}
}
catch (const std::exception& except) {
messages.push_back(std::string(testname) + ": " + except.what());
}
catch (...) {
caughtBadExceptionType(testname, "test threw unrecognized type");
throw;
}
}
void caughtBadExceptionType(const std::string& name, const std::string& msg) {
std::cerr << name << ": " << msg << "; please at least inherit from std::exception" << std::endl;
}
namespace {
template<class X>
bool always_true(const X&) {
return true;
}
class TestRunnerImpl: public TestRunner {
public:
TestRunnerImpl():
NumTests(0), NumRun(0), Debug(false)
{
traverse([this](AutoRegister*) {
++this->NumTests;
});
}
virtual void runTest(const TestCase& test, MessageList& messages) {
if (!(NameFilter || SourceFilter)
|| (NameFilter && std::regex_match(test.Name, *NameFilter))
|| (SourceFilter && std::regex_match(test.SourceFile, *SourceFilter)))
{
lastTest() = test.Name;
if (Debug) {
std::cerr << "Running " << test.Name << std::endl;
}
++NumRun;
test.Run(messages);
if (Debug) {
std::cerr << "Done with " << test.Name << std::endl;
}
lastTest().clear();
}
}
virtual void run(MessageList& messages) {
traverse([this, &messages](AutoRegister* cur) {
std::unique_ptr<TestCase> test(cur->Construct());
this->runTest(*test, messages);
});
}
virtual unsigned int numTests() const {
return NumTests;
}
virtual unsigned int numRun() const {
return NumRun;
}
virtual void setDebug(bool val) {
Debug = val;
}
virtual void setFilter(const std::shared_ptr<std::regex>& filter) {
NameFilter = filter;
}
virtual void setSourceFilter(const std::shared_ptr<std::regex>& sourceFilter) {
SourceFilter = sourceFilter;
}
template<class AutoRegFnType>
void traverse(AutoRegFnType&& fn) {
auto& r(root());
for (auto cur(r.FirstChild); cur; cur = cur->Next) {
fn(cur);
}
}
private:
std::shared_ptr<std::regex> NameFilter,
SourceFilter;
unsigned int NumTests,
NumRun;
bool Debug;
};
}
Node<AutoRegister>& TestRunner::root(void) {
static Node<AutoRegister> root;
return root;
}
std::string& TestRunner::lastTest(void) {
static std::string last;
return last;
}
void handleTerminate() {
// the handler can be called on multiple threads
// this is a legitimate use of a static mutex
// weirdly
static std::mutex theHighlander;
std::lock_guard<std::mutex> lock(theHighlander);
{
std::cerr << "std::terminate called, last test was "
<< TestRunner::lastTest()
<< ". Aborting." << std::endl;
std::abort();
}
}
std::map<int, std::string> signalMap() {
return std::map<int, std::string> {
{SIGFPE, "floating point exception (SIGFPE)"},
{SIGSEGV, "segmentation fault (SIGSEGV)"},
{SIGTERM, "termination request (SIGTERM)"},
{SIGINT, "interrupt request (SIGINT)"}
};
}
void handleSignal(int signum) {
auto friendlySig = signalMap()[signum];
std::cerr << "Received signal " << signum << ", " << friendlySig
<< ". Last test was " << TestRunner::lastTest() << ". Aborting." << std::endl;
std::abort();
}
template<typename HandlerT>
void setHandlers(HandlerT handler) {
auto sigmap = signalMap();
for (auto sig: sigmap) {
std::signal(sig.first, handler);
}
}
bool DefaultRun(std::ostream& out, int argc, char** argv) {
TCLAP::CmdLine parser("Scope test", ' ', "version number? what's a version number?", true);
TCLAP::ValueArg<std::string> sourceFile("s", "source-filter", "Run tests from source files where the filenames match the provided regexp", false, "", "regexp", parser);
TCLAP::ValueArg<std::string> filter("f", "filter", "Only run test cases whose names match provided regexp", false, "", "regexp", parser);
TCLAP::SwitchArg verbose("v", "verbose", "Print debugging info", parser);
TCLAP::SwitchArg list("l", "list", "List test names", parser);
try {
parser.parse(argc, argv);
}
catch (TCLAP::ArgException& e) {
std::cerr << "Error: " << e.error() << " for argument " << e.argId() << std::endl;
return false;
}
MessageList msgs;
TestRunnerImpl runner;
std::string f(filter.getValue());
if (!f.empty()) {
try {
runner.setFilter(std::make_shared<std::regex>(f));
}
catch (std::regex_error& e) {
std::cerr << "Error with filter regexp '" << f << "': " << e.what() << std::endl;
return false;
}
}
std::string s(sourceFile.getValue());
if (!s.empty()) {
try {
runner.setSourceFilter(std::make_shared<std::regex>(s));
}
catch (std::regex_error& e) {
std::cerr << "Error with filter regexp '" << s << "': " << e.what() << std::endl;
return false;
}
}
if (list.getValue()) {
runner.traverse([](AutoRegister* cur) { std::cerr << cur->TestName << '\t' << cur->SourceFile << '\n'; });
return true;
}
if (verbose.getValue()) {
runner.setDebug(true);
out << "Running in debug mode" << std::endl;
}
setHandlers(handleSignal);
std::set_terminate(&handleTerminate);
runner.run(msgs);
std::set_terminate(0);
setHandlers(SIG_DFL);
for(const std::string& m : msgs) {
out << m << '\n';
}
if (msgs.empty()) {
out << "OK (" << runner.numRun() << " tests)" << std::endl;
return true;
}
else {
out << "Failures!" << std::endl;
out << "Tests run: " << runner.numRun() << ", Failures: " << msgs.size() << std::endl;
return false;
}
}
}
| 28.184739 | 172 | 0.563693 |
29771aa73c13b30f5baf75007112bbe9fc799bb7 | 573 | c | C | ports/xt804/src/utf8_map.c | gengyong/micropython | 89ca27426e11eca00af15fde8c486654faa471b5 | [
"MIT"
] | 16 | 2021-11-17T09:06:36.000Z | 2022-03-15T02:58:56.000Z | ports/xt804/src/utf8_map.c | gengyong/micropython | 89ca27426e11eca00af15fde8c486654faa471b5 | [
"MIT"
] | null | null | null | ports/xt804/src/utf8_map.c | gengyong/micropython | 89ca27426e11eca00af15fde8c486654faa471b5 | [
"MIT"
] | 2 | 2021-11-19T11:32:50.000Z | 2021-12-20T09:20:15.000Z | const unsigned char SizeOfUTF8Code[256] = {
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,6,6,0,0
}; | 57.3 | 65 | 0.506108 |
349c27e447d2e4e1f4e89c651d16c279b4e2acfa | 275 | h | C | ProjectTemplate/ProjectTemplate/Classes/Modules/ModuleName/Controller/WJHomeViewController.h | istupid/WilliamPro | 3c3511c34509302214ba4ebf14e55709d8fb566d | [
"MIT"
] | null | null | null | ProjectTemplate/ProjectTemplate/Classes/Modules/ModuleName/Controller/WJHomeViewController.h | istupid/WilliamPro | 3c3511c34509302214ba4ebf14e55709d8fb566d | [
"MIT"
] | null | null | null | ProjectTemplate/ProjectTemplate/Classes/Modules/ModuleName/Controller/WJHomeViewController.h | istupid/WilliamPro | 3c3511c34509302214ba4ebf14e55709d8fb566d | [
"MIT"
] | null | null | null | //
// WJHomeViewController.h
// ProjectTemplate
//
// Created by William on 2018/12/4.
// Copyright © 2018 William. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface WJHomeViewController : UIViewController
@end
NS_ASSUME_NONNULL_END
| 15.277778 | 50 | 0.752727 |
9562c3b35351d25c1951a76f13edda04a9430824 | 386 | c | C | sample/10/input.c | alexktvsky/tec | 64579ec93ac0b93665678fa4e8dc0de866b78d4a | [
"BSD-2-Clause"
] | null | null | null | sample/10/input.c | alexktvsky/tec | 64579ec93ac0b93665678fa4e8dc0de866b78d4a | [
"BSD-2-Clause"
] | null | null | null | sample/10/input.c | alexktvsky/tec | 64579ec93ac0b93665678fa4e8dc0de866b78d4a | [
"BSD-2-Clause"
] | null | null | null | #include <stdio.h>
#include <stdint.h>
#include <stddef.h>
template <typename T>
typedef struct node_s<T> node_t<T>;
template <typename T>
struct node_s {
T data;
node_t<T> *next;
node_t<T> *prev;
};
template <typename T>
typedef struct {
node_t<T> *head;
node_t<T> *tail;
} list_t;
int main(void) {
list_t<int> l1;
list_t<double> l2;
return 0;
}
| 13.310345 | 35 | 0.626943 |
9fe5b97a9e61c41b4372b46640ec84d7b535a2b2 | 387 | h | C | BCC102/include/windows/sdk/drivinit.h | FarouDev/Projects-for-beginner-with-Cpp | 1210457c122cb5da8f7c5a4a7386eb064e8b31b0 | [
"MIT"
] | null | null | null | BCC102/include/windows/sdk/drivinit.h | FarouDev/Projects-for-beginner-with-Cpp | 1210457c122cb5da8f7c5a4a7386eb064e8b31b0 | [
"MIT"
] | null | null | null | BCC102/include/windows/sdk/drivinit.h | FarouDev/Projects-for-beginner-with-Cpp | 1210457c122cb5da8f7c5a4a7386eb064e8b31b0 | [
"MIT"
] | null | null | null | #pragma option push -b -a8 -pc -A- -w-pun /*P_O_Push*/
//+---------------------------------------------------------------------------
//
// Microsoft Windows
// Copyright (C) Microsoft Corporation, 1992-1999.
//
// File: drivinit.h
//
//----------------------------------------------------------------------------
// All items moved to wingdi.h
#pragma option pop /*P_O_Pop*/
| 27.642857 | 78 | 0.374677 |
95faa25dae1b2386b94a963462a47c4d3b6dd989 | 561 | h | C | LeetCode/C++/0121._Best_Time_to_Buy_and_Sell_Stock/solution.h | icgw/LeetCode | cb70ca87aa4604d1aec83d4224b3489eacebba75 | [
"MIT"
] | 4 | 2018-09-12T09:32:17.000Z | 2018-12-06T03:17:38.000Z | LeetCode/C++/0121._Best_Time_to_Buy_and_Sell_Stock/solution.h | icgw/algorithm | cb70ca87aa4604d1aec83d4224b3489eacebba75 | [
"MIT"
] | null | null | null | LeetCode/C++/0121._Best_Time_to_Buy_and_Sell_Stock/solution.h | icgw/algorithm | cb70ca87aa4604d1aec83d4224b3489eacebba75 | [
"MIT"
] | null | null | null | /*
* solution.h
* Copyright (C) 2021 Guowei Chen <icgw@outlook.com>
*
* Distributed under terms of the Apache license.
*/
#ifndef _SOLUTION_H_
#define _SOLUTION_H_
#include <vector>
using std::vector;
#include <algorithm>
using std::max;
using std::min;
class Solution {
public:
int maxProfit(vector<int>& prices) {
int buy_price = prices[0];
int max_profit = 0;
for (int p : prices) {
max_profit = max(max_profit, p - buy_price);
buy_price = min(buy_price, p);
}
return max_profit;
}
};
#endif /* !_SOLUTION_H_ */
| 17.53125 | 52 | 0.654189 |
452994b2a435744a30fb1ea0e642051e0f04c654 | 1,211 | h | C | Software/OOP/Version 2/Soccer_Simulation_v2/Classes/Compass.h | Brenocq/SoccerOpenRCJ | 1711e251861c124e49df21abb63eb169569bea4f | [
"MIT"
] | 2 | 2019-05-02T23:01:06.000Z | 2019-05-11T01:29:06.000Z | Software/OOP/Version 2/Soccer_Simulation_v2/Classes/Compass.h | Brenocq/SoccerOpenRCJ | 1711e251861c124e49df21abb63eb169569bea4f | [
"MIT"
] | null | null | null | Software/OOP/Version 2/Soccer_Simulation_v2/Classes/Compass.h | Brenocq/SoccerOpenRCJ | 1711e251861c124e49df21abb63eb169569bea4f | [
"MIT"
] | null | null | null | ///////////////////////////////////////////////////////////
// Compass.h
// Implementation of the Class Compass
// Created on: 21-mar-2018 21:46:56
// Original author: Breno Queiroz
///////////////////////////////////////////////////////////
#ifndef COMPASS_H
#define COMPASS_H
#include "Sensor.h"
#if defined(ARDUINO)//arduino libraries
#if ARDUINO>=100
#include "Arduino.h"//arduino version >= 1.0.0
#elif ARDUINO<100
#include "WProgram.h"//arduino old version
#endif
#else
#include <iostream>//cout,cin
using std::cout;
using std::cin;
using std::endl;
#include <iomanip>//setprecision
using std::setprecision;
extern "C" {
#include "../CopelliaSim/extApi.h"
}
#endif
class Compass : public Sensor
{
public:
#if defined(ARDUINO)
Compass();
void begin();
void print(bool plotter=false);
void updateAccel();
int accelX();
int accelY();
int accelZ();
#else
Compass(string name, int robotN);
#endif
virtual ~Compass();
//value
virtual float value();
private:
bool isFirstReading; // ajust the first angle to 0
float adjustFront;
int accelerometerX;
int accelerometerY;
int accelerometerZ;
};
#endif // COMPASS_H
| 18.921875 | 60 | 0.604459 |
c775be6d63f353fd8f374a5d96c98332a61c0768 | 296 | h | C | KRHome/KRHome/Classes/Targets/Target_KRHome.h | KinRainModulization/KRHome | 3d0da6462450107e50251b4b1a06f49983ce3b2f | [
"MIT"
] | null | null | null | KRHome/KRHome/Classes/Targets/Target_KRHome.h | KinRainModulization/KRHome | 3d0da6462450107e50251b4b1a06f49983ce3b2f | [
"MIT"
] | null | null | null | KRHome/KRHome/Classes/Targets/Target_KRHome.h | KinRainModulization/KRHome | 3d0da6462450107e50251b4b1a06f49983ce3b2f | [
"MIT"
] | null | null | null | //
// Target_KRHome.h
// KRHome
//
// Created by LX on 2017/12/12.
// Copyright © 2017年 Ace. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface Target_KRHome : NSObject
- (UIViewController *)Action_HomeViewController:(NSDictionary *)params;
@end
| 17.411765 | 71 | 0.712838 |
ba4739987d6773c16593ea6c98bd5b799fdc32a2 | 876 | h | C | DemoGather/Class/Other/Extension/UIView+HSKit.h | Qing-CN/DemoGather | 636a3050c9f4d720a8ea43e37975befaf521260d | [
"MIT"
] | null | null | null | DemoGather/Class/Other/Extension/UIView+HSKit.h | Qing-CN/DemoGather | 636a3050c9f4d720a8ea43e37975befaf521260d | [
"MIT"
] | null | null | null | DemoGather/Class/Other/Extension/UIView+HSKit.h | Qing-CN/DemoGather | 636a3050c9f4d720a8ea43e37975befaf521260d | [
"MIT"
] | null | null | null | //
// UIView+HSKit.h
// YANGXIN
//
// Created by GY.Z on 2019/9/9.
// Copyright © 2019 张广义. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface UIView (HSKit)
@property (nonatomic, assign) CGFloat left;
@property (nonatomic, assign) CGFloat right;
@property (nonatomic, assign) CGFloat top;
@property (nonatomic, assign) CGFloat bottom;
@property (nonatomic, assign) CGFloat width;
@property (nonatomic, assign) CGFloat height;
@property (nonatomic, assign) CGFloat centerX;
@property (nonatomic, assign) CGFloat centerY;
@property (nonatomic, assign, readonly) CGPoint boundsCenter;
@property (nonatomic, assign, readonly) CGFloat boundsCenterX;
@property (nonatomic, assign, readonly) CGFloat boundsCenterY;
@property (nonatomic, assign) CGPoint origin;
@property (nonatomic, assign) CGSize size;
@end
NS_ASSUME_NONNULL_END
| 24.333333 | 62 | 0.753425 |
ba5b42bdfd09c47768a005a3512c7e1999860c37 | 6,516 | c | C | interfaces/I2C-Master-Slave/I2C_Master/src/main.c | svdpuranik/BLE_SDK6_examples | 1eedc9ae8922e1c0bc4fc1337639085fbb9eeba0 | [
"MIT"
] | 27 | 2021-04-14T06:21:04.000Z | 2022-03-24T02:02:13.000Z | interfaces/I2C-Master-Slave/I2C_Master/src/main.c | svdpuranik/BLE_SDK6_examples | 1eedc9ae8922e1c0bc4fc1337639085fbb9eeba0 | [
"MIT"
] | 10 | 2021-05-03T13:24:43.000Z | 2022-03-21T15:06:42.000Z | interfaces/I2C-Master-Slave/I2C_Master/src/main.c | svdpuranik/BLE_SDK6_examples | 1eedc9ae8922e1c0bc4fc1337639085fbb9eeba0 | [
"MIT"
] | 22 | 2021-04-29T14:30:09.000Z | 2022-03-23T03:10:40.000Z | /**
*******************************************************************************
*
* THIS SOFTWARE IS AN UNOFFICIAL RELEASE FROM DIALOG SEMICONDUCTOR (‘DIALOG’)
* AND MAY ONLY BE USED BY RECIPIENT AT ITS OWN RISK AND WITHOUT SUPPORT OF ANY
* KIND. THIS SOFTWARE IS SOLELY FOR USE ON AUTHORIZED DIALOG PRODUCTS AND
* PLATFORMS. RECIPIENT SHALL NOT TRANSMIT ANY SOFTWARE SOURCE CODE TO ANY THIRD
* PARTY WITHOUT DIALOG’S PRIOR WRITTEN PERMISSION.
*
* TO THE FULLEST EXTENT PERMITTED BY LAW, THE SOFTWARE IS DELIVERED “AS IS”,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,
* INCLUDING, BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF FITNESS FOR A
* PARTICULAR PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT, AND ALL
* WARRANTIES THAT MAY ARISE FROM COURSE OF DEALING, CUSTOM OR USAGE IN TRADE.
* FOR THE SAKE OF CLARITY, DIALOG AND ITS AFFILIATES AND ITS AND THEIR
* SUPPLIERS DO NOT WARRANT, GUARANTEE OR MAKE ANY REPRESENTATIONS (A) REGARDING
* THE USE, OR THE RESULTS OF THE USE, OF THE LICENSED SOFTWARE IN TERMS OF
* CORRECTNESS, COMPLETENESS, ACCURACY, RELIABILITY OR OTHERWISE, AND (B) THAT
* THE LICENSED SOFTWARE HAS BEEN TESTED FOR COMPLIANCE WITH ANY REGULATORY OR
* INDUSTRY STANDARD, INCLUDING, WITHOUT LIMITATION, ANY SUCH STANDARDS
* PROMULGATED BY THE FCC OR OTHER LIKE AGENCIES.
*
* IN NO EVENT SHALL DIALOG BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/**
*******************************************************************************
*
* @file main.c
*
*******************************************************************************
*/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "arch_system.h"
#include "user_periph_setup.h"
#include "i2c.h"
#include "gpio.h"
#include "uart.h"
#include "uart_utils.h"
#include "syscntl.h"
void write_buffer_initialization(void *buffer, uint16_t len, uint8_t cell_size);
void i2c_master_transmit_receive(void);
static volatile unsigned int counter = 0;
uint8_t write_buffer[16];
uint8_t read_buffer[16];
static void write_cb(void *cb_data, uint16_t len, bool success)
{
counter++;
}
static void read_cb(void *cb_data, uint16_t len, bool success)
{
counter++;
}
void printbanner(void) {
printf_string(UART,"\r\n ---------------");
printf_string(UART,"\r\n I2C Master Demo");
printf_string(UART,"\r\n ---------------");
}
void printbufferdata(void) {
printf_string(UART,"\r\nThis is what the master sent to the slave\r\n");
for (size_t i = 0; i < sizeof(write_buffer); i++) {
printf_byte(UART, *(write_buffer + i));
printf_string(UART, " ");
}
printf_string(UART,"\r\n");
printf_string(UART,"\r\n");
printf_string(UART,"\r\nThis is what the master received from the slave\r\n");
for (size_t i = 0; i < sizeof(read_buffer); i++) {
printf_byte(UART, *(read_buffer + i));
printf_string(UART, " ");
}
printf_string(UART,"\r\n");
}
void busy_wait(uint32_t delay) {
for (volatile uint32_t i = 0; i < delay; i++);
}
//Write/Read multiple bytes to/From I2C slave asynchronously.
void i2c_master_transmit_receive(void) {
printbanner();
while (1) {
while(GPIO_GetPinStatus(KEY_PORT, KEY_PIN)) {
__nop();
}
// this is for the key debouncing,
// not a clever way but this is just a demo.
busy_wait(BUSY_WAIT_AMOUNT);
i2c_cfg_t i2c_configuration;
memset(&write_buffer, 0, sizeof(write_buffer));
memset(&read_buffer, 0, sizeof(read_buffer));
memset(&i2c_configuration, 0, sizeof(i2c_configuration));
i2c_configuration.speed = I2C_SPEED_MODE;
i2c_configuration.mode = I2C_MODE_MASTER;
i2c_configuration.addr_mode = I2C_ADDRESS_MODE;
i2c_configuration.address = I2C_TARGET_ADDRESS;
i2c_configuration.clock_cfg.fs_hcnt = I2C_FS_SCL_HCNT_REG_RESET;
i2c_configuration.clock_cfg.fs_lcnt = I2C_FS_SCL_LCNT_REG_RESET;
i2c_configuration.clock_cfg.ss_hcnt = I2C_SS_SCL_HCNT_REG_RESET;
i2c_configuration.clock_cfg.ss_lcnt = I2C_SS_SCL_LCNT_REG_RESET;
i2c_configuration.tx_fifo_level = 15;
i2c_configuration.rx_fifo_level = 15;
//Initialisation
write_buffer_initialization(write_buffer, sizeof(write_buffer), sizeof(write_buffer[0]));
i2c_init(&i2c_configuration);
counter = 0;
// Write data to slave
i2c_master_transmit_buffer_async(write_buffer, sizeof(write_buffer), write_cb, NULL, I2C_FLAGS );
/* wait for write to complete */
while (counter < 1) {
__WFI();
}
//wait some time from test to test for slave to become idle
for (volatile int k = 0; k < 25000; k++);
//wait some time from test to test for slave to become idle
for (volatile int k = 0; k < 25000; k++);
// Receive data from the slave
i2c_master_receive_buffer_async(read_buffer, sizeof(read_buffer), read_cb, NULL, I2C_FLAGS);
/* wait for read to complete */
while (counter < 2) {
__WFI();
}
//wait some time from test to test for slave to become idle
for (volatile int k = 0; k < 25000; k++);
//wait some time from test to test for slave to become idle
for (volatile int k = 0; k < 25000; k++);
//Print Data
printbufferdata();
}
}
void write_buffer_initialization(void *buffer, uint16_t len, uint8_t cell_size)
{
uint8_t *temp_buffer8 = (uint8_t *)buffer;
uint16_t *temp_buffer16 = (uint16_t *)buffer;;
uint8_t * ram1 = (uint8_t *) 0x07FC0000;
/* Initialize table with values from memory */
if (cell_size == 1)
{
memcpy(temp_buffer8, ram1, len);
}
if (cell_size == 2)
{
for (uint16_t i = 0 ; i < len; i++)
{
temp_buffer16[i] = 0x00FF & (*ram1);
(ram1)++;
}
}
}
/**
*******************************************************************************
* @brief main function
*
*******************************************************************************
*/
int main (void) {
system_init();
periph_init();
i2c_master_transmit_receive();
// should never reach here.
GPIO_SetActive(LED_PORT, LED_PIN);
while(1);
}
| 29.753425 | 101 | 0.653775 |
0f9aa43d7a74e8e93045e79a43b8d1c74bca029e | 2,746 | c | C | V2.0/contrib/maybe/bloom/Util.c | oldbitpusher/npasswd | c0d535196d0d26bde72f44e4883a5be0a841c6b7 | [
"BSD-4-Clause-UC"
] | null | null | null | V2.0/contrib/maybe/bloom/Util.c | oldbitpusher/npasswd | c0d535196d0d26bde72f44e4883a5be0a841c6b7 | [
"BSD-4-Clause-UC"
] | null | null | null | V2.0/contrib/maybe/bloom/Util.c | oldbitpusher/npasswd | c0d535196d0d26bde72f44e4883a5be0a841c6b7 | [
"BSD-4-Clause-UC"
] | null | null | null | /*----------------------------------------------------------------------------*
| |
| Author: Donald Olivier |
| Instructional Computing Facility |
| Harvard School of Public Health |
| 677 Huntington Ave. |
| Boston, MA 02115 |
| don@hsph.harvard.edu |
| |
| This code may be distributed freely, provided this notice is retained. |
| |
*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*
| Util.c |
| Utility routines |
*----------------------------------------------------------------------------*/
#include <ctype.h>
#include <stdio.h>
#include "Util.h"
/*----------------------------------------------------------------------------*
| IsVowel: is a character aeiouAEIOU |
| IsInCap: is a character a non-word-initial and non-word-final cap |
*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*
| IsVowel |
*----------------------------------------------------------------------------*/
int
IsVowel(c)
char c;
{
return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ||
c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U';
}
/*----------------------------------------------------------------------------*
| IsInCap |
*----------------------------------------------------------------------------*/
int
IsInCap(p, s)
char* p; /* pointer to character */
char* s; /* pointer to string */
{
if (!isupper(*p)) return 0;
if (!isalnum(*(p+1))) return 0;
if (p == s) return 0;
if (!isalnum(*(p-1))) return 0;
return 1;
}
/*----------------------------------------------------------------------------*
| CantHappen |
*----------------------------------------------------------------------------*/
void
CantHappen()
{
fprintf(stderr, "Can't happen\n");
abort();
}
| 41.606061 | 79 | 0.201748 |
4451c9876a3d97cde8f66b677df4c2f6c9b8fa6b | 18,254 | c | C | src/mlp/c/mlp.c | augustomatheuss/ia-hub | c36f120e4d090acfa274ce8f376934af15dd6a6e | [
"BSD-2-Clause"
] | null | null | null | src/mlp/c/mlp.c | augustomatheuss/ia-hub | c36f120e4d090acfa274ce8f376934af15dd6a6e | [
"BSD-2-Clause"
] | null | null | null | src/mlp/c/mlp.c | augustomatheuss/ia-hub | c36f120e4d090acfa274ce8f376934af15dd6a6e | [
"BSD-2-Clause"
] | null | null | null | /* C Multilayer Perceptron Neural Network Library
*
* Copyright (c) 2016, Augusto Damasceno.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "mlp.h"
/* Integer Vector Rand Permutation */
/* The pseudo-random number generator must be initialized */
void vperm(int * a, int sz)
{
int i;
int m = ceil(sz/2);
int sw;
int r;
for(i=0; i<m; i++)
{
r = rand() % sz;
sw = a[i];
a[i] = a[r];
a[r] = sw;
}
}
/* Mean Square Error Batch Mode */
double mseb(double ** reference, double ** output,\
int nexamples, int noutputs)
{
int e;
int o;
double serror;
double sum;
double mseb = 0.0;
for(e=0; e<nexamples; e++)
{
sum = 0.0;
for(o=0; o<noutputs; o++)
{
serror = (reference[e][o] - output[e][o]);
serror *= serror;
sum += serror;
}
mseb += sum/noutputs;
}
return (mseb/nexamples);
}
/* Matrix Memory Allocation */
double ** matrixAlloc(int r, int c)
{
double ** m = (double**) malloc(sizeof(double*)*r);
int i;
for(i=0; i<r; i++)
m[i] = (double*) malloc(sizeof(double)*c);
return m;
}
/* Get activation function id */
int getActv(char * name)
{
if (strcmp(name,"sigmoid") == 0)
{
return 1;
}
/* Reserved to update */
else if (strcmp(name,"activation2") == 0)
{
return 1;
}
else
{
return 1;
}
}
/* Sigmoid Function */
void sigmoid(double ** ori, double ** dest, int layer, double sz)
{
int i;
for(i=0; i<sz; i++)
dest[layer][i]= 1.0/(1.0+exp(-1.0*ori[layer][i]));
}
/* Layer 0 Out */
void layerOut0(double ** dest, double bias, \
double ** examples, int example, int ninputs, \
double *** weights, int nneurons, int activation)
{
int i;
int j;
double sum;
for(i=0; i<(nneurons); i++)
{
sum = 0;
for(j=0; j<(ninputs+1); j++)
{
if (j)
{
sum += examples[example][j-1] * weights[0][i][j];
}
else
{
sum += bias * weights[0][i][j];
}
}
dest[0][i] = sum;
}
switch(activation)
{
case 1:
sigmoid(dest,dest,0,nneurons);
break;
default:
sigmoid(dest,dest,0,nneurons);
break;
}
}
/* Layer 1 and Following Out */
void layersOut(double ** dest, double bias, int nOutsPrev, \
double *** weights, int layer, int nneurons, int activation)
{
int i;
int j;
double sum;
for(i=0; i<(nneurons); i++)
{
sum = 0;
for(j=0; j<(nOutsPrev+1); j++)
{
if (j)
{
sum += dest[layer-1][j-1]*weights[layer][i][j];
}
else
{
sum += bias*weights[layer][i][j];
}
}
dest[layer][i] = sum;
}
switch(activation)
{
case 1:
sigmoid(dest,dest,layer,nneurons);
break;
default:
sigmoid(dest,dest,layer,nneurons);
break;
}
}
/* Error = (desired output) - (reference output) */
void errorMLP(double *error, double ** ref, int example, \
double ** yout, int layer, int outs)
{
int i;
for(i=0; i<outs; i++)
error[i] = ref[example][i] - yout[layer][i];
}
/* Derivative of the activation function = df */
void dActivation(double ** df, double ** yout, \
int layer, int outs, int activation)
{
int i;
switch(activation)
{
case 1:
for(i=0; i<outs; i++)
df[layer][i] = yout[layer][i] * (1 - yout[layer][i]);
break;
default:
for(i=0; i<outs; i++)
df[layer][i] = yout[layer][i] * (1 - yout[layer][i]);
break;
}
}
/* Local gradient. Last layer = Error * df. */
void gradientLast(double ** gradient, double * error, \
double ** df, int layer, int neurons)
{
int i;
for(i=0; i<neurons; i++)
gradient[layer][i] = error[i] * df[layer][i];
}
/* Local gradient. Layer 0 until (layers-1) */
void gradient(double ** gradient, double ** wgs, \
double ** df, int layer, int neurons)
{
int i;
for(i=0; i<neurons; i++)
gradient[layer][i] = wgs[layer][i] * df[layer][i];
}
/* Copy Weights */
void weightsCopy(double *** ori, double *** dest,\
int * neurons, int nlayers, int ninputs)
{
double *** weights = (double***) \
weightsAlloc(neurons, nlayers, ninputs);
int layer;
int neuron;
int weight;
for(layer=0; layer<nlayers; layer++)
{
for(neuron=0; neuron<neurons[layer]; neuron++)
{
if(layer)
{
for(weight=0; weight<(neurons[layer-1]+1); weight++)
{
dest[layer][neuron][weight] =\
ori[layer][neuron][weight];
}
}
else
{
for(weight=0; weight<(ninputs+1); weight++)
{
dest[layer][neuron][weight] =\
ori[layer][neuron][weight];
}
}
}
}
}
/* Update Layer 1 and Following */
void updateLayer(double *** weights,double alpha, \
double *** weightsPast, double lrate, double ** gs, double bias, \
double ** yout, int layer, int neurons, int neuronsPrev)
{
int neuron;
int weight;
for(neuron=0; neuron<neurons; neuron++)
{
for(weight=0; weight<(neuronsPrev+1); weight++)
{
if(weight)
{
weights[layer][neuron][weight] = \
weights[layer][neuron][weight] + \
alpha * weightsPast[layer][neuron][weight] + \
lrate*gs[layer][neuron]*yout[layer-1][weight-1];
}
else
{
weights[layer][neuron][weight] = \
weights[layer][neuron][weight] + \
alpha * weightsPast[layer][neuron][weight] + \
lrate*gs[layer][neuron]*bias;
}
}
}
}
/* Update layer 0 */
void updateLayer0(double *** weights,double alpha, \
double *** weightsPast, double lrate, double ** gs, double bias, \
double ** ref, int example, int neurons, int ninputs)
{
int neuron;
int weight;
for(neuron=0; neuron<neurons; neuron++)
{
for(weight=0; weight<(ninputs+1); weight++)
{
if(weight)
{
weights[0][neuron][weight] = \
weights[0][neuron][weight] + \
alpha * weightsPast[0][neuron][weight] + \
lrate*gs[0][neuron]*ref[example][weight-1];
}
else
{
weights[0][neuron][weight] = \
weights[0][neuron][weight] + \
alpha * weightsPast[0][neuron][weight] + \
lrate*gs[0][neuron]*bias;
}
}
}
}
/* SUM WtGs = sum of (next layer G * next layer weights) */
/* Ignore the weights relative to bias */
void sumWtGs(double ** wgs, double *** weights, double ** gs, \
int nextLayer, int neuronsNextLayer, int neurons)
{
int neuron;
int weight;
for(weight=1; weight<(neurons+1); weight++)
{
wgs[nextLayer-1][weight] = 0;
for(neuron=0; neuron<(neuronsNextLayer); neuron++)
{
wgs[nextLayer-1][weight-1] += gs[nextLayer][weight] * \
weights[nextLayer][neuron][weight];
}
}
}
/* Memory Allocation of the Weights */
double *** weightsAlloc(int * neurons, int nlayers, int ninputs)
{
int layer;
int neuron;
int weight;
double *** weights =\
(double ***) malloc(sizeof(double**)*nlayers);
if(weights == NULL)
return NULL;
for(layer=0; layer<nlayers; layer++)
{
weights[layer] = \
(double **) malloc(sizeof(double*)*neurons[layer]);
if(weights[layer] == NULL)
return NULL;
for(neuron=0; neuron<neurons[layer]; neuron++)
{
if(layer)
{
weights[layer][neuron] = (double *) \
malloc(sizeof(double)*(neurons[layer-1]+1));
}
else
{
weights[layer][neuron] = (double *) \
malloc(sizeof(double)*(ninputs+1));
}
if(weights[layer][neuron] == NULL)
return NULL;
}
}
return weights;
}
/* Deallocate memory of a traning struct */
void trainingDestruct(training * tr)
{
int i;
free(tr->neurons);
free(tr->bias);
for(i=1; i<tr->examples; i++)
{
free(tr->x[i]);
free(tr->reference[i]);
}
free(tr->x);
free(tr->reference);
free(tr);
}
/* Print the training struct */
void trainingPrint(training * tr)
{
int i;
printf("Training Data\n\n");
printf(">> Architecture\n");
printf("Layers: %d\n",tr->nlayers);
for(i=0; i<tr->nlayers; i++)
{
if(tr->neurons[i] == 1)
{
printf("\tLayer %d: 1 neuron\n",i);
}
else
{
printf("\tLayer %d: %d neurons\n",i,tr->neurons[i]);
}
}
for(i=0; i<tr->nlayers; i++)
printf("\tBias of Layer %d: %f\n",i,tr->bias[i]);
printf("Inputs: %d\n",tr->ninputs);
printf("\n>> Training Parameters\n");
printf("Alpha: %.4e\n",tr->alpha);
printf("Learning Rate: %.8f\n",tr->lrate);
printf("Accepted Error: %.4e\n",tr->acceptedError);
printf("Maximum Iteration: %ld\n",tr->maxIteration);
}
/* MLP initialization */
double *** initMLP(int * neurons, int nlayers, int ninputs)
{
#ifdef DEBUG_MODE
printf("Initializing MLP weights\n");
#endif
double *** weights = weightsAlloc(neurons, nlayers, ninputs);
int layer;
int neuron;
int weight;
srand(time(NULL));
for(layer=0; layer<nlayers; layer++)
{
for(neuron=0; neuron<neurons[layer]; neuron++)
{
if(layer)
{
for(weight=0; weight<(neurons[layer-1]+1); weight++)
{
weights[layer][neuron][weight] =\
(double) rand()/RAND_MAX;
#ifdef DEBUG_MODE
printf("Layer %d - Neuron %d",layer,neuron);
printf(" - Weight %d: %.6f\n",\
weight,weights[layer][neuron][weight]);
#endif
}
}
else
{
for(weight=0; weight<(ninputs+1); weight++)
{
weights[layer][neuron][weight] =\
(double) rand()/RAND_MAX;
#ifdef DEBUG_MODE
printf("Layer %d - Neuron %d",layer,neuron);
printf(" - Weight %d: %.6f\n",\
weight,weights[layer][neuron][weight]);
#endif
}
}
}
}
#ifdef DEBUG_MODE
printf("\n");
#endif
return weights;
}
/* MLP Training */
double * trainingMLP(double *** weights, training * trainingData, \
char * activation)
{
int nlayers = trainingData->nlayers;
int * neurons = trainingData->neurons;
int ninputs = trainingData->ninputs;
double alpha = trainingData->alpha;
double * bias = trainingData->bias;
double ** x = trainingData->x;
int examples = trainingData->examples;
double ** ref = trainingData->reference;
double lrate = trainingData->lrate;
double acceptedError = trainingData->acceptedError;
long int maxIteration = trainingData->maxIteration;
int layer;
int neuron;
int weight;
int i;
int j;
int actv = getActv(activation);
/* Memory of past weights and swap weights */
double *** weightsPast = weightsAlloc(neurons, nlayers, ninputs);
double *** weightsSwap = weightsAlloc(neurons, nlayers, ninputs);
for(layer=0; layer<nlayers; layer++)
{
for(neuron=0; neuron<neurons[layer]; neuron++)
{
if(layer)
{
for(weight=0; weight<(neurons[layer-1]+1); weight++)
weightsPast[layer][neuron][weight] = 0;
}
else
{
for(weight=0; weight<(ninputs+1); weight++)
weightsPast[layer][neuron][weight] = 0;
}
}
}
if(weightsPast == NULL)
return NULL;
/* Memory for layers outputs */
double ** yout = (double**) malloc(sizeof(double*)*nlayers);
for(i=0; i<nlayers; i++)
yout[i] = (double*) malloc(sizeof(double)*neurons[i]);
/* Memory for last layers outputs of the examples */
double ** youtLastLayers = (double**) \
malloc(sizeof(double*)*examples);
for(i=0; i<examples; i++)
{
youtLastLayers[i] = (double*) \
malloc(sizeof(double)*neurons[nlayers-1]);
}
/* MLP error */
double * error = (double*) \
malloc(sizeof(double)*neurons[nlayers-1]);
/* Derivative of the activation function */
double ** df = (double**) \
malloc(sizeof(double*)*nlayers);
for(i=0; i<nlayers; i++)
df[i] = (double*) malloc(sizeof(double)*neurons[i]);
/* Local gradient. */
/* Last layer = Error * df. */
/* Others layers = df * SUM */
/* SUM = sum of (next layer G * next layer weights) */
double ** gs = (double**) \
malloc(sizeof(double*)*nlayers);
for(i=0; i<nlayers; i++)
gs[i] = (double*) malloc(sizeof(double)*neurons[i]);
/* SUM WtGs = sum of (next layer G * next layer weights) */
/* Ignore the weights relative to bias */
double ** wgs = (double**) \
malloc(sizeof(double*)*nlayers-1);
for(i=0; i<(nlayers-1); i++)
wgs[i] = (double*) malloc(sizeof(double)*neurons[i]);
/* Mean Square Error */
double mse = acceptedError+1;
/* Index of examples */
int * xidx = (int*) malloc(sizeof(int)*examples);
for(i=0; i<examples; i++)
xidx[i] = i;
/* Training loop */
int ex = 0;
long int counter = 0;
/* The position 0 of mse_hist is the last position of history */
long int mse_counter = 1;
double * mse_hist = (double*) \
malloc(sizeof(double)*floor(maxIteration/examples));
int progress = 0;
int displayStep = ceil(0.05*maxIteration);
vperm(xidx,examples);
while(mse > acceptedError && counter < maxIteration)
{
/* Iteration Number */
counter++;
/* Number of Training Example */
ex = (ex % examples)+1;
/* Propagation */
/* Out of first layer */
layerOut0(yout,bias[0],x,xidx[(ex-1)],ninputs,\
weights,neurons[0],actv);
for(layer=1; layer<nlayers; layer++)
{
/* Out of "layer" layer */
layersOut(yout,bias[layer],neurons[layer-1], \
weights,layer,neurons[layer],actv);
}
/* Backpropagation */
/* Neuron Update = learning-rate*G*y(layer-1) */
/* Error = yref - y */
errorMLP(error,ref,xidx[(ex-1)],yout,nlayers-1, \
neurons[nlayers-1]);
/* Derivative of the activation function = df */
dActivation(df,yout,nlayers-1,neurons[nlayers-1],actv);
/* Local gradient. Last layer = Error * df */
gradientLast(gs,error,df,nlayers-1,neurons[nlayers-1]);
/* Save weights in swap weights*/
weightsCopy(weights,weightsSwap,neurons,nlayers,ninputs);
/* Update layer */
updateLayer(weights,alpha,weightsPast, lrate, gs, \
bias[nlayers-1], yout, nlayers-1, neurons[nlayers-1], \
neurons[nlayers-2]);
/* Update layers */
for(i=nlayers-2; i>=0; i--)
{
/* SUM GsW */
sumWtGs(wgs,weights,gs,i+1,neurons[i+1],neurons[i]);
/* Derivative of the activation function = df */
dActivation(df,yout,i,neurons[i],actv);
/* Local gradient. */
/* df * sum of (next layer G * next layer weights) */
gradient(gs,wgs,df,i,neurons[i]);
/* Update layer. */
if(i)
{
updateLayer(weights,alpha,weightsPast, \
lrate, gs, bias[i], yout, i, neurons[i], \
neurons[i-1]);
}
else
{
updateLayer0(weights,alpha,weightsPast, \
lrate, gs, bias[i], x, xidx[ex-1], \
neurons[i], ninputs);
}
}
/* Save past weights */
weightsCopy(weightsSwap,weightsPast,neurons,nlayers,ninputs);
/* Save output of the examples */
for(i=0; i<neurons[nlayers-1]; i++)
youtLastLayers[xidx[ex-1]][i] = yout[nlayers-1][i];
/* Mean Square Error. */
if (ex == examples)
{
/* MSE */
mse = mseb(ref,youtLastLayers, \
examples,neurons[nlayers-1]);
/* Change order of training set */
vperm(xidx,examples);
/* Save history of MSE */
mse_hist[mse_counter] = mse;
mse_counter += 1;
}
/* Display the progress */
#ifdef DEBUG_MODE
if( (progress % displayStep) == 0 )
{
printf("%.2f%% of maximum iteration.\n",
(float) (counter*100)/maxIteration);
printf("MSE: %.4e\n",mse);
}
progress += 1;
#endif
}
/* Add in the position '0' the 'mse_counter'-1
* to identify the last position of history
*/
mse_hist[0] = mse_counter-1;
/* Deallocate memory */
// weightsPast
// yout
// youtLastLayers
// error
// gs
// df
// wgs
// xidx
/* Return history of MSE */
return mse_hist;
}
/* Output of MLP */
void outMLP(double *** weights, training * trainingData, \
char * activation, double ** in, int pos, double * out)
{
int nlayers = trainingData->nlayers;
int * neurons = trainingData->neurons;
int ninputs = trainingData->ninputs;
double alpha = trainingData->alpha;
double * bias = trainingData->bias;
int layer;
int i;
int actv = getActv(activation);
/* Memory for layers outputs */
double ** yout = (double**) malloc(sizeof(double*)*nlayers);
for(i=0; i<nlayers; i++)
yout[i] = (double*) malloc(sizeof(double)*neurons[i]);
/* Propagation */
/* Out of first layer */
layerOut0(yout,bias[0],in,pos,ninputs,\
weights,neurons[0],actv);
for(layer=1; layer<nlayers; layer++)
{
/* Out of "layer" layer */
layersOut(yout,bias[layer],neurons[layer-1], \
weights,layer,neurons[layer],actv);
}
/* Copy output of last layer to out */
for(i=0; i<neurons[nlayers-1]; i++)
out[i] = yout[nlayers-1][i];
/* Deallocate 'yout' memory */
for(i=0; i<nlayers; i++)
free(yout[i]);
free(yout);
}
/* Save training data and weights of MLP in a file */
void saveMLP(char * filename, training * trainingData, \
double *** weights)
{
}
/* Load the examples, references and configuration from files. */
int loadExamplesFromFile(char * inputs, char * outputs, \
char * conf, training * trainingData);
/* Print the neural network */
void printMLP(double *** weights, training * trainingData)
{
int nlayers = trainingData->nlayers;
int * neurons = trainingData->neurons;
int ninputs = trainingData->ninputs;
double * bias = trainingData->bias;
int l;
int n;
int w;
printf("\n--------------------\n");
printf("Neural Network\n\nInputs: %d\nLayers: %d",\
ninputs,nlayers);
printf("\nOutputs: %d\n\n", neurons[nlayers-1]);
for(l=0; l<nlayers; l++)
{
printf("Layer %d\nBias: %.6f\n",l,bias[l]);
for(n=0; n<neurons[l]; n++)
{
printf(" Neuron %d\n",n);
if(l)
{
for(w=0; w<(neurons[l-1]+1); w++)
printf(" Weight %d: %.6f\n",w,weights[l][n][w]);
}
else
{
for(w=0; w<(ninputs+1); w++)
printf(" Weight %d: %.6f\n",w,weights[l][n][w]);
}
}
}
printf("\n--------------------\n");
}
| 23.106329 | 81 | 0.624466 |
4154ef850760a1fcbe26c11ca8d3a046bcae2aab | 1,498 | h | C | source/idhook.h | playday3008/hack-cs-1.6-eV0L | 40bdc3ef0fbe4d14a24939417efed6df58efe856 | [
"MIT"
] | 5 | 2020-05-02T17:29:32.000Z | 2021-09-20T19:19:15.000Z | source/idhook.h | playday3008/hack-cs-1.6-eV0L | 40bdc3ef0fbe4d14a24939417efed6df58efe856 | [
"MIT"
] | null | null | null | source/idhook.h | playday3008/hack-cs-1.6-eV0L | 40bdc3ef0fbe4d14a24939417efed6df58efe856 | [
"MIT"
] | 3 | 2020-05-02T19:03:48.000Z | 2021-09-22T03:44:22.000Z | #ifndef _IDHOOK_
#define _IDHOOK_
class IdHook
{
public:
int FirstKillPlayer[33];
void ClearPlayer();
void RelistPlayer();
void AddPlayer(int ax);
struct Player;
struct PlayerEntry{
PlayerEntry() :player(0){}
char name[256];
char content[256];
Player* player;
};
struct Player
{
Player():parent(0),selection(0),seekselection(0){}
void boundSelection()
{
// wrap around
if(selection<0) { selection = items.size()-1; seekselection = 2;}
else if(selection >= (int)items.size()) { selection = 0; seekselection = 0;}
if(selection==items.size()-1){seekselection = 2;}
else if(selection==items.size()-2){seekselection = 1;}
else {seekselection = 0;}
}
void boundSelection1()
{
// wrap around
if(selection<0)
{
selection = 0;
}
else if(selection >= (int)items.size()-3)
{
if(seekselection == 0)
selection = items.size()-3;
else if(seekselection == 1)
selection = items.size()-2;
else if(seekselection == 2)
selection = items.size()-1;
}
else
{
if(seekselection == 1)
selection = items.size()-2;
else if(seekselection == 2)
selection = items.size()-1;
}
}
Player* parent;
string name;
int selection;
int seekselection;
vector<PlayerEntry> items;
};
IdHook():basePlayer(0){}
void init();
struct Player* basePlayer;
};
void ListIdHook();
void ID_HookCommands();
void DrawIDHookWindow();
void func_player_toggle();
extern IdHook idhook;
#endif | 19.454545 | 80 | 0.634179 |
41d1c260b7cbe9d20e0d96b1616d20f058b382be | 5,401 | h | C | ns3/ns-3.26/src/config-store/model/display-functions.h | Aedemon/clusim | 7f09cdb79b5f02cf0fed1bd44842981941f29f32 | [
"Apache-2.0"
] | 11 | 2015-11-24T11:07:28.000Z | 2021-12-23T04:10:29.000Z | ns3/ns-3.26/src/config-store/model/display-functions.h | Aedemon/clusim | 7f09cdb79b5f02cf0fed1bd44842981941f29f32 | [
"Apache-2.0"
] | 3 | 2017-08-11T03:04:59.000Z | 2017-09-11T14:01:14.000Z | ns3/ns-3.26/src/config-store/model/display-functions.h | Aedemon/clusim | 7f09cdb79b5f02cf0fed1bd44842981941f29f32 | [
"Apache-2.0"
] | 6 | 2016-03-01T06:32:21.000Z | 2022-03-24T19:31:41.000Z | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Authors: Faker Moatamri <faker.moatamri@sophia.inria.fr>
* Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#ifndef DISPLAY_FUNCTIONS_H
#define DISPLAY_FUNCTIONS_H
#include "model-node-creator.h"
#include "model-typeid-creator.h"
#include <gtk/gtk.h>
namespace ns3 {
/**
* This function includes the name of the attribute or the editable value
* in the second column
*/
void
cell_data_function_col_1 (GtkTreeViewColumn *col, GtkCellRenderer *renderer,
GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data);
/**
* This function includes the name of the object, pointer, vector or vector item
* in the first column
*/
void
cell_data_function_col_0 (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model,
GtkTreeIter *iter, gpointer user_data);
/**
* This is the callback called when the value of an attribute is changed
*/
void
cell_edited_callback (GtkCellRendererText *cell, gchar *path_string,
gchar *new_text, gpointer user_data);
/**
* This function gets the column number 0 or 1 from the mouse
* click
*/
int
get_col_number_from_tree_view_column (GtkTreeViewColumn *col);
/**
* This function displays the tooltip for an object, pointer, vector
* item or an attribute
*/
gboolean
cell_tooltip_callback (GtkWidget *widget, gint x, gint y, gboolean keyboard_tip,
GtkTooltip *tooltip, gpointer user_data);
/**
* This is the main view opening the widget, getting tooltips and drawing the
* tree of attributes...
*/
GtkWidget *
create_view (GtkTreeStore *model);
/**
* This is the action done when the user presses on the save button.
* It will save the config to a file.
*/
void
save_clicked (GtkButton *button, gpointer user_data);
/**
* If the user presses the button load, it will load the config file into memory.
*/
void
load_clicked (GtkButton *button, gpointer user_data);
/**
* Exit the window when exit button is pressed
*/
void
exit_clicked_callback (GtkButton *button, gpointer user_data);
/**
* Exit the application
*/
gboolean
delete_event_callback (GtkWidget *widget, GdkEvent *event, gpointer user_data);
/**
* Delete the tree model contents
*/
gboolean
clean_model_callback (GtkTreeModel *model, GtkTreePath *path,
GtkTreeIter *iter, gpointer data);
/************************** display functions used by default configurator **********************/
/**
* This function writes data in the second column, this data is going to be editable
* if it is a NODE_ATTRIBUTE
*/
void
cell_data_function_col_1_config_default (GtkTreeViewColumn *col, GtkCellRenderer *renderer,
GtkTreeModel *model, GtkTreeIter *iter,
gpointer user_data);
/**
* This function writes the attribute or typeid name in the column 0
*/
void
cell_data_function_col_0_config_default (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model,
GtkTreeIter *iter, gpointer user_data);
/**
* This is the action done when the user presses on the save button.
* It will save the config to a file.
*/
void
save_clicked_default (GtkButton *button, gpointer user_data);
/**
* If the user presses the button load, it will load the config file into memory.
*/
void
load_clicked_default (GtkButton *button, gpointer user_data);
/**
* This functions is called whenever there is a change in the value of an attribute
* If the input value is ok, it will be updated in the default value and in the
* gui, otherwise, it won't be updated in both.
*/
void
cell_edited_callback_config_default (GtkCellRendererText *cell, gchar *path_string,
gchar *new_text, gpointer user_data);
/**
* This function is used to display a tooltip whenever the user puts the mouse
* over a type ID or an attribute. It will give the type and the possible values of
* an attribute value and the type of the object for an attribute object or a
* typeID object
*/
gboolean
cell_tooltip_callback_config_default (GtkWidget *widget, gint x, gint y,
gboolean keyboard_tip, GtkTooltip *tooltip, gpointer user_data);
/**
* This is the main view opening the widget, getting tooltips and drawing the
* tree of attributes
*/
GtkWidget *
create_view_config_default (GtkTreeStore *model);
/**
* Delete the tree model contents
*/
gboolean
clean_model_callback_config_default (GtkTreeModel *model, GtkTreePath *path,
GtkTreeIter *iter, gpointer data);
} //end namespace ns3
#endif
| 35.768212 | 113 | 0.701166 |
5798a0a95032393c469223225fcd96b61d43fe62 | 1,864 | h | C | include/behavior_tree_ros/plugins/decorator/cmd_updater_node.h | hackin-zhao/behavior_tree_ros | 3eaf5c89696fc982d205c313e703fa0b097911ed | [
"MIT"
] | 2 | 2022-03-22T08:47:39.000Z | 2022-03-23T05:45:23.000Z | include/behavior_tree_ros/plugins/decorator/cmd_updater_node.h | hackin-zhao/behavior_tree_ros | 3eaf5c89696fc982d205c313e703fa0b097911ed | [
"MIT"
] | null | null | null | include/behavior_tree_ros/plugins/decorator/cmd_updater_node.h | hackin-zhao/behavior_tree_ros | 3eaf5c89696fc982d205c313e703fa0b097911ed | [
"MIT"
] | null | null | null | #ifndef _CMD_UPDATER_NODE_H_
#define _CMD_UPDATER_NODE_H_
#include <memory>
#include <string>
#include "behaviortree_cpp_v3/decorator_node.h"
#include <ros/ros.h>
#include <ros/callback_queue.h>
#include <geometry_msgs/PoseStamped.h>
#include <std_msgs/String.h>
namespace behavior_tree
{
/**
* @brief A BT::DecoratorNode that subscribes to a goal topic and updates
* the current goal on the blackboard
*/
class CmdUpdater : public BT::DecoratorNode
{
public:
/**
* @brief A constructor for nav2_behavior_tree::CmdUpdater
* @param xml_tag_name Name for the XML tag for this node
* @param conf BT node configuration
*/
CmdUpdater(
const std::string &xml_tag_name,
const BT::NodeConfiguration &conf);
/**
* @brief Creates list of BT ports
* @return BT::PortsList Containing node-specific ports
*/
static BT::PortsList providedPorts()
{
return {
BT::InputPort<geometry_msgs::PoseStamped>("input_goal", "Original Goal"),
BT::OutputPort<geometry_msgs::PoseStamped>(
"output_goal",
"Received Goal by subscription"),
};
}
private:
/**
* @brief The main override required by a BT action
* @return BT::NodeStatus Status of tick execution
*/
BT::NodeStatus tick() override;
/**
* @brief Callback function for goal update topic
* @param msg Shared pointer to geometry_msgs::msg::PoseStamped message
*/
void cmdUpdatedCallback(const std_msgs::String::ConstPtr &msg);
ros::NodeHandle n_;
ros::Subscriber cmd_updater_sub_;
ros::SubscribeOptions cmd_updater_sub_opts_;
ros::CallbackQueue cmd_updater_queue_;
std::string battery_topic_;
std_msgs::String last_cmd_received_;
};
} // namespace nav2_behavior_tree
#endif // _CMD_UPDATER_NODE_H_
| 25.888889 | 83 | 0.677575 |
70b9b0a9d0595090e44d7679c05d3f539c6e462d | 350 | h | C | QSToolKit/QSToolKit.h | qs3673132/QSToolKit | a28f048cb16becf0477907e1e5a8e320efdcc9bd | [
"MIT"
] | null | null | null | QSToolKit/QSToolKit.h | qs3673132/QSToolKit | a28f048cb16becf0477907e1e5a8e320efdcc9bd | [
"MIT"
] | null | null | null | QSToolKit/QSToolKit.h | qs3673132/QSToolKit | a28f048cb16becf0477907e1e5a8e320efdcc9bd | [
"MIT"
] | null | null | null | //
// QSToolKit.h
// QSToolKit
//
// Created by qs on 16/10/30.
// Copyright © 2016年 齐嵩. All rights reserved.
//
#import <Foundation/Foundation.h>
FOUNDATION_EXPORT double QSToolKitVersionNumber;
FOUNDATION_EXPORT const unsigned char QSToolKitVersionString[];
#import <QSToolKit/NSString+QSToolKit.h>
#import <QSToolKit/NSArray+QSToolKit.h>
| 19.444444 | 63 | 0.754286 |
02fc9e02b5e70cdbc66eeb97f5897f7c370051c1 | 3,941 | h | C | src/gui/raster/qgshillshaderendererwidget.h | dyna-mis/Hilabeling | cb7d5d4be29624a20c8a367162dbc6fd779b2b52 | [
"MIT"
] | null | null | null | src/gui/raster/qgshillshaderendererwidget.h | dyna-mis/Hilabeling | cb7d5d4be29624a20c8a367162dbc6fd779b2b52 | [
"MIT"
] | null | null | null | src/gui/raster/qgshillshaderendererwidget.h | dyna-mis/Hilabeling | cb7d5d4be29624a20c8a367162dbc6fd779b2b52 | [
"MIT"
] | 1 | 2021-12-25T08:40:30.000Z | 2021-12-25T08:40:30.000Z | /***************************************************************************
qgshillshaderendererwidget.h
---------------------------------
begin : May 2016
copyright : (C) 2016 by Nathan Woodrow
email : woodrow dot nathan at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSHILLSHADERENDERERWIDGET_H
#define QGSHILLSHADERENDERERWIDGET_H
#include "ui_qgshillshaderendererwidget.h"
#include "qgis_sip.h"
#include <QDoubleSpinBox>
#include "qgsrasterrendererwidget.h"
#include "qgis_gui.h"
/**
* \brief Renderer widget for the hill shade renderer.
* \ingroup gui
* \since QGIS 2.16
*/
class GUI_EXPORT QgsHillshadeRendererWidget: public QgsRasterRendererWidget, private Ui::QgsHillShadeWidget
{
Q_OBJECT
public:
/**
* \brief Renderer widget for the hill shade renderer.
* \param layer The layer attached for this widget.
* \param extent The current extent.
*/
QgsHillshadeRendererWidget( QgsRasterLayer *layer, const QgsRectangle &extent = QgsRectangle() );
/**
* Factory method to create the renderer for this type.
*/
static QgsRasterRendererWidget *create( QgsRasterLayer *layer, const QgsRectangle &extent ) SIP_FACTORY { return new QgsHillshadeRendererWidget( layer, extent ); }
/**
* \brief The renderer for the widget.
* \returns A new renderer for the the config in the widget
*/
QgsRasterRenderer *renderer() override;
/**
* \brief Set the widget state from the given renderer.
* \param renderer The renderer to take the state from.
*/
void setFromRenderer( const QgsRasterRenderer *renderer );
/**
* Returns the direction of the light over the raster between 0-360.
* \see setAzimuth()
*/
double azimuth() const;
/**
* Returns the angle of the light source over the raster.
* \see setAltitude()
*/
double altitude() const;
/**
* Returns the Z scaling factor.
* \see setZFactor()
*/
double zFactor() const;
/**
* Returns TRUE if the renderer should use the multi-directional hillshade algorithm.
* \see setMultiDirectional()
*/
bool multiDirectional() const;
public slots:
/**
* \brief Set the altitude of the light source
* \param altitude the altitude
* \see altitude()
*/
void setAltitude( double altitude );
/**
* \brief Set the azimuth of the light source.
* \param azimuth The azimuth of the light source, between 0 and 360.0
* \see azimuth()
*/
void setAzimuth( double azimuth );
/**
* \brief Set the Z scaling factor of the result image.
* \param zfactor The z factor
* \see zFactor()
*/
void setZFactor( double zfactor );
/**
* Sets whether to render using a multi-directional hillshade algorithm.
* \param isMultiDirectional set to TRUE to use multi directional rendering
* \see multiDirectional()
*/
void setMultiDirectional( bool isMultiDirectional );
private slots:
void mLightAzimuth_updated( double value );
void mLightAzimuthDial_updated( int value );
};
#endif // QGSSINGLEBANDGRAYRENDERERWIDGET_H
| 31.528 | 167 | 0.567622 |
27ab60ac7f3713affa5727e6b450753b6082a8b4 | 29 | h | C | .vim/sourceCode/glibc-2.16.0/include/stropts.h | lakehui/Vim_config | 6cab80dc1209b34bf6379f42b1a92790bd0c146b | [
"MIT"
] | 12 | 2018-09-18T19:51:27.000Z | 2022-01-18T15:31:41.000Z | .vim/sourceCode/glibc-2.16.0/include/stropts.h | lakehui/Vim_config | 6cab80dc1209b34bf6379f42b1a92790bd0c146b | [
"MIT"
] | null | null | null | .vim/sourceCode/glibc-2.16.0/include/stropts.h | lakehui/Vim_config | 6cab80dc1209b34bf6379f42b1a92790bd0c146b | [
"MIT"
] | 3 | 2019-06-12T19:38:54.000Z | 2020-03-05T19:17:23.000Z | #include <streams/stropts.h>
| 14.5 | 28 | 0.758621 |
b45567ece702754d456e0e1c141618f8e1aec15c | 6,224 | c | C | hal/src/software/system/mblaze/sched.c | eugenecartwright/hthreads | 826c495dd855f8fcc1e12e1ac01845c2983ecf04 | [
"BSD-3-Clause"
] | 3 | 2018-02-14T23:24:45.000Z | 2022-03-30T18:48:06.000Z | hal/src/software/system/ppc440/sched.c | eugenecartwright/hthreads | 826c495dd855f8fcc1e12e1ac01845c2983ecf04 | [
"BSD-3-Clause"
] | null | null | null | hal/src/software/system/ppc440/sched.c | eugenecartwright/hthreads | 826c495dd855f8fcc1e12e1ac01845c2983ecf04 | [
"BSD-3-Clause"
] | null | null | null | /************************************************************************************
* Copyright (c) 2015, University of Arkansas - Hybridthreads Group
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of the University of Arkansas nor the name of the
* Hybridthreads Group nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
************************************************************************************/
/** \internal
* \file sched.c
* \brief The implementation of the software level thread scheduler.
*
* \author Wesley Peck <peckw@ittc.ku.edu>\n
* Ed Komp <komp@ittc.ku.edu>
*
* FIXME: Add description
*/
#include <hthread.h>
#include <debug.h>
#include <sys/core.h>
#include <manager/manager.h>
#include <processor/processor.h>
#include <hwti/commands.h>
//#include <arch/smp.h>
//#include <arch/context.h>
// Declare the global variable used to profile context switching
////hprofile_buff_declare( CONTEXT, CONTYPE );
/*#if PROFILE_CONTEXT
static void __attribute((constructor)) profile_start( void )
{
//hprofile_buff_create( CONTEXT, CONTYPE, CONSIZE );
}
static void __attribute((destructor)) profile_finish( void )
{
//hprofile_buff_flush( CONTEXT, CONTYPE, CONOUT, CONNAME );
//hprofile_buff_close( CONTEXT, CONTYPE );
}
#endif
*/
/** \internal
* \brief Save the currently running context and restore the given context.
*
* \author Wesley Peck <peckw@eecs.ku.edu>
*
* This function saves the currently running context into the thread context
* identified by curr. The thread context identified by next is then restored
* to the CPU.
*/
void _switch_context( Huint curr, Huint next )
{
TRACE_PRINTF( TRACE_FINE, TRACE_SCHED, "SWITCH: (CUR=%d) (NXT=%d)\n", curr, next );
if( threads[next].newthread )
{
TRACE_PRINTF( TRACE_FINE, TRACE_SCHED, "SWITCH: (OP=NEW) (CUR=%d) (NXT=%d)\n", curr, next );
threads[next].newthread = Hfalse;
//hprofile_buff_time( CONTEXT, CONTYPE, curr );
//_context_save_restore_new(threads[curr].context,threads[next].context);
//hprofile_buff_time( CONTEXT, CONTYPE, curr );
}
else
{
TRACE_PRINTF( TRACE_FINE, TRACE_SCHED, "SWITCH: (OP=OLD) (CUR=%d) (NXT=%d)\n", curr, next );
//hprofile_buff_time( CONTEXT, CONTYPE, curr );
///_context_save_restore( threads[curr].context, threads[next].context );
//hprofile_buff_time( CONTEXT, CONTYPE, curr );
}
}
/** \internal
* \brief Abandon the currenly running context and restore the given context.
*
* \author Wesley Peck <peckw@eecs.ku.edu>
*
* This function abandons the currently running context. The thread context
* identified by next is restored to the CPU.
*/
void _restore_context( Huint curr, Huint next )
{
if( threads[next].newthread )
{
threads[next].newthread = Hfalse;
//hprofile_buff_time( CONTEXT, CONTYPE, curr );
//_context_restore_new( threads[curr].context, threads[next].context );
//hprofile_buff_time( CONTEXT, CONTYPE, curr );
}
else
{
TRACE_PRINTF( TRACE_FINE, TRACE_SCHED, "SWITCH: (OP=OLD) (CUR=%d) (NXT=%d)\n", curr, next );
//hprofile_buff_time( CONTEXT, CONTYPE, curr );
//_context_restore( threads[curr].context, threads[next].context );
//hprofile_buff_time( CONTEXT, CONTYPE, curr );
}
}
/** \internal
* \brief Run the scheduler.
*
* This function runs the scheduler. The function will pick a new thread
* to run and switch to that thread if it is not the currently running thread.
*
* \param save This parameters determines if the currently running context
* is saved before the new context is restored. Under normal
* circumstances this parameter should be Htrue. However, in the
* case of exiting a thread this parameter should be Hfalse.
*/
void _run_sched( Hbool save )
{
// MicroBlaze-specific V-HWTI code:
// Context switching is not allowed (a thread runs here until it terminates).
// Therefore, if save = HTrue, block, and wait until awakened
// Otherwise, (if save = HFalse), just return
// FIXME : Jason, add in MB-specific V-HWTI code to block
if (save == Htrue)
{
volatile Huint * cmd_ptr = _vhwti_command_pointer();
while(*cmd_ptr != HT_HWTI_GO);
*cmd_ptr = 0x00;
}
/* Huint curr;
Huint next;
TRACE_PRINTF( TRACE_FINE, TRACE_SCHED, "SCHED: (SAVE=0x%8.8x)\n", save );
curr = _current_thread();
next = _next_thread();
TRACE_PRINTF( TRACE_FINE, TRACE_SCHED, "SCHED: (SAVE=0x%8.8x) (CUR=%d) (NXT=%d)\n", save, curr, next );
if( curr == next ) return;
if( save ) _switch_context( curr, next );
else _restore_context( curr, next );
*/
}
| 38.184049 | 107 | 0.667898 |
7da7a9ca951e92ad6f69f1d4c74c9f5868f04c44 | 369 | h | C | src/objects/objects.h | nddvn2008/bullet-physics-playground | 2895af190054b6a38525b679cf3f241c7147ee6f | [
"Zlib"
] | 1 | 2015-10-05T01:25:18.000Z | 2015-10-05T01:25:18.000Z | src/objects/objects.h | nddvn2008/bullet-physics-playground | 2895af190054b6a38525b679cf3f241c7147ee6f | [
"Zlib"
] | null | null | null | src/objects/objects.h | nddvn2008/bullet-physics-playground | 2895af190054b6a38525b679cf3f241c7147ee6f | [
"Zlib"
] | 2 | 2015-01-02T20:02:13.000Z | 2018-02-26T03:08:43.000Z | #ifndef OBJECTS_H
#define OBJECTS_H
#include "object.h"
#include <btBulletDynamicsCommon.h>
class Objects : public Object {
public:
Objects();
QList<Object *>getObjects() const;
static void luaBind(lua_State *s);
QString toString() const;
virtual void renderInLocalFrame(QTextStream *s);
protected:
QList<Object *> _objects;
};
#endif // CUBE_H
| 14.192308 | 50 | 0.715447 |
7b05c7327887b2748da4933d7f21667c5a811743 | 2,314 | c | C | gurba/lib/cmds/player/search.c | DEFCON-MUD/defcon-28-mud-source | b25b5bd15fee6a4acda5119ea864bde4dff62714 | [
"Unlicense"
] | 4 | 2021-07-21T17:49:01.000Z | 2022-03-11T20:50:59.000Z | gurba/lib/cmds/player/search.c | DEFCON-MUD/defcon-28-mud-source | b25b5bd15fee6a4acda5119ea864bde4dff62714 | [
"Unlicense"
] | null | null | null | gurba/lib/cmds/player/search.c | DEFCON-MUD/defcon-28-mud-source | b25b5bd15fee6a4acda5119ea864bde4dff62714 | [
"Unlicense"
] | 1 | 2021-12-31T00:55:05.000Z | 2021-12-31T00:55:05.000Z | inherit M_COMMAND;
string *usage(void) {
string *lines;
lines = ({ "Usage: search [-h] [OBJECT]" });
lines += ({ "" });
lines += ({ "Search the specified object." });
lines += ({ "" });
lines += ({ "Options:" });
lines += ({ "\t-h\tHelp, this usage message." });
lines += ({ "Examples:" });
lines += ({ "\tsearch junk" });
lines += ({ "\tsearch" });
lines += get_alsos();
return lines;
}
void setup_alsos() {
add_also("player", "buy");
add_also("player", "extinguish");
add_also("player", "identify");
add_also("player", "light");
add_also("player", "list");
add_also("player", "listen");
add_also("player", "look");
add_also("player", "sell");
add_also("player", "value");
add_also("wiz", "last");
add_also("wiz", "locate");
add_also("wiz", "mudlist");
add_also("wiz", "possess");
add_also("wiz", "rwho");
add_also("wiz", "snoop");
add_also("wiz", "where");
add_also("wiz", "who");
}
static void main(string str) {
object obj;
if (!alsos) {
setup_alsos();
}
if (sscanf(str, "-%s", str)) {
this_player()->more(usage());
return;
}
if (this_environment()->is_dark()) {
if (query_wizard(this_player())) {
write("This room is dark, however, being a wizard allows " +
"you to see in the dark.\n");
} else if (this_player()->query_race_object()->has_darkvision()) {
write("This room is dark, however, your race allows " +
"you to see in the dark.\n");
} else {
write("It is too dark to see.\n");
return;
}
}
if (!str || str == "" || strcmp(str, "room") == 0 || str == "here") {
obj = this_player()->query_environment();
} else {
obj = this_player()->present(str);
if (!obj) {
obj = this_player()->query_environment()->present(str);
if (!obj) {
obj = this_player()->query_environment();
}
}
}
if (obj->is_living()) {
write("That's not acceptable behavior.");
return;
}
if (!call_other(obj, "do_search")) {
this_player()->query_environment()->tell_room(this_player(),
this_player()->query_Name() + " searches " +
obj->query_id() + "\n");
write("You find nothing.\n");
}
}
| 25.152174 | 72 | 0.528954 |
d7ebe2b1b0417bb54d3bb327da66a7646c7786fb | 750 | h | C | src/stack.h | indutny/buoyant-core | ee32482be6ca6d3c3c4a69dfc186a455b293e540 | [
"MIT",
"Unlicense"
] | 1 | 2017-05-31T13:34:24.000Z | 2017-05-31T13:34:24.000Z | src/stack.h | indutny/buoyant-core | ee32482be6ca6d3c3c4a69dfc186a455b293e540 | [
"MIT",
"Unlicense"
] | null | null | null | src/stack.h | indutny/buoyant-core | ee32482be6ca6d3c3c4a69dfc186a455b293e540 | [
"MIT",
"Unlicense"
] | null | null | null | #ifndef SRC_STACK_H_
#define SRC_STACK_H_
#include "assert.h"
typedef struct buoyant__stack_s buoyant__stack_t;
struct buoyant__stack_s {
void** data;
void** start;
void** end;
};
static void buoyant__stack_push(buoyant__stack_t* s, void* data) {
assert(s->data >= s->end);
(*s->data--) = data;
}
static void* buoyant__stack_pop(buoyant__stack_t* s) {
assert(s->data < s->start);
return (*++s->data);
}
static void buoyant__stack_reserve(buoyant__stack_t* s, unsigned int num) {
s->data -= num;
assert(s->end < s->data && s->data <= s->start);
}
static void buoyant__stack_restore(buoyant__stack_t* s, unsigned int num) {
s->data += num;
assert(s->end < s->data && s->data <= s->start);
}
#endif /* SRC_STACK_H_ */
| 19.230769 | 75 | 0.670667 |
7d4814e272a1d258e78159825a8b5e1a08a50434 | 3,584 | h | C | plugin/YmTypes.h | thepsr/qmmp-plugin-ym | 521c9799658d6626b2a923d66512416b79e4c990 | [
"BSD-2-Clause"
] | 6 | 2015-10-05T08:02:36.000Z | 2021-07-19T16:19:20.000Z | plugin/YmTypes.h | thepsr/qmmp-plugin-ym | 521c9799658d6626b2a923d66512416b79e4c990 | [
"BSD-2-Clause"
] | null | null | null | plugin/YmTypes.h | thepsr/qmmp-plugin-ym | 521c9799658d6626b2a923d66512416b79e4c990 | [
"BSD-2-Clause"
] | 1 | 2017-11-16T14:23:09.000Z | 2017-11-16T14:23:09.000Z | /*-----------------------------------------------------------------------------
ST-Sound ( YM files player library )
Define YM types for multi-platform compilation.
Change that file depending of your platform. Please respect the right size
for each type.
-----------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------
* ST-Sound, ATARI-ST Music Emulator
* Copyright (c) 1995-1999 Arnaud Carre ( http://leonard.oxg.free.fr )
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
-----------------------------------------------------------------------------*/
#ifndef __YMTYPES__
#define __YMTYPES__
#ifdef _MSC_VER
typedef __int8 int8_t;
typedef unsigned __int8 uint8_t;
typedef __int16 int16_t;
typedef unsigned __int16 uint16_t;
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#else
#include <stdint.h>
#endif
#define YM_INTEGER_ONLY
//-----------------------------------------------------------
// Platform specific stuff
//-----------------------------------------------------------
#ifdef YM_INTEGER_ONLY
typedef int64_t yms64;
#else
typedef float ymfloat;
#endif
typedef int8_t yms8; // 8 bits signed integer
typedef int16_t yms16; // 16 bits signed integer
typedef int32_t yms32; // 32 bits signed integer
typedef uint8_t ymu8; // 8 bits unsigned integer
typedef uint16_t ymu16; // 16 bits unsigned integer
typedef uint32_t ymu32; // 32 bits unsigned integer
typedef yms32 ymint; // Native "int" for speed purpose. StSound suppose int is signed and at least 32bits. If not, change it to match to yms32
typedef char ymchar; // 8 bits char character (used for null terminated strings)
#ifndef NULL
#define NULL (0L)
#endif
//-----------------------------------------------------------
// Multi-platform
//-----------------------------------------------------------
typedef int ymbool; // boolean ( theorically nothing is assumed for its size in StSound,so keep using int)
typedef yms16 ymsample; // StSound emulator render mono 16bits signed PCM samples
#define YMFALSE (0)
#define YMTRUE (!YMFALSE)
#endif
| 36.948454 | 146 | 0.623884 |
d10c8b6b15b8324588c51fc03455b50370a99aae | 5,328 | h | C | src/compose/compiler_structs.h | lachlanorr/gaen | 325b4604ac8a8a366aa93cca9d8393ccdbc682fa | [
"Zlib"
] | 2 | 2015-05-07T21:03:25.000Z | 2017-10-11T11:17:28.000Z | src/compose/compiler_structs.h | lachlanorr/gaen | 325b4604ac8a8a366aa93cca9d8393ccdbc682fa | [
"Zlib"
] | 4 | 2016-06-25T21:41:50.000Z | 2016-12-26T19:35:19.000Z | src/compose/compiler_structs.h | lachlanorr/gaen | 325b4604ac8a8a366aa93cca9d8393ccdbc682fa | [
"Zlib"
] | 1 | 2016-08-27T18:05:49.000Z | 2016-08-27T18:05:49.000Z | //------------------------------------------------------------------------------
// compiler_structs.h - Compose script compiler structs
//
// Gaen Concurrency Engine - http://gaen.org
// Copyright (c) 2014-2021 Lachlan Orr
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//------------------------------------------------------------------------------
#ifndef GAEN_COMPOSE_COMPILER_STRUCTS_H
#define GAEN_COMPOSE_COMPILER_STRUCTS_H
#include "core/base_defines.h"
#include "core/mem.h"
#include "compose/compiler.h"
#include "compose/comp_mem.h"
using namespace gaen;
static const u32 kMaxCmpId = 128;
struct SymRec;
struct SymDataType;
struct SymStructField
{
const SymDataType * pSymDataType;
const char * name;
u32 flags;
};
struct TypeDesc
{
DataType dataType;
bool isConst;
bool isReference;
// to support maps
bool operator< (const TypeDesc & rhs) const
{
if (dataType == rhs.dataType)
{
if (isConst == rhs.isConst)
{
return isReference < rhs.isReference;
}
else
return isConst < rhs.isConst;
}
else
return dataType < rhs.dataType;
}
};
struct SymDataType
{
TypeDesc typeDesc;
u32 cellCount;
const char * name;
const char * mangledType;
const char * mangledParam;
const char * cppTypeStr;
CompList<SymStructField*> fields;
};
struct RelatedTypes
{
SymDataType * pNormal;
SymDataType * pConst;
SymDataType * pReference;
SymDataType * pConstReference;
};
enum SymRecFlag
{
kSRFL_None = 0x0000,
kSRFL_Member = 0x0001,
kSRFL_NeedsCppParens = 0x0002,
kSRFL_AssetRelated = 0x0004,
kSRFL_BuiltInFunction = 0x0008,
kSRFL_BuiltInConst = 0x0010
};
struct SymRec
{
SymType type;
const SymDataType * pSymDataType;
const char * name;
const char * fullName;
Ast * pAst;
Ast * pInitVal;
SymTab * pSymTab;
SymTab * pSymTabInternal;
SymRec * pStructSymRec;
u32 order;
u32 flags;
};
struct SymTab
{
SymTab * pParent;
Ast * pAst;
ParseData * pParseData;
CompMap<const char*, SymRec*, StrcmpComp> dict;
CompList<SymRec*> orderedSymRecs;
CompList<SymTab*> children;
};
struct AstList
{
CompList<Ast*> nodes;
};
// Block storage info for properties, fields, and message parameters
struct BlockInfo
{
Ast * pAst;
const SymDataType * pSymDataType;
u32 blockIndex;
u32 blockMemoryIndex;
u32 cellIndex;
u32 cellCount;
bool isPayload;
bool isAssigned;
bool isBlockMemoryType;
BlockInfo(Ast * pAst);
};
struct BlockInfos
{
u32 blockCount;
u32 blockMemoryItemCount;
CompVector<BlockInfo> items;
BlockInfos()
: blockCount(0)
, blockMemoryItemCount(0)
{}
const BlockInfo * find(const Ast * pAst) const
{
for (auto it = items.begin(); it != items.end(); ++it)
{
if (it->pAst == pAst)
return &*it;
}
return nullptr;
}
const BlockInfo * find_payload() const
{
for (auto it = items.begin(); it != items.end(); ++it)
{
if (it->isPayload)
return &*it;
}
return nullptr;
}
};
struct Ast
{
ParseData * pParseData;
AstType type;
Ast* pParent;
Scope* pScope;
SymRec* pSymRec;
SymRec* pSymRecRef;
const SymDataType * pSymDataType;
Ast* pLhs;
Ast* pMid;
Ast* pRhs;
int numi;
float numf;
const char * str;
AstList* pChildren;
const char * fullPath;
BlockInfos * pBlockInfos;
};
struct Scope
{
AstList * pAstList;
SymTab * pSymTab;
};
struct Using
{
const char * namespace_;
const ParseData * pParseData;
};
struct ParseData
{
Ast* pRootAst;
void * pScanner;
Scope* pRootScope;
const char * namespace_;
CompList<Scope*> scopeStack;
CompSet<CompString> strings;
// ParseData structs from compilations of usings
CompList<Using> usings;
CompMap<TypeDesc, SymDataType*> basicTypes;
// location info
int line;
int column;
const char * fullPath;
const char * filename;
const char * scriptsRootPath;
size_t scriptsRootPathLen;
MessageHandler messageHandler;
bool hasErrors;
CompList<CompString> * pSystemIncludes;
CompSet<CompString> scriptIncludes;
};
#endif // #ifndef GAEN_COMPOSE_COMPILER_STRUCTS_H
| 21.658537 | 80 | 0.626502 |
28e1ea96cffbfe43fb24361c95bdafeb175ad2b7 | 1,431 | c | C | image/effects.c | soueuls/raytraCer | e025d030fc3a4c6790935819d3d1952204f375ac | [
"MIT"
] | null | null | null | image/effects.c | soueuls/raytraCer | e025d030fc3a4c6790935819d3d1952204f375ac | [
"MIT"
] | null | null | null | image/effects.c | soueuls/raytraCer | e025d030fc3a4c6790935819d3d1952204f375ac | [
"MIT"
] | null | null | null | /*
** effects.c for RT in /home/coudra/Desktop/igraph/RT
**
** Made by Colin Coudray
** Login <coudra@epitech.net>
**
** Started on Tue Apr 1 14:33:10 2014 Colin Coudray
** Last update Tue Apr 15 17:34:42 2014 Colin Coudray
*/
#include "igraph.h"
t_pt celshading(t_lif *obj, long double arc_cos)
{
t_pt tmp;
tmp = load_celshader(arc_cos);
tmp.x = tmp.x * obj->color.x / 255.0;
tmp.y = tmp.y * obj->color.y / 255.0;
tmp.z = tmp.z * obj->color.z / 255.0;
return (tmp);
}
t_pt inverse_color(t_pt color)
{
t_pt tmp;
tmp.x = 0;
tmp.y = 0;
tmp.z = 0;
(void)color;
return (tmp);
}
t_pt color_checker(t_lif *obj, t_pt color, t_pt inter)
{
int a;
int b;
int c;
a = (inter.x + WIDTH / 2.0) / L_CARR;
b = (inter.y + WIDTH / 2.0) / L_CARR;
c = inter.z / L_CARR;
if (c % 2 || obj->type != 1)
{
if (a % 2)
return ((b % 2) ? (color) : (inverse_color(color)));
else
return ((b % 2 == 0) ? (color) : (inverse_color(color)));
}
else
{
if (a % 2)
return ((b % 2 == 0) ? (color) : (inverse_color(color)));
else
return ((b % 2) ? (color) : (inverse_color(color)));
}
}
t_pt effects(t_lif *obj, t_pt inter, long double arc_cos, t_pt color)
{
if (obj->noise)
color = color_noise(obj, color, inter, arc_cos);
if (obj->checker)
color = color_checker(obj, color, inter);
if (CELSHADING)
color = celshading(obj, arc_cos);
return (color);
}
| 20.442857 | 69 | 0.584207 |
75f474494b8dfec1c8b5dbb890b3253c6d886d9b | 1,188 | h | C | src/EndPoint.h | polosskevin/lw_network | 834f995cf21e6efde51182554dea7631794e50f9 | [
"MIT"
] | 5 | 2018-01-23T18:13:08.000Z | 2018-01-28T21:10:38.000Z | src/EndPoint.h | polosskevin/lw_network | 834f995cf21e6efde51182554dea7631794e50f9 | [
"MIT"
] | 4 | 2018-01-10T15:56:30.000Z | 2018-01-28T16:08:57.000Z | src/network/EndPoint.h | polosskevin/rtype | 605707c430c4b5e6ebd2a19f8131ee59a1e990c5 | [
"MIT"
] | null | null | null | //
// Created by Kévin POLOSSAT on 10/01/2018.
//
#ifndef LW_TCP_SERVER_ENDPOINT_H
#define LW_TCP_SERVER_ENDPOINT_H
#include <cstddef>
#include <string>
#include "Protocol.h"
#include "socket_operations.h"
namespace lw_network {
class EndPoint {
public:
EndPoint();
EndPoint(addrinfo const *addrinfo, std::string const & hostName, std::string const & service);
EndPoint(EndPoint const &other);
EndPoint(EndPoint &&other);
EndPoint &operator=(EndPoint const &other);
EndPoint &operator=(EndPoint &&other);
const std::string &HostName() const;
void SetHostName(const std::string &hostName_);
const std::string &Service() const;
void SetService(const std::string &service_);
std::size_t Size() const;
void SetSize(std::size_t s);
sockaddr *Data();
sockaddr const *Data() const;
Protocol const & protocol() const;
void setProtocol(Protocol const & p);
std::string PortStr() const;
std::string HostNameStr() const;
private:
std::size_t size_ = sizeof(sockaddr_storage);
std::string hostName_;
std::string service_;
Protocol protocol_;
sockaddr_storage addr_;
};
}
#endif //LW_TCP_SERVER_ENDPOINT_H
| 25.826087 | 98 | 0.70202 |
92485b8acd54c6f223c2258d90f8b81473b8c0f0 | 1,854 | h | C | YLCleaner/Xcode-RuntimeHeaders/DevToolsInterface/PBXFilenameSmartGroup.h | liyong03/YLCleaner | 7453187a884c8e783bda1af82cbbb51655ec41c6 | [
"MIT"
] | 1 | 2019-02-15T02:16:35.000Z | 2019-02-15T02:16:35.000Z | YLCleaner/Xcode-RuntimeHeaders/DevToolsInterface/PBXFilenameSmartGroup.h | liyong03/YLCleaner | 7453187a884c8e783bda1af82cbbb51655ec41c6 | [
"MIT"
] | null | null | null | YLCleaner/Xcode-RuntimeHeaders/DevToolsInterface/PBXFilenameSmartGroup.h | liyong03/YLCleaner | 7453187a884c8e783bda1af82cbbb51655ec41c6 | [
"MIT"
] | null | null | null | /*
* Generated by class-dump 3.3.4 (64 bit).
*
* class-dump is Copyright (C) 1997-1998, 2000-2001, 2004-2011 by Steve Nygard.
*/
#import <DevToolsInterface/PBXSmartGroup.h>
@class NSMutableArray, NSString, PBXGroup, TSRegularExpression;
@interface PBXFilenameSmartGroup : PBXSmartGroup
{
NSMutableArray *_childFiles;
NSString *_rootGroupID;
PBXGroup *_root;
BOOL _recursive;
NSString *_regexString;
TSRegularExpression *_regex;
BOOL _didRegComp;
char *_fnCString;
id _backgroundTask;
}
+ (id)globalID;
+ (id)flattenArrayOfReferences:(id)arg1;
+ (void)addLeafNodes:(id)arg1 to:(id)arg2 checkUniqueness:(BOOL)arg3 stayFlat:(BOOL)arg4 includeChildrenOfOtherContainers:(BOOL)arg5;
+ (void)addLeafNodes:(id)arg1 to:(id)arg2 checkUniqueness:(BOOL)arg3 stayFlat:(BOOL)arg4;
+ (BOOL)shouldIncludeReference:(id)arg1;
- (id)iconImage;
- (void)_cancelFindChildren:(id)arg1;
- (void)_findChildren:(id)arg1;
- (void)flushCache;
- (id)children;
- (void)setRegexFilter:(id)arg1 simpleFilter:(id)arg2;
- (id)simpleFilter;
- (void)_setSimpleFilter:(id)arg1;
- (void)setSimpleFilter:(id)arg1;
- (id)regexFilter;
- (void)_setRegexFilter:(id)arg1;
- (void)setRegexFilter:(id)arg1;
- (BOOL)recursive;
- (void)setRecursive:(BOOL)arg1;
- (id)gid;
- (id)root;
- (void)_setRootWithGlobalID:(id)arg1;
- (void)setRootWithGlobalID:(id)arg1;
- (void)addLeafNodes:(id)arg1 to:(id)arg2 checkUniqueness:(BOOL)arg3;
- (BOOL)shouldIncludeReference:(id)arg1;
- (void)projectRefereceWillBeRemoved:(id)arg1;
- (void)projectRefereceAdded:(id)arg1;
- (Class)datasourceClass;
- (id)datasource;
- (void)setOwningModule:(id)arg1;
- (BOOL)setName:(id)arg1 syncDisk:(BOOL)arg2;
- (void)setName:(id)arg1;
- (BOOL)allowsEditing;
- (BOOL)isUserSmartGroup;
- (void)setupRoot;
- (void)finalize;
- (void)dealloc;
- (id)initWithBinding:(id)arg1;
@end
| 28.523077 | 133 | 0.731931 |
fad249135a6235e74cba2473861afd243f8c96f6 | 1,463 | h | C | src/mame/machine/namco06.h | Robbbert/messui | 49b756e2140d8831bc81335298ee8c5471045e79 | [
"BSD-3-Clause"
] | 26 | 2015-03-31T06:25:51.000Z | 2021-12-14T09:29:04.000Z | src/mame/machine/namco06.h | Robbbert/messui | 49b756e2140d8831bc81335298ee8c5471045e79 | [
"BSD-3-Clause"
] | null | null | null | src/mame/machine/namco06.h | Robbbert/messui | 49b756e2140d8831bc81335298ee8c5471045e79 | [
"BSD-3-Clause"
] | 10 | 2015-03-27T05:45:51.000Z | 2022-02-04T06:57:36.000Z | // license:BSD-3-Clause
// copyright-holders:Mike Harris, Aaron Giles
#ifndef MAME_MACHINE_NAMCO06_H
#define MAME_MACHINE_NAMCO06_H
#pragma once
/* device get info callback */
class namco_06xx_device : public device_t
{
public:
namco_06xx_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
template <typename T> void set_maincpu(T &&tag) { m_nmicpu.set_tag(std::forward<T>(tag)); }
template <unsigned N> auto chip_select_callback() { return m_chipsel[N].bind(); }
template <unsigned N> auto rw_callback() { return m_rw[N].bind(); }
template <unsigned N> auto read_callback() { return m_read[N].bind(); }
template <unsigned N> auto write_callback() { return m_write[N].bind(); }
uint8_t data_r(offs_t offset);
void data_w(offs_t offset, uint8_t data);
uint8_t ctrl_r();
void ctrl_w(uint8_t data);
protected:
// device-level overrides
virtual void device_start() override;
virtual void device_reset() override;
private:
void set_nmi(int state);
TIMER_CALLBACK_MEMBER( nmi_generate );
// internal state
emu_timer *m_nmi_timer;
uint8_t m_control;
bool m_next_timer_state;
bool m_nmi_stretch;
bool m_rw_stretch;
bool m_rw_change;
required_device<cpu_device> m_nmicpu;
devcb_write_line::array<4> m_chipsel;
devcb_write_line::array<4> m_rw;
devcb_read8::array<4> m_read;
devcb_write8::array<4> m_write;
};
DECLARE_DEVICE_TYPE(NAMCO_06XX, namco_06xx_device)
#endif // MAME_MACHINE_NAMCO06_H
| 25.666667 | 100 | 0.760082 |
4f133d8da2a851128dbee5cdf5816e60275bb133 | 3,304 | c | C | pkgs/apps/vips/src/libvips/histograms_lut/im_mpercent.c | manggoguy/parsec-modified | d14edfb62795805c84a4280d67b50cca175b95af | [
"BSD-3-Clause"
] | 64 | 2015-03-06T00:30:56.000Z | 2022-03-24T13:26:53.000Z | pkgs/apps/vips/src/libvips/histograms_lut/im_mpercent.c | manggoguy/parsec-modified | d14edfb62795805c84a4280d67b50cca175b95af | [
"BSD-3-Clause"
] | 12 | 2020-12-15T08:30:19.000Z | 2022-03-13T03:54:24.000Z | pkgs/apps/vips/src/libvips/histograms_lut/im_mpercent.c | manggoguy/parsec-modified | d14edfb62795805c84a4280d67b50cca175b95af | [
"BSD-3-Clause"
] | 40 | 2015-02-26T15:31:16.000Z | 2022-03-03T23:23:37.000Z | /* find percent of pixels
* Copyright: 1990, N. Dessipris
*
* Author: N. Dessipris
* Written on: 02/08/1990
* Modified on : 29/4/93 K.Martinez for Sys5
* 20/2/95 JC
* - now returns result through parameter
* - ANSIfied a little
* 19/1/07
* - redone with the vips hist operators
* 25/3/10
* - gtkdoc
*/
/*
This file is part of VIPS.
VIPS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/
#include <vips/intl.h>
#include <stdio.h>
#include <string.h>
#include <vips/vips.h>
#ifdef WITH_DMALLOC
#include <dmalloc.h>
#endif /*WITH_DMALLOC*/
/**
* im_mpercent_hist:
* @hist: input histogram image
* @percent: threshold percentage
* @out: output threshold value
*
* Just like im_mpercent(), except it works on an image histogram. Handy if
* you want to run im_mpercent() several times without having to recompute the
* histogram each time.
*
* See also: im_mpercent().
*
* Returns: 0 on success, -1 on error
*/
int
im_mpercent_hist( IMAGE *hist, double percent, int *out )
{
IMAGE *base;
IMAGE *t[6];
double pos;
if( im_check_hist( "im_mpercent", hist ) )
return( -1 );
if( !(base = im_open( "im_mpercent", "p" )) )
return( -1 );
if( im_open_local_array( base, t, 6, "im_mpercent", "p" ) ) {
im_close( base );
return( -1 );
}
if( im_histcum( hist, t[1] ) ||
im_histnorm( t[1], t[2] ) ||
im_lessconst( t[2], t[3], percent * t[2]->Xsize ) ||
im_fliphor( t[3], t[4] ) ||
im_profile( t[4], t[5], 1 ) ||
im_avg( t[5], &pos ) ) {
im_close( base );
return( -1 );
}
im_close( base );
*out = pos;
return( 0 );
}
/**
* im_mpercent:
* @in: input image
* @percent: threshold percentage
* @out: output threshold value
*
* im_mpercent() returns (through the @out parameter) the threshold above
* which there are @percent values of @in. If for example percent=.1, the
* number of pels of the input image with values greater than the returned
* int will correspond to 10% of all pels of the image.
*
* The function works for uchar and ushort images only. It can be used
* to threshold the scaled result of a filtering operation.
*
* See also: im_histgr(), im_profile().
*
* Returns: 0 on success, -1 on error
*/
int
im_mpercent( IMAGE *in, double percent, int *out )
{
IMAGE *t;
if( !(t = im_open( "im_mpercent1", "p" )) )
return( -1 );
if( im_histgr( in, t, -1 ) ||
im_mpercent_hist( t, percent, out ) ) {
im_close( t );
return( -1 );
}
im_close( t );
return( 0 );
}
| 24.116788 | 79 | 0.661017 |
4d7c2d5fd9ee315299b64ef409ee083ebd34312d | 1,515 | c | C | server.c | martinb416/C-Server | 3b1d97b68913d8995eeba1d1a3654e342c572766 | [
"MIT"
] | null | null | null | server.c | martinb416/C-Server | 3b1d97b68913d8995eeba1d1a3654e342c572766 | [
"MIT"
] | null | null | null | server.c | martinb416/C-Server | 3b1d97b68913d8995eeba1d1a3654e342c572766 | [
"MIT"
] | null | null | null | /*
* Binds a socket to the host machine and begins listening.
* Handles the polling/receiving of new connections
*
* Author: Martin Buitrago
* 2018
*/
#include "common.h"
#include "server.h"
#define LISTEN_QUEUE 32
/*
* Set up and tear down the server structs, bind to a port, and start listening
* Returns the socket descriptor bound to the server
*/
int startup(char *port){
struct addrinfo info, *addr;
int sock, result;
memset(&info, 0, sizeof(struct addrinfo));
info.ai_family = AF_UNSPEC; // Might need to force AF_INET for IPV4
info.ai_socktype = SOCK_STREAM;
info.ai_flags = AI_PASSIVE;
info.ai_protocol = IPPROTO_TCP;
if((result = getaddrinfo(LOCALHOST, port, &info, &addr)) != 0) {
fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(result));
exit(result);
}
sock = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
if(sock == -1){
perror("Socket");
exit(errno);
}else{
// Allows port reuse
int iSetOption = 1;
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char*)&iSetOption,
sizeof(iSetOption));
if((result = bind(sock, addr->ai_addr, addr->ai_addrlen)) != 0){
perror("Bind");
close(sock);
exit(errno);
}
// Success!
freeaddrinfo(addr);
}
if((result = listen(sock, LISTEN_QUEUE)) != 0){
perror("Listen");
close(sock);
exit(errno);
}
return sock;
}
// TODO: pointer to prog arg port/ip needs security review
void *run_server(void *port){
int bound_socket = startup((char*)port);
return 0;
} | 21.956522 | 79 | 0.673267 |
9e15f353b7a05d6f4f740b57f751a4622d2c2250 | 114 | h | C | packages/arm32-issuer/rng.h | Dobrokhvalov/shibboleth | e8593b3f9680a467e09031ae90fb9b57d544aec2 | [
"MIT"
] | null | null | null | packages/arm32-issuer/rng.h | Dobrokhvalov/shibboleth | e8593b3f9680a467e09031ae90fb9b57d544aec2 | [
"MIT"
] | 2 | 2022-01-29T05:16:22.000Z | 2022-01-29T05:16:23.000Z | packages/arm32-issuer/rng.h | Dobrokhvalov/shibboleth | e8593b3f9680a467e09031ae90fb9b57d544aec2 | [
"MIT"
] | null | null | null | #ifndef RNG_H
#define RNG_H
#include <stdint.h>
int rng(uint8_t *dest, unsigned size);
void rng_init();
#endif | 11.4 | 38 | 0.719298 |
9e1f3e4efcd97089d70661a5d7ba3d820ca51bed | 35,505 | c | C | src/crt_abstractions.c | sergioprado/azure-c-shared-utility | 9ad82cf0e5d0768506dac2baa192829ae6f34188 | [
"MIT"
] | 1 | 2021-12-26T03:48:42.000Z | 2021-12-26T03:48:42.000Z | src/crt_abstractions.c | sergioprado/azure-c-shared-utility | 9ad82cf0e5d0768506dac2baa192829ae6f34188 | [
"MIT"
] | null | null | null | src/crt_abstractions.c | sergioprado/azure-c-shared-utility | 9ad82cf0e5d0768506dac2baa192829ae6f34188 | [
"MIT"
] | null | null | null | // Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#define __STDC_WANT_LIB_EXT1__ 1
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <limits.h>
#include <float.h>
#include <math.h>
#include <errno.h>
#include "azure_c_shared_utility/gballoc.h"
#include "azure_c_shared_utility/optimize_size.h"
#include "azure_c_shared_utility/crt_abstractions.h"
// VS 2008 does not have INFINITY and all the nice goodies...
#if defined (TIZENRT)
#define DEFINE_INFINITY 1
#else
#if defined _MSC_VER
#if _MSC_VER <= 1500
#define DEFINE_INFINITY 1
#endif
#endif
#endif
#if defined DEFINE_INFINITY
#pragma warning(disable:4756 4056) // warning C4756: overflow in constant arithmetic
// These defines are missing in math.h for WEC2013 SDK
#ifndef _HUGE_ENUF
#define _HUGE_ENUF 1e+300 // _HUGE_ENUF*_HUGE_ENUF must overflow
#endif
#define INFINITY ((float)(_HUGE_ENUF * _HUGE_ENUF))
#define HUGE_VALF ((float)INFINITY)
#define HUGE_VALL ((long double)INFINITY)
#define NAN ((float)(INFINITY * 0.0F))
#endif
#if defined (_MSC_VER) || defined (MINGW_HAS_SECURE_API)
#else
/*Codes_SRS_CRT_ABSTRACTIONS_99_008: [strcat_s shall append the src to dst and terminates the resulting string with a null character.]*/
int strcat_s(char* dst, size_t dstSizeInBytes, const char* src)
{
int result;
/*Codes_SRS_CRT_ABSTRACTIONS_99_004: [If dst is NULL or unterminated, the error code returned shall be EINVAL & dst shall not be modified.]*/
if (dst == NULL)
{
result = EINVAL;
}
/*Codes_SRS_CRT_ABSTRACTIONS_99_005: [If src is NULL, the error code returned shall be EINVAL and dst[0] shall be set to 0.]*/
else if (src == NULL)
{
dst[0] = '\0';
result = EINVAL;
}
else
{
/*Codes_SRS_CRT_ABSTRACTIONS_99_006: [If the dstSizeInBytes is 0 or smaller than the required size for dst & src, the error code returned shall be ERANGE & dst[0] set to 0.]*/
if (dstSizeInBytes == 0)
{
result = ERANGE;
dst[0] = '\0';
}
else
{
size_t dstStrLen = 0;
size_t src_len = strlen(src);
#ifdef __STDC_LIB_EXT1__
dstStrLen = strnlen_s(dst, dstSizeInBytes);
#else
size_t i;
for(i=0; (i < dstSizeInBytes) && (dst[i]!= '\0'); i++)
{
}
dstStrLen = i;
#endif
/*Codes_SRS_CRT_ABSTRACTIONS_99_004: [If dst is NULL or unterminated, the error code returned shall be EINVAL & dst shall not be modified.]*/
if (dstSizeInBytes == dstStrLen) /* this means the dst string is not terminated*/
{
result = EINVAL;
}
// If we are instructed to write too much data to the buffer
// return ERANGE
else if ((src_len + dstStrLen) >= dstSizeInBytes)
{
dst[0] = '\0';
result = ERANGE;
}
else
{
// memcpy should at most copy the result of strlen(src) or there may be
// some issues with copying unwanted memory
size_t bytes_to_cpy = dstSizeInBytes - dstStrLen;
if (bytes_to_cpy > src_len)
{
bytes_to_cpy = src_len;
}
/*Codes_SRS_CRT_ABSTRACTIONS_99_009: [The initial character of src shall overwrite the terminating null character of dst.]*/
if (memcpy(&dst[dstStrLen], src, bytes_to_cpy) == NULL)
/*Codes_SRS_CRT_ABSTRACTIONS_99_006: [If the dstSizeInBytes is 0 or smaller than the required size for dst & src, the error code returned shall be ERANGE & dst[0] set to 0.]*/
{
dst[0] = '\0';
result = ERANGE;
}
else
{
/*Codes_SRS_CRT_ABSTRACTIONS_99_003: [strcat_s shall return Zero upon success.]*/
dst[dstStrLen+bytes_to_cpy] = '\0';
result = 0;
}
}
}
}
return result;
}
/*Codes_SRS_CRT_ABSTRACTIONS_99_025: [strncpy_s shall copy the first N characters of src to dst, where N is the lesser of MaxCount and the length of src.]*/
int strncpy_s(char* dst, size_t dstSizeInBytes, const char* src, size_t maxCount)
{
int result;
int truncationFlag = 0;
/*Codes_SRS_CRT_ABSTRACTIONS_99_020: [If dst is NULL, the error code returned shall be EINVAL and dst shall not be modified.]*/
if (dst == NULL)
{
result = EINVAL;
}
/*Codes_SRS_CRT_ABSTRACTIONS_99_021: [If src is NULL, the error code returned shall be EINVAL and dst[0] shall be set to 0.]*/
else if (src == NULL)
{
dst[0] = '\0';
result = EINVAL;
}
/*Codes_SRS_CRT_ABSTRACTIONS_99_022: [If the dstSizeInBytes is 0, the error code returned shall be EINVAL and dst shall not be modified.]*/
else if (dstSizeInBytes == 0)
{
result = EINVAL;
}
else
{
size_t srcLength = strlen(src);
if (maxCount != _TRUNCATE)
{
/*Codes_SRS_CRT_ABSTRACTIONS_99_041: [If those N characters will fit within dst (whose size is given as dstSizeInBytes) and still leave room for a null terminator, then those characters shall be copied and a terminating null is appended; otherwise, strDest[0] is set to the null character and ERANGE error code returned.]*/
if (srcLength > maxCount)
{
srcLength = maxCount;
}
/*Codes_SRS_CRT_ABSTRACTIONS_99_023: [If dst is not NULL & dstSizeInBytes is smaller than the required size for the src string, the error code returned shall be ERANGE and dst[0] shall be set to 0.]*/
if (srcLength + 1 > dstSizeInBytes)
{
dst[0] = '\0';
result = ERANGE;
}
else
{
(void)memcpy(dst, src, srcLength);
dst[srcLength] = '\0';
/*Codes_SRS_CRT_ABSTRACTIONS_99_018: [strncpy_s shall return Zero upon success]*/
result = 0;
}
}
/*Codes_SRS_CRT_ABSTRACTIONS_99_026: [If MaxCount is _TRUNCATE (defined as -1), then as much of src as will fit into dst shall be copied while still leaving room for the terminating null to be appended.]*/
else
{
if (srcLength + 1 > dstSizeInBytes )
{
srcLength = dstSizeInBytes - 1;
truncationFlag = 1;
}
(void)memcpy(dst, src, srcLength);
dst[srcLength] = '\0';
result = 0;
}
}
/*Codes_SRS_CRT_ABSTRACTIONS_99_019: [If truncation occurred as a result of the copy, the error code returned shall be STRUNCATE.]*/
if (truncationFlag == 1)
{
result = STRUNCATE;
}
return result;
}
/* Codes_SRS_CRT_ABSTRACTIONS_99_016: [strcpy_s shall copy the contents in the address of src, including the terminating null character, to the location that's specified by dst.]*/
int strcpy_s(char* dst, size_t dstSizeInBytes, const char* src)
{
int result;
/* Codes_SRS_CRT_ABSTRACTIONS_99_012: [If dst is NULL, the error code returned shall be EINVAL & dst shall not be modified.]*/
if (dst == NULL)
{
result = EINVAL;
}
/* Codes_SRS_CRT_ABSTRACTIONS_99_013: [If src is NULL, the error code returned shall be EINVAL and dst[0] shall be set to 0.]*/
else if (src == NULL)
{
dst[0] = '\0';
result = EINVAL;
}
/* Codes_SRS_CRT_ABSTRACTIONS_99_014: [If the dstSizeInBytes is 0 or smaller than the required size for the src string, the error code returned shall be ERANGE & dst[0] set to 0.]*/
else if (dstSizeInBytes == 0)
{
dst[0] = '\0';
result = ERANGE;
}
else
{
size_t neededBuffer = strlen(src);
/* Codes_SRS_CRT_ABSTRACTIONS_99_014: [If the dstSizeInBytes is 0 or smaller than the required size for the src string, the error code returned shall be ERANGE & dst[0] set to 0.]*/
if (neededBuffer + 1 > dstSizeInBytes)
{
dst[0] = '\0';
result = ERANGE;
}
else
{
(void)memcpy(dst, src, neededBuffer + 1);
/*Codes_SRS_CRT_ABSTRACTIONS_99_011: [strcpy_s shall return Zero upon success]*/
result = 0;
}
}
return result;
}
/*Codes_SRS_CRT_ABSTRACTIONS_99_029: [The sprintf_s function shall format and store series of characters and values in dst. Each argument (if any) is converted and output according to the corresponding Format Specification in the format variable.]*/
/*Codes_SRS_CRT_ABSTRACTIONS_99_031: [A null character is appended after the last character written.]*/
int sprintf_s(char* dst, size_t dstSizeInBytes, const char* format, ...)
{
int result;
/*Codes_SRS_CRT_ABSTRACTIONS_99_028: [If dst or format is a null pointer, sprintf_s shall return -1 and set errno to EINVAL]*/
if ((dst == NULL) ||
(format == NULL))
{
errno = EINVAL;
result = -1;
}
else
{
/*Codes_SRS_CRT_ABSTRACTIONS_99_033: [sprintf_s shall check the format string for valid formatting characters. If the check fails, the function returns -1.]*/
#if defined _MSC_VER
#error crt_abstractions is not provided for Microsoft Compilers
#else
/*not Microsoft compiler... */
#if defined (__STDC_VERSION__) || (__cplusplus)
#if ( \
((__STDC_VERSION__ == 199901L) || (__STDC_VERSION__ == 201000L) || (__STDC_VERSION__ == 201112L) || (__STDC_VERSION__ == 201710L)) || \
(defined __cplusplus) \
)
/*C99 compiler*/
va_list args;
va_start(args, format);
/*Codes_SRS_CRT_ABSTRACTIONS_99_027: [sprintf_s shall return the number of characters stored in dst upon success. This number shall not include the terminating null character.]*/
result = vsnprintf(dst, dstSizeInBytes, format, args);
va_end(args);
/*C99: Thus, the null-terminated output has been completely written if and only if the returned value is nonnegative and less than n*/
if (result < 0)
{
result = -1;
}
else if ((size_t)result >= dstSizeInBytes)
{
/*Codes_SRS_CRT_ABSTRACTIONS_99_034: [If the dst buffer is too small for the text being printed, then dst is set to an empty string and the function shall return -1.]*/
dst[0] = '\0';
result = -1;
}
else
{
/*do nothing, all is fine*/
}
#else
#error STDC_VERSION defined, but of unknown value; unable to sprinf_s, or provide own implementation
#endif
#else
#error for STDC_VERSION undefined (assumed C89), provide own implementation of sprintf_s
#endif
#endif
}
return result;
}
#endif /* _MSC_VER || MINGW_HAS_SECURE_API */
/*Codes_SRS_CRT_ABSTRACTIONS_21_006: [The strtoull_s must use the letters from a(or A) through z(or Z) to represent the numbers between 10 to 35.]*/
/* returns the integer value that correspond to the character 'c'. If the character is invalid, it returns -1. */
#define DIGIT_VAL(c) (((c>='0') && (c<='9')) ? (c-'0') : ((c>='a') && (c<='z')) ? (c-'a'+10) : ((c>='A') && (c<='Z')) ? (c-'A'+10) : -1)
#define IN_BASE_RANGE(d, b) ((d >= 0) && (d < b))
/*Codes_SRS_CRT_ABSTRACTIONS_21_010: [The white-space must be one of the characters ' ', '\f', '\n', '\r', '\t', '\v'.]*/
#define IS_SPACE(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v')
/*Codes_SRS_CRT_ABSTRACTIONS_21_001: [The strtoull_s must convert the initial portion of the string pointed to by nptr to unsigned long long int representation.]*/
/*Codes_SRS_CRT_ABSTRACTIONS_21_002: [The strtoull_s must resembling an integer represented in some radix determined by the value of base.]*/
/*Codes_SRS_CRT_ABSTRACTIONS_21_003: [The strtoull_s must return the integer that represents the value in the initial part of the string. If any.]*/
unsigned long long strtoull_s(const char* nptr, char** endptr, int base)
{
unsigned long long result = 0ULL;
bool validStr = true;
char* runner = (char*)nptr;
bool isNegative = false;
int digitVal;
/*Codes_SRS_CRT_ABSTRACTIONS_21_005: [The strtoull_s must convert number using base 2 to 36.]*/
/*Codes_SRS_CRT_ABSTRACTIONS_21_012: [If the subject sequence is empty or does not have the expected form, the strtoull_s must not perform any conversion; the value of nptr is stored in the object pointed to by endptr, provided that endptr is not a NULL pointer.]*/
/*Codes_SRS_CRT_ABSTRACTIONS_21_013: [If no conversion could be performed, the strtoull_s returns the value 0L.]*/
/*Codes_SRS_CRT_ABSTRACTIONS_21_035: [If the nptr is NULL, the strtoull_s must **not** perform any conversion and must returns 0L; endptr must receive NULL, provided that endptr is not a NULL pointer.]*/
if (((base >= 2) || (base == 0)) && (base <= 36) && (runner != NULL))
{
/*Codes_SRS_CRT_ABSTRACTIONS_21_011: [The valid sequence starts after the first non-white-space character, followed by an optional positive or negative sign, a number or a letter(depending of the base).]*/
/*Codes_SRS_CRT_ABSTRACTIONS_21_010: [The white-space must be one of the characters ' ', '\f', '\n', '\r', '\t', '\v'.]*/
while (IS_SPACE(*runner))
{
runner++;
}
if ((*runner) == '+')
{
runner++;
}
else if ((*runner) == '-')
{
/*Codes_SRS_CRT_ABSTRACTIONS_21_038: [If the subject sequence starts with a negative sign, the strtoull_s will convert it to the posive representation of the negative value.]*/
isNegative = true;
runner++;
}
if ((*runner) == '0')
{
if ((*(runner+1) == 'x') || (*(runner+1) == 'X'))
{
/*Codes_SRS_CRT_ABSTRACTIONS_21_008: [If the base is 0 and '0x' or '0X' precedes the number, strtoull_s must convert to a hexadecimal (base 16).]*/
/* hexadecimal... */
if ((base == 0) || (base == 16))
{
base = 16;
runner += 2;
}
}
else if((base == 0) || (base == 8))
{
/*Codes_SRS_CRT_ABSTRACTIONS_21_009: [If the base is 0 and '0' precedes the number, strtoull_s must convert to an octal (base 8).]*/
/* octal... */
base = 8;
runner++;
}
}
if(base == 0)
{
/*Codes_SRS_CRT_ABSTRACTIONS_21_007: [If the base is 0 and no special chars precedes the number, strtoull_s must convert to a decimal (base 10).]*/
/* decimal... */
base = 10;
}
digitVal = DIGIT_VAL(*runner);
if (validStr && IN_BASE_RANGE(digitVal, base))
{
errno = 0;
do
{
if (((ULLONG_MAX - digitVal) / base) < result)
{
/*Codes_SRS_CRT_ABSTRACTIONS_21_014: [If the correct value is outside the range, the strtoull_s returns the value ULLONG_MAX, and errno will receive the value ERANGE.]*/
/* overflow... */
result = ULLONG_MAX;
errno = ERANGE;
}
else
{
result = result * base + digitVal;
}
runner++;
digitVal = DIGIT_VAL(*runner);
} while (IN_BASE_RANGE(digitVal, base));
}
else
{
runner = (char*)nptr;
}
}
/*Codes_SRS_CRT_ABSTRACTIONS_21_004: [The strtoull_s must return in endptr a final string of one or more unrecognized characters, including the terminating null character of the input string.]*/
if (endptr != NULL)
{
(*endptr) = (char*)runner;
}
/*Codes_SRS_CRT_ABSTRACTIONS_21_038: [If the subject sequence starts with a negative sign, the strtoull_s will convert it to the posive representation of the negative value.]*/
if (isNegative)
{
result = ULLONG_MAX - result + 1;
}
return result;
}
/*Codes_SRS_CRT_ABSTRACTIONS_21_023: [If the string is 'INF' of 'INFINITY' (ignoring case), the strtof_s must return the INFINITY value for float.]*/
/*Codes_SRS_CRT_ABSTRACTIONS_21_024: [If the string is 'NAN' or 'NAN(...)' (ignoring case), the strtof_s must return 0.0f and points endptr to the first character after the 'NAN' sequence.]*/
/*Codes_SRS_CRT_ABSTRACTIONS_21_033: [If the string is 'INF' of 'INFINITY' (ignoring case), the strtold_s must return the INFINITY value for long double.]*/
/*Codes_SRS_CRT_ABSTRACTIONS_21_034: [If the string is 'NAN' or 'NAN(...)' (ignoring case), the strtold_s must return 0.0 and points endptr to the first character after the 'NAN' sequence.]*/
static int substricmp(const char* nptr, const char* subsrt)
{
int result = 0;
while (((*subsrt) != '\0') && (result == 0))
{
result = TOUPPER(*nptr) - TOUPPER(*subsrt);
nptr++;
subsrt++;
}
return result;
}
/*Codes_SRS_CRT_ABSTRACTIONS_21_023: [If the string is 'INF' of 'INFINITY' (ignoring case), the strtof_s must return the INFINITY value for float.]*/
/*Codes_SRS_CRT_ABSTRACTIONS_21_033: [If the string is 'INF' of 'INFINITY' (ignoring case), the strtold_s must return the INFINITY value for long double.]*/
static bool isInfinity(const char** endptr)
{
bool result = false;
if (substricmp((*endptr), "INF") == 0)
{
(*endptr) += 3;
result = true;
if (substricmp((*endptr), "INITY") == 0)
{
(*endptr) += 5;
}
}
return result;
}
/*Codes_SRS_CRT_ABSTRACTIONS_21_024: [If the string is 'NAN' or 'NAN(...)' (ignoring case), the strtof_s must return 0.0f and points endptr to the first character after the 'NAN' sequence.]*/
/*Codes_SRS_CRT_ABSTRACTIONS_21_034: [If the string is 'NAN' or 'NAN(...)' (ignoring case), the strtold_s must return 0.0 and points endptr to the first character after the 'NAN' sequence.]*/
static bool isNaN(const char** endptr)
{
const char* runner = (*endptr);
bool result = false;
if (substricmp(runner, "NAN") == 0)
{
runner += 3;
result = true;
if ((*runner) == '(')
{
do
{
runner++;
} while (((*runner) != '\0') && ((*runner) != ')'));
if ((*runner) == ')')
runner++;
else
result = false;
}
}
if (result)
(*endptr) = runner;
return result;
}
#define FLOAT_STRING_TYPE_VALUES \
FST_INFINITY, \
FST_NAN, \
FST_NUMBER, \
FST_OVERFLOW, \
FST_ERROR
MU_DEFINE_ENUM(FLOAT_STRING_TYPE, FLOAT_STRING_TYPE_VALUES);
static FLOAT_STRING_TYPE splitFloatString(const char* nptr, char** endptr, int *signal, double *fraction, int *exponential)
{
FLOAT_STRING_TYPE result = FST_ERROR;
unsigned long long ullInteger = 0;
unsigned long long ullFraction = 0;
int integerSize = 0;
int fractionSize = 0;
char* startptr;
(*endptr) = (char*)nptr;
/*Codes_SRS_CRT_ABSTRACTIONS_21_018: [The white-space for strtof_s must be one of the characters ' ', '\f', '\n', '\r', '\t', '\v'.]*/
/*Codes_SRS_CRT_ABSTRACTIONS_21_028: [The white-space for strtold_s must be one of the characters ' ', '\f', '\n', '\r', '\t', '\v'.]*/
while (IS_SPACE(**endptr))
{
(*endptr)++;
}
/*Codes_SRS_CRT_ABSTRACTIONS_21_019: [The valid sequence for strtof_s starts after the first non-white - space character, followed by an optional positive or negative sign, a number, 'INF', or 'NAN' (ignoring case).]*/
/*Codes_SRS_CRT_ABSTRACTIONS_21_029: [The valid sequence for strtold_s starts after the first non-white - space character, followed by an optional positive or negative sign, a number, 'INF', or 'NAN' (ignoring case).]*/
(*signal) = +1;
if ((**endptr) == '+')
{
(*endptr)++;
}
else if ((**endptr) == '-')
{
(*signal) = -1;
(*endptr)++;
}
/*Codes_SRS_CRT_ABSTRACTIONS_21_023: [If the string is 'INF' of 'INFINITY' (ignoring case), the strtof_s must return the INFINITY value for float.]*/
/*Codes_SRS_CRT_ABSTRACTIONS_21_033: [If the string is 'INF' of 'INFINITY' (ignoring case), the strtold_s must return the INFINITY value for long double.]*/
if (isInfinity((const char**)endptr))
{
result = FST_INFINITY;
}
/*Codes_SRS_CRT_ABSTRACTIONS_21_034: [If the string is 'NAN' or 'NAN(...)' (ignoring case), the strtold_s must return 0.0 and points endptr to the first character after the 'NAN' sequence.]*/
/*Codes_SRS_CRT_ABSTRACTIONS_21_024: [If the string is 'NAN' or 'NAN(...)' (ignoring case), the strtof_s must return 0.0f and points endptr to the first character after the 'NAN' sequence.]*/
else if (isNaN((const char**)endptr))
{
result = FST_NAN;
}
else if (IN_BASE_RANGE(DIGIT_VAL(**endptr), 10))
{
result = FST_NUMBER;
startptr = *endptr;
/* integers will go to the fraction and exponential. */
ullInteger = strtoull_s(startptr, endptr, 10);
integerSize = (int)((*endptr) - startptr);
if ((ullInteger == ULLONG_MAX) && (errno != 0))
{
result = FST_OVERFLOW;
}
/* get the real fraction part, if exist. */
if ((**endptr) == '.')
{
startptr = (*endptr) + 1;
ullFraction = strtoull_s(startptr, endptr, 10);
fractionSize = (int)((*endptr) - startptr);
if ((ullFraction == ULLONG_MAX) && (errno != 0))
{
result = FST_OVERFLOW;
}
}
if (((**endptr) == 'e') || ((**endptr) == 'E'))
{
startptr = (*endptr) + 1;
(*exponential) = (int)strtol(startptr, endptr, 10);
if (((*exponential) < (DBL_MAX_10_EXP * (-1))) || ((*exponential) > DBL_MAX_10_EXP))
{
result = FST_OVERFLOW;
}
}
else
{
(*exponential) = 0;
}
if (result == FST_NUMBER)
{
/* Add ullInteger to ullFraction. */
ullFraction += (ullInteger * (unsigned long long)(pow(10, (double)fractionSize)));
(*fraction) = ((double)ullFraction / (pow(10.0f, ((double)fractionSize + (double)integerSize - 1.00))));
/* Unify rest of integerSize and fractionSize in the exponential. */
(*exponential) += integerSize - 1;
}
}
return result;
}
/*Codes_SRS_CRT_ABSTRACTIONS_21_015: [The strtof_s must convert the initial portion of the string pointed to by nptr to float representation.]*/
/*Codes_SRS_CRT_ABSTRACTIONS_21_016: [The strtof_s must return the float that represents the value in the initial part of the string. If any.]*/
float strtof_s(const char* nptr, char** endptr)
{
int signal = 1;
double fraction;
int exponential;
char* runner = (char*)nptr;
double val;
/*Codes_SRS_CRT_ABSTRACTIONS_21_021: [If no conversion could be performed, the strtof_s returns the value 0.0.]*/
float result = 0.0;
/*Codes_SRS_CRT_ABSTRACTIONS_21_036: [**If the nptr is NULL, the strtof_s must not perform any conversion and must returns 0.0f; endptr must receive NULL, provided that endptr is not a NULL pointer.]*/
if (nptr != NULL)
{
switch (splitFloatString(nptr, &runner, &signal, &fraction, &exponential))
{
case FST_INFINITY:
/*Codes_SRS_CRT_ABSTRACTIONS_21_023: [If the string is 'INF' of 'INFINITY' (ignoring case), the strtof_s must return the INFINITY value for float.]*/
result = INFINITY * (signal);
errno = 0;
break;
case FST_NAN:
/*Codes_SRS_CRT_ABSTRACTIONS_21_024: [If the string is 'NAN' or 'NAN(...)' (ignoring case), the strtof_s must return 0.0f and points endptr to the first character after the 'NAN' sequence.]*/
result = NAN;
break;
case FST_NUMBER:
val = fraction * pow(10.0, (double)exponential) * (double)signal;
if ((val >= (FLT_MAX * (-1.0f))) && (val <= FLT_MAX))
{
/*Codes_SRS_CRT_ABSTRACTIONS_21_016: [The strtof_s must return the float that represents the value in the initial part of the string. If any.]*/
result = (float)val;
}
else
{
/*Codes_SRS_CRT_ABSTRACTIONS_21_022: [If the correct value is outside the range, the strtof_s returns the value plus or minus HUGE_VALF, and errno will receive the value ERANGE.]*/
result = HUGE_VALF * (signal);
errno = ERANGE;
}
break;
case FST_OVERFLOW:
/*Codes_SRS_CRT_ABSTRACTIONS_21_022: [If the correct value is outside the range, the strtof_s returns the value plus or minus HUGE_VALF, and errno will receive the value ERANGE.]*/
result = HUGE_VALF * (signal);
errno = ERANGE;
break;
default:
/*Codes_SRS_CRT_ABSTRACTIONS_21_020: [If the subject sequence is empty or does not have the expected form, the strtof_s must not perform any conversion and must returns 0.0f; the value of nptr is stored in the object pointed to by endptr, provided that endptr is not a NULL pointer.]*/
runner = (char*)nptr;
break;
}
}
/*Codes_SRS_CRT_ABSTRACTIONS_21_017: [The strtof_s must return in endptr a final string of one or more unrecognized characters, including the terminating null character of the input string.]*/
if (endptr != NULL)
{
(*endptr) = runner;
}
return result;
}
/*Codes_SRS_CRT_ABSTRACTIONS_21_025: [The strtold_s must convert the initial portion of the string pointed to by nptr to long double representation.]*/
/*Codes_SRS_CRT_ABSTRACTIONS_21_026: [The strtold_s must return the long double that represents the value in the initial part of the string. If any.]*/
long double strtold_s(const char* nptr, char** endptr)
{
int signal = 1;
double fraction;
int exponential;
char* runner = (char*)nptr;
/*Codes_SRS_CRT_ABSTRACTIONS_21_031: [If no conversion could be performed, the strtold_s returns the value 0.0.]*/
long double result = 0.0;
/*Codes_SRS_CRT_ABSTRACTIONS_21_037: [If the nptr is NULL, the strtold_s must not perform any conversion and must returns 0.0; endptr must receive NULL, provided that endptr is not a NULL pointer.]*/
if (nptr != NULL)
{
switch (splitFloatString(nptr, &runner, &signal, &fraction, &exponential))
{
case FST_INFINITY:
/*Codes_SRS_CRT_ABSTRACTIONS_21_033: [If the string is 'INF' of 'INFINITY' (ignoring case), the strtold_s must return the INFINITY value for long double.]*/
result = (long double)INFINITY * (long double)(signal);
errno = 0;
break;
case FST_NAN:
/*Codes_SRS_CRT_ABSTRACTIONS_21_034: [If the string is 'NAN' or 'NAN(...)' (ignoring case), the strtold_s must return 0.0 and points endptr to the first character after the 'NAN' sequence.]*/
result = (long double)NAN;
break;
case FST_NUMBER:
if ((exponential != DBL_MAX_10_EXP || (fraction <= 1.7976931348623158)) &&
(exponential != (DBL_MAX_10_EXP * (-1)) || (fraction <= 2.2250738585072014)))
{
/*Codes_SRS_CRT_ABSTRACTIONS_21_026: [The strtold_s must return the long double that represents the value in the initial part of the string. If any.]*/
result = fraction * pow(10.0, (double)exponential) * (double)signal;
}
else
{
/*Codes_SRS_CRT_ABSTRACTIONS_21_032: [If the correct value is outside the range, the strtold_s returns the value plus or minus HUGE_VALL, and errno will receive the value ERANGE.]*/
result = (long double)HUGE_VALF * (long double)(signal);
errno = ERANGE;
}
break;
case FST_OVERFLOW:
/*Codes_SRS_CRT_ABSTRACTIONS_21_032: [If the correct value is outside the range, the strtold_s returns the value plus or minus HUGE_VALL, and errno will receive the value ERANGE.]*/
result = (long double)HUGE_VALF * (long double)(signal);
errno = ERANGE;
break;
default:
/*Codes_SRS_CRT_ABSTRACTIONS_21_030: [If the subject sequence is empty or does not have the expected form, the strtold_s must not perform any conversion and must returns 0.0; the value of nptr is stored in the object pointed to by endptr, provided that endptr is not a NULL pointer.]*/
runner = (char*)nptr;
break;
}
}
/*Codes_SRS_CRT_ABSTRACTIONS_21_027: [The strtold_s must return in endptr a final string of one or more unrecognized characters, including the terminating null character of the input string.]*/
if (endptr != NULL)
{
(*endptr) = runner;
}
return result;
}
/*Codes_SRS_CRT_ABSTRACTIONS_99_038: [mallocAndstrcpy_s shall allocate memory for destination buffer to fit the string in the source parameter.]*/
int mallocAndStrcpy_s(char** destination, const char* source)
{
int result;
int copied_result;
/*Codes_SRS_CRT_ABSTRACTIONS_99_036: [destination parameter or source parameter is NULL, the error code returned shall be EINVAL and destination shall not be modified.]*/
if ((destination == NULL) || (source == NULL))
{
/*If strDestination or strSource is a NULL pointer[...]these functions return EINVAL */
result = EINVAL;
}
else
{
size_t l = strlen(source);
char* temp = (char*)malloc(l + 1);
/*Codes_SRS_CRT_ABSTRACTIONS_99_037: [Upon failure to allocate memory for the destination, the function will return ENOMEM.]*/
if (temp == NULL)
{
result = ENOMEM;
}
else
{
*destination = temp;
/*Codes_SRS_CRT_ABSTRACTIONS_99_039: [mallocAndstrcpy_s shall copy the contents in the address source, including the terminating null character into location specified by the destination pointer after the memory allocation.]*/
copied_result = strcpy_s(*destination, l + 1, source);
if (copied_result < 0) /*strcpy_s error*/
{
free(*destination);
*destination = NULL;
result = copied_result;
}
else
{
/*Codes_SRS_CRT_ABSTRACTIONS_99_035: [mallocAndstrcpy_s shall return Zero upon success]*/
result = 0;
}
}
}
return result;
}
/*takes "value" and transforms it into a decimal string*/
/*10 => "10"*/
/*return 0 when everything went ok*/
/*Codes_SRS_CRT_ABSTRACTIONS_02_001: [unsignedIntToString shall convert the parameter value to its decimal representation as a string in the buffer indicated by parameter destination having the size indicated by parameter destinationSize.] */
int unsignedIntToString(char* destination, size_t destinationSize, unsigned int value)
{
int result;
size_t pos;
/*the below loop gets the number in reverse order*/
/*Codes_SRS_CRT_ABSTRACTIONS_02_003: [If destination is NULL then unsignedIntToString shall fail.] */
/*Codes_SRS_CRT_ABSTRACTIONS_02_002: [If the conversion fails for any reason (for example, insufficient buffer space), a non-zero return value shall be supplied and unsignedIntToString shall fail.] */
if (
(destination == NULL) ||
(destinationSize < 2) /*because the smallest number is '0\0' which requires 2 characters*/
)
{
result = MU_FAILURE;
}
else
{
pos = 0;
do
{
destination[pos++] = '0' + (value % 10);
value /= 10;
} while ((value > 0) && (pos < (destinationSize-1)));
if (value == 0)
{
size_t w;
destination[pos] = '\0';
/*all converted and they fit*/
for (w = 0; w <= (pos-1) >> 1; w++)
{
char temp;
temp = destination[w];
destination[w] = destination[pos - 1 - w];
destination[pos -1 - w] = temp;
}
/*Codes_SRS_CRT_ABSTRACTIONS_02_004: [If the conversion has been successfull then unsignedIntToString shall return 0.] */
result = 0;
}
else
{
/*Codes_SRS_CRT_ABSTRACTIONS_02_002: [If the conversion fails for any reason (for example, insufficient buffer space), a non-zero return value shall be supplied and unsignedIntToString shall fail.] */
result = MU_FAILURE;
}
}
return result;
}
/*takes "value" and transforms it into a decimal string*/
/*10 => "10"*/
/*return 0 when everything went ok*/
/*Codes_SRS_CRT_ABSTRACTIONS_02_001: [unsignedIntToString shall convert the parameter value to its decimal representation as a string in the buffer indicated by parameter destination having the size indicated by parameter destinationSize.] */
int size_tToString(char* destination, size_t destinationSize, size_t value)
{
int result;
size_t pos;
/*the below loop gets the number in reverse order*/
/*Codes_SRS_CRT_ABSTRACTIONS_02_003: [If destination is NULL then unsignedIntToString shall fail.] */
/*Codes_SRS_CRT_ABSTRACTIONS_02_002: [If the conversion fails for any reason (for example, insufficient buffer space), a non-zero return value shall be supplied and unsignedIntToString shall fail.] */
if (
(destination == NULL) ||
(destinationSize < 2) /*because the smallest number is '0\0' which requires 2 characters*/
)
{
result = MU_FAILURE;
}
else
{
pos = 0;
do
{
destination[pos++] = '0' + (value % 10);
value /= 10;
} while ((value > 0) && (pos < (destinationSize - 1)));
if (value == 0)
{
size_t w;
destination[pos] = '\0';
/*all converted and they fit*/
for (w = 0; w <= (pos - 1) >> 1; w++)
{
char temp;
temp = destination[w];
destination[w] = destination[pos - 1 - w];
destination[pos - 1 - w] = temp;
}
/*Codes_SRS_CRT_ABSTRACTIONS_02_004: [If the conversion has been successfull then unsignedIntToString shall return 0.] */
result = 0;
}
else
{
/*Codes_SRS_CRT_ABSTRACTIONS_02_002: [If the conversion fails for any reason (for example, insufficient buffer space), a non-zero return value shall be supplied and unsignedIntToString shall fail.] */
result = MU_FAILURE;
}
}
return result;
}
| 42.368735 | 335 | 0.610449 |
b11676e4c37ab458165d392573177fad7b7fb46f | 5,268 | c | C | tools-src/gnu/glibc/sysdeps/unix/sysv/aix/tcsetattr.c | enfoTek/tomato.linksys.e2000.nvram-mod | 2ce3a5217def49d6df7348522e2bfda702b56029 | [
"FSFAP"
] | 80 | 2015-01-02T10:14:04.000Z | 2021-06-07T06:29:49.000Z | tools-src/gnu/glibc/sysdeps/unix/sysv/aix/tcsetattr.c | unforgiven512/tomato | 96f09fab4929c6ddde5c9113f1b2476ad37133c4 | [
"FSFAP"
] | 9 | 2015-05-14T11:03:12.000Z | 2018-01-04T07:12:58.000Z | tools-src/gnu/glibc/sysdeps/unix/sysv/aix/tcsetattr.c | unforgiven512/tomato | 96f09fab4929c6ddde5c9113f1b2476ad37133c4 | [
"FSFAP"
] | 69 | 2015-01-02T10:45:56.000Z | 2021-09-06T07:52:13.000Z | /* Copyright (C) 1992, 1995, 1996, 1997, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stddef.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <sysv_termio.h>
const speed_t __unix_speeds[] =
{
0,
50,
75,
110,
134,
150,
200,
300,
600,
1200,
1800,
2400,
4800,
9600,
19200,
38400,
};
/* Set the state of FD to *TERMIOS_P. */
int
tcsetattr (fd, optional_actions, termios_p)
int fd;
int optional_actions;
const struct termios *termios_p;
{
struct __sysv_termio buf;
int ioctl_function;
if (termios_p == NULL)
{
__set_errno (EINVAL);
return -1;
}
switch (optional_actions)
{
case TCSANOW:
ioctl_function = _TCSETA;
break;
case TCSADRAIN:
ioctl_function = _TCSETAW;
break;
case TCSAFLUSH:
ioctl_function = _TCSETAF;
break;
default:
__set_errno (EINVAL);
return -1;
}
if ((termios_p->c_cflag & 0x000f0000) >> 16 != (termios_p->c_cflag & 0xf))
{
__set_errno (EINVAL);
return -1;
}
buf.c_iflag = 0;
if (termios_p->c_iflag & IGNBRK)
buf.c_iflag |= _SYSV_IGNBRK;
if (termios_p->c_iflag & BRKINT)
buf.c_iflag |= _SYSV_BRKINT;
if (termios_p->c_iflag & IGNPAR)
buf.c_iflag |= _SYSV_IGNPAR;
if (termios_p->c_iflag & PARMRK)
buf.c_iflag |= _SYSV_PARMRK;
if (termios_p->c_iflag & INPCK)
buf.c_iflag |= _SYSV_INPCK;
if (termios_p->c_iflag & ISTRIP)
buf.c_iflag |= _SYSV_ISTRIP;
if (termios_p->c_iflag & INLCR)
buf.c_iflag |= _SYSV_INLCR;
if (termios_p->c_iflag & IGNCR)
buf.c_iflag |= _SYSV_IGNCR;
if (termios_p->c_iflag & ICRNL)
buf.c_iflag |= _SYSV_ICRNL;
if (termios_p->c_iflag & IXON)
buf.c_iflag |= _SYSV_IXON;
if (termios_p->c_iflag & IXOFF)
buf.c_iflag |= _SYSV_IXOFF;
if (termios_p->c_iflag & IXANY)
buf.c_iflag |= _SYSV_IXANY;
if (termios_p->c_iflag & IMAXBEL)
buf.c_iflag |= _SYSV_IMAXBEL;
buf.c_oflag = 0;
if (termios_p->c_oflag & OPOST)
buf.c_oflag |= _SYSV_OPOST;
if (termios_p->c_oflag & ONLCR)
buf.c_oflag |= _SYSV_ONLCR;
/* So far, buf.c_cflag contains the speed in CBAUD. */
if (termios_p->c_cflag & CSTOPB)
buf.c_cflag |= _SYSV_CSTOPB;
if (termios_p->c_cflag & CREAD)
buf.c_cflag |= _SYSV_CREAD;
if (termios_p->c_cflag & PARENB)
buf.c_cflag |= _SYSV_PARENB;
if (termios_p->c_cflag & PARODD)
buf.c_cflag |= _SYSV_PARODD;
if (termios_p->c_cflag & HUPCL)
buf.c_cflag |= _SYSV_HUPCL;
if (termios_p->c_cflag & CLOCAL)
buf.c_cflag |= _SYSV_CLOCAL;
switch (termios_p->c_cflag & CSIZE)
{
case CS5:
buf.c_cflag |= _SYSV_CS5;
break;
case CS6:
buf.c_cflag |= _SYSV_CS6;
break;
case CS7:
buf.c_cflag |= _SYSV_CS7;
break;
case CS8:
buf.c_cflag |= _SYSV_CS8;
break;
}
buf.c_lflag = 0;
if (termios_p->c_lflag & ISIG)
buf.c_lflag |= _SYSV_ISIG;
if (termios_p->c_lflag & ICANON)
buf.c_lflag |= _SYSV_ICANON;
if (termios_p->c_lflag & ECHO)
buf.c_lflag |= _SYSV_ECHO;
if (termios_p->c_lflag & ECHOE)
buf.c_lflag |= _SYSV_ECHOE;
if (termios_p->c_lflag & ECHOK)
buf.c_lflag |= _SYSV_ECHOK;
if (termios_p->c_lflag & ECHONL)
buf.c_lflag |= _SYSV_ECHONL;
if (termios_p->c_lflag & NOFLSH)
buf.c_lflag |= _SYSV_NOFLSH;
if (termios_p->c_lflag & TOSTOP)
buf.c_lflag |= _SYSV_TOSTOP;
if (termios_p->c_lflag & ECHOCTL)
buf.c_lflag |= _SYSV_ECHOCTL;
if (termios_p->c_lflag & ECHOPRT)
buf.c_lflag |= _SYSV_ECHOPRT;
if (termios_p->c_lflag & ECHOKE)
buf.c_lflag |= _SYSV_ECHOKE;
if (termios_p->c_lflag & FLUSHO)
buf.c_lflag |= _SYSV_FLUSHO;
if (termios_p->c_lflag & PENDIN)
buf.c_lflag |= _SYSV_PENDIN;
if (termios_p->c_lflag & IEXTEN)
buf.c_lflag |= _SYSV_IEXTEN;
buf.c_cc[_SYSV_VINTR] = termios_p->c_cc[VINTR];
buf.c_cc[_SYSV_VQUIT] = termios_p->c_cc[VQUIT];
buf.c_cc[_SYSV_VERASE] = termios_p->c_cc[VERASE];
buf.c_cc[_SYSV_VKILL] = termios_p->c_cc[VKILL];
if (buf.c_lflag & _SYSV_ICANON)
{
buf.c_cc[_SYSV_VEOF] = termios_p->c_cc[VEOF];
buf.c_cc[_SYSV_VEOL] = termios_p->c_cc[VEOL];
}
else
{
buf.c_cc[_SYSV_VMIN] = termios_p->c_cc[VMIN];
buf.c_cc[_SYSV_VTIME] = termios_p->c_cc[VTIME];
}
buf.c_cc[_SYSV_VEOL2] = termios_p->c_cc[VEOL2];
if (__ioctl (fd, ioctl_function, &buf) < 0)
return -1;
return 0;
}
| 26.606061 | 76 | 0.65224 |
7f590737d650953758abbb49b1ef651906a53a5e | 1,052 | c | C | uart.c | 0x664b44c3/TallyRelayBox | 9916ebcb76059417b68008495c202987cb8a38ca | [
"MIT"
] | null | null | null | uart.c | 0x664b44c3/TallyRelayBox | 9916ebcb76059417b68008495c202987cb8a38ca | [
"MIT"
] | null | null | null | uart.c | 0x664b44c3/TallyRelayBox | 9916ebcb76059417b68008495c202987cb8a38ca | [
"MIT"
] | null | null | null | #include <avr/io.h>
#include <avr/pgmspace.h>
void uart_putc(unsigned char data)
{
/* Wait for empty transmit buffer */
while ( !( UCSR0A & (1<<UDRE0)) );
/* Put data into buffer, sends the data */
UDR0 = data;
}/* uart_putc */
/*************************************************************************
Function: uart_puts()
Purpose: transmit string to UART
Input: string to be transmitted
Returns: none
**************************************************************************/
void uart_puts(const char *s )
{
while (*s)
uart_putc(*s++);
}/* uart_puts */
/*************************************************************************
Function: uart_puts_p()
Purpose: transmit string from program memory to UART
Input: program memory string to be transmitted
Returns: none
**************************************************************************/
void uart_puts_p(const char *progmem_s )
{
register char c;
while ( (c = pgm_read_byte(progmem_s++)) )
uart_putc(c);
}/* uart_puts_p */
| 25.658537 | 76 | 0.462928 |
36b057ab6e6e40947e2d0dc3febae6da97c6a8a4 | 1,257 | c | C | cracking-the-coding-interview/ch1-arrays-and-strings/1.2-reverse-string.c | joeghodsi/interview-questions | 3e4eb76891245ce978cb9171e87d60e3b292b0a8 | [
"Unlicense"
] | 1 | 2018-06-11T18:18:39.000Z | 2018-06-11T18:18:39.000Z | cracking-the-coding-interview/ch1-arrays-and-strings/1.2-reverse-string.c | joeghodsi/interview-questions | 3e4eb76891245ce978cb9171e87d60e3b292b0a8 | [
"Unlicense"
] | null | null | null | cracking-the-coding-interview/ch1-arrays-and-strings/1.2-reverse-string.c | joeghodsi/interview-questions | 3e4eb76891245ce978cb9171e87d60e3b292b0a8 | [
"Unlicense"
] | null | null | null | /*
Problem: In C or C++ write a function that reverses a null-terminated string
Solution: inc from start, dec from end. swap at each step
- linear time, constant space
total time: 46
mistakes:
- didn't deal with NULL edge case
struggles:
- char*:
- was passing "..." to function rather than setting to string and passing it
- bus error because I was doing char* str = "..." instead of char str[] = "..."
- printf: had to look up and slow to work with
- NULL: had issues with NUL, NULL, '\0', forgot string literals had implicit '\0'
- forgot about strlen so manually detemrined length of string
*/
#include <stdio.h>
#include <string.h>
void reverse(char* string) {
if (!string) return;
int i = 0, j = strlen(string) - 1;
char temp;
for(; i <= j; i++, j--) {
temp = string[i];
string[i] = string[j];
string[j] = temp;
}
}
int main() {
char* string;
strcpy(string, "abc");
reverse(string);
printf("%s\n", string);
strcpy(string, "abcd");
reverse(string);
printf("%s\n", string);
strcpy(string, "a");
reverse(string);
printf("%s\n", string);
string = NULL;
reverse(string);
printf("%s\n", string);
return 0;
}
| 23.716981 | 87 | 0.595068 |
cffa9e9f876873ae1700be1bead3edd151b5fe89 | 45,667 | h | C | runtime/vm/compiler/assembler/assembler_x64.h | n0npax/sdk | b683098fde9611cea472cb081da2cea7ba15bc8b | [
"BSD-3-Clause"
] | 1 | 2021-09-26T13:34:27.000Z | 2021-09-26T13:34:27.000Z | runtime/vm/compiler/assembler/assembler_x64.h | Hector096/sdk | e7644d9a4c6f400680206f6d03135f24d0480052 | [
"BSD-3-Clause"
] | null | null | null | runtime/vm/compiler/assembler/assembler_x64.h | Hector096/sdk | e7644d9a4c6f400680206f6d03135f24d0480052 | [
"BSD-3-Clause"
] | null | null | null | // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#ifndef RUNTIME_VM_COMPILER_ASSEMBLER_ASSEMBLER_X64_H_
#define RUNTIME_VM_COMPILER_ASSEMBLER_ASSEMBLER_X64_H_
#if defined(DART_PRECOMPILED_RUNTIME)
#error "AOT runtime should not use compiler sources (including header files)"
#endif // defined(DART_PRECOMPILED_RUNTIME)
#ifndef RUNTIME_VM_COMPILER_ASSEMBLER_ASSEMBLER_H_
#error Do not include assembler_x64.h directly; use assembler.h instead.
#endif
#include <functional>
#include "platform/assert.h"
#include "platform/utils.h"
#include "vm/compiler/assembler/assembler_base.h"
#include "vm/constants.h"
#include "vm/constants_x86.h"
#include "vm/hash_map.h"
#include "vm/pointer_tagging.h"
namespace dart {
// Forward declarations.
class FlowGraphCompiler;
class RegisterSet;
namespace compiler {
class Immediate : public ValueObject {
public:
explicit Immediate(int64_t value) : value_(value) {}
Immediate(const Immediate& other) : ValueObject(), value_(other.value_) {}
int64_t value() const { return value_; }
bool is_int8() const { return Utils::IsInt(8, value_); }
bool is_uint8() const { return Utils::IsUint(8, value_); }
bool is_int16() const { return Utils::IsInt(16, value_); }
bool is_uint16() const { return Utils::IsUint(16, value_); }
bool is_int32() const { return Utils::IsInt(32, value_); }
bool is_uint32() const { return Utils::IsUint(32, value_); }
private:
const int64_t value_;
// TODO(5411081): Add DISALLOW_COPY_AND_ASSIGN(Immediate) once the mac
// build issue is resolved.
// And remove the unnecessary copy constructor.
};
class Operand : public ValueObject {
public:
uint8_t rex() const { return rex_; }
uint8_t mod() const { return (encoding_at(0) >> 6) & 3; }
Register rm() const {
int rm_rex = (rex_ & REX_B) << 3;
return static_cast<Register>(rm_rex + (encoding_at(0) & 7));
}
ScaleFactor scale() const {
return static_cast<ScaleFactor>((encoding_at(1) >> 6) & 3);
}
Register index() const {
int index_rex = (rex_ & REX_X) << 2;
return static_cast<Register>(index_rex + ((encoding_at(1) >> 3) & 7));
}
Register base() const {
int base_rex = (rex_ & REX_B) << 3;
return static_cast<Register>(base_rex + (encoding_at(1) & 7));
}
int8_t disp8() const {
ASSERT(length_ >= 2);
return static_cast<int8_t>(encoding_[length_ - 1]);
}
int32_t disp32() const {
ASSERT(length_ >= 5);
return bit_copy<int32_t>(encoding_[length_ - 4]);
}
Operand(const Operand& other)
: ValueObject(), length_(other.length_), rex_(other.rex_) {
memmove(&encoding_[0], &other.encoding_[0], other.length_);
}
Operand& operator=(const Operand& other) {
length_ = other.length_;
rex_ = other.rex_;
memmove(&encoding_[0], &other.encoding_[0], other.length_);
return *this;
}
bool Equals(const Operand& other) const {
if (length_ != other.length_) return false;
if (rex_ != other.rex_) return false;
for (uint8_t i = 0; i < length_; i++) {
if (encoding_[i] != other.encoding_[i]) return false;
}
return true;
}
protected:
Operand() : length_(0), rex_(REX_NONE) {} // Needed by subclass Address.
void SetModRM(int mod, Register rm) {
ASSERT((mod & ~3) == 0);
if ((rm > 7) && !((rm == R12) && (mod != 3))) {
rex_ |= REX_B;
}
encoding_[0] = (mod << 6) | (rm & 7);
length_ = 1;
}
void SetSIB(ScaleFactor scale, Register index, Register base) {
ASSERT(length_ == 1);
ASSERT((scale & ~3) == 0);
if (base > 7) {
ASSERT((rex_ & REX_B) == 0); // Must not have REX.B already set.
rex_ |= REX_B;
}
if (index > 7) rex_ |= REX_X;
encoding_[1] = (scale << 6) | ((index & 7) << 3) | (base & 7);
length_ = 2;
}
void SetDisp8(int8_t disp) {
ASSERT(length_ == 1 || length_ == 2);
encoding_[length_++] = static_cast<uint8_t>(disp);
}
void SetDisp32(int32_t disp) {
ASSERT(length_ == 1 || length_ == 2);
memmove(&encoding_[length_], &disp, sizeof(disp));
length_ += sizeof(disp);
}
private:
uint8_t length_;
uint8_t rex_;
uint8_t encoding_[6];
explicit Operand(Register reg) : rex_(REX_NONE) { SetModRM(3, reg); }
// Get the operand encoding byte at the given index.
uint8_t encoding_at(intptr_t index) const {
ASSERT(index >= 0 && index < length_);
return encoding_[index];
}
// Returns whether or not this operand is really the given register in
// disguise. Used from the assembler to generate better encodings.
bool IsRegister(Register reg) const {
return ((reg > 7 ? 1 : 0) == (rex_ & REX_B)) // REX.B match.
&& ((encoding_at(0) & 0xF8) == 0xC0) // Addressing mode is register.
&& ((encoding_at(0) & 0x07) == reg); // Register codes match.
}
friend class Assembler;
};
class Address : public Operand {
public:
Address(Register base, int32_t disp) {
if ((disp == 0) && ((base & 7) != RBP)) {
SetModRM(0, base);
if ((base & 7) == RSP) {
SetSIB(TIMES_1, RSP, base);
}
} else if (Utils::IsInt(8, disp)) {
SetModRM(1, base);
if ((base & 7) == RSP) {
SetSIB(TIMES_1, RSP, base);
}
SetDisp8(disp);
} else {
SetModRM(2, base);
if ((base & 7) == RSP) {
SetSIB(TIMES_1, RSP, base);
}
SetDisp32(disp);
}
}
// This addressing mode does not exist.
Address(Register base, Register r);
Address(Register index, ScaleFactor scale, int32_t disp) {
ASSERT(index != RSP); // Illegal addressing mode.
ASSERT(scale != TIMES_16); // Unsupported scale factor.
SetModRM(0, RSP);
SetSIB(scale, index, RBP);
SetDisp32(disp);
}
// This addressing mode does not exist.
Address(Register index, ScaleFactor scale, Register r);
Address(Register base, Register index, ScaleFactor scale, int32_t disp) {
ASSERT(index != RSP); // Illegal addressing mode.
ASSERT(scale != TIMES_16); // Unsupported scale factor.
if ((disp == 0) && ((base & 7) != RBP)) {
SetModRM(0, RSP);
SetSIB(scale, index, base);
} else if (Utils::IsInt(8, disp)) {
SetModRM(1, RSP);
SetSIB(scale, index, base);
SetDisp8(disp);
} else {
SetModRM(2, RSP);
SetSIB(scale, index, base);
SetDisp32(disp);
}
}
// This addressing mode does not exist.
Address(Register base, Register index, ScaleFactor scale, Register r);
Address(const Address& other) : Operand(other) {}
Address& operator=(const Address& other) {
Operand::operator=(other);
return *this;
}
static Address AddressRIPRelative(int32_t disp) {
return Address(RIPRelativeDisp(disp));
}
static Address AddressBaseImm32(Register base, int32_t disp) {
return Address(base, disp, true);
}
// This addressing mode does not exist.
static Address AddressBaseImm32(Register base, Register r);
private:
Address(Register base, int32_t disp, bool fixed) {
ASSERT(fixed);
SetModRM(2, base);
if ((base & 7) == RSP) {
SetSIB(TIMES_1, RSP, base);
}
SetDisp32(disp);
}
struct RIPRelativeDisp {
explicit RIPRelativeDisp(int32_t disp) : disp_(disp) {}
const int32_t disp_;
};
explicit Address(const RIPRelativeDisp& disp) {
SetModRM(0, static_cast<Register>(0x5));
SetDisp32(disp.disp_);
}
};
class FieldAddress : public Address {
public:
FieldAddress(Register base, int32_t disp)
: Address(base, disp - kHeapObjectTag) {}
// This addressing mode does not exist.
FieldAddress(Register base, Register r);
FieldAddress(Register base, Register index, ScaleFactor scale, int32_t disp)
: Address(base, index, scale, disp - kHeapObjectTag) {}
// This addressing mode does not exist.
FieldAddress(Register base, Register index, ScaleFactor scale, Register r);
FieldAddress(const FieldAddress& other) : Address(other) {}
FieldAddress& operator=(const FieldAddress& other) {
Address::operator=(other);
return *this;
}
};
class Assembler : public AssemblerBase {
public:
explicit Assembler(ObjectPoolBuilder* object_pool_builder,
bool use_far_branches = false);
~Assembler() {}
/*
* Emit Machine Instructions.
*/
void call(Register reg) { EmitUnaryL(reg, 0xFF, 2); }
void call(const Address& address) { EmitUnaryL(address, 0xFF, 2); }
void call(Label* label);
void call(const ExternalLabel* label);
void pushq(Register reg);
void pushq(const Address& address) { EmitUnaryL(address, 0xFF, 6); }
void pushq(const Immediate& imm);
void PushImmediate(const Immediate& imm) { pushq(imm); }
void PushImmediate(int64_t value) { PushImmediate(Immediate(value)); }
void popq(Register reg);
void popq(const Address& address) { EmitUnaryL(address, 0x8F, 0); }
void setcc(Condition condition, ByteRegister dst);
void EnterSafepoint();
void LeaveSafepoint();
void TransitionGeneratedToNative(Register destination_address,
Register new_exit_frame,
Register new_exit_through_ffi,
bool enter_safepoint);
void TransitionNativeToGenerated(bool leave_safepoint);
// Register-register, register-address and address-register instructions.
#define RR(width, name, ...) \
void name(Register dst, Register src) { Emit##width(dst, src, __VA_ARGS__); }
#define RA(width, name, ...) \
void name(Register dst, const Address& src) { \
Emit##width(dst, src, __VA_ARGS__); \
}
#define AR(width, name, ...) \
void name(const Address& dst, Register src) { \
Emit##width(src, dst, __VA_ARGS__); \
}
#define REGULAR_INSTRUCTION(name, ...) \
RA(W, name##w, __VA_ARGS__) \
RA(L, name##l, __VA_ARGS__) \
RA(Q, name##q, __VA_ARGS__) \
RR(W, name##w, __VA_ARGS__) \
RR(L, name##l, __VA_ARGS__) \
RR(Q, name##q, __VA_ARGS__)
REGULAR_INSTRUCTION(test, 0x85)
REGULAR_INSTRUCTION(xchg, 0x87)
REGULAR_INSTRUCTION(imul, 0xAF, 0x0F)
REGULAR_INSTRUCTION(bsf, 0xBC, 0x0F)
REGULAR_INSTRUCTION(bsr, 0xBD, 0x0F)
REGULAR_INSTRUCTION(popcnt, 0xB8, 0x0F, 0xF3)
REGULAR_INSTRUCTION(lzcnt, 0xBD, 0x0F, 0xF3)
#undef REGULAR_INSTRUCTION
RA(Q, movsxd, 0x63)
RR(Q, movsxd, 0x63)
AR(L, movb, 0x88)
AR(L, movl, 0x89)
AR(Q, movq, 0x89)
AR(W, movw, 0x89)
RA(L, movb, 0x8A)
RA(L, movl, 0x8B)
RA(Q, movq, 0x8B)
RR(L, movl, 0x8B)
RA(Q, leaq, 0x8D)
RA(L, leal, 0x8D)
AR(L, cmpxchgl, 0xB1, 0x0F)
AR(Q, cmpxchgq, 0xB1, 0x0F)
RA(L, cmpxchgl, 0xB1, 0x0F)
RA(Q, cmpxchgq, 0xB1, 0x0F)
RR(L, cmpxchgl, 0xB1, 0x0F)
RR(Q, cmpxchgq, 0xB1, 0x0F)
RA(Q, movzxb, 0xB6, 0x0F)
RR(Q, movzxb, 0xB6, 0x0F)
RA(Q, movzxw, 0xB7, 0x0F)
RR(Q, movzxw, 0xB7, 0x0F)
RA(Q, movsxb, 0xBE, 0x0F)
RR(Q, movsxb, 0xBE, 0x0F)
RA(Q, movsxw, 0xBF, 0x0F)
RR(Q, movsxw, 0xBF, 0x0F)
#define DECLARE_CMOV(name, code) \
RR(Q, cmov##name##q, 0x40 + code, 0x0F) \
RR(L, cmov##name##l, 0x40 + code, 0x0F) \
RA(Q, cmov##name##q, 0x40 + code, 0x0F) \
RA(L, cmov##name##l, 0x40 + code, 0x0F)
X86_CONDITIONAL_SUFFIXES(DECLARE_CMOV)
#undef DECLARE_CMOV
#undef AA
#undef RA
#undef AR
#define SIMPLE(name, ...) \
void name() { EmitSimple(__VA_ARGS__); }
SIMPLE(cpuid, 0x0F, 0xA2)
SIMPLE(fcos, 0xD9, 0xFF)
SIMPLE(fincstp, 0xD9, 0xF7)
SIMPLE(fsin, 0xD9, 0xFE)
SIMPLE(lock, 0xF0)
SIMPLE(rep_movsb, 0xF3, 0xA4)
SIMPLE(rep_movsw, 0xF3, 0x66, 0xA5)
SIMPLE(rep_movsl, 0xF3, 0xA5)
SIMPLE(rep_movsq, 0xF3, 0x48, 0xA5)
#undef SIMPLE
// XmmRegister operations with another register or an address.
#define XX(width, name, ...) \
void name(XmmRegister dst, XmmRegister src) { \
Emit##width(dst, src, __VA_ARGS__); \
}
#define XA(width, name, ...) \
void name(XmmRegister dst, const Address& src) { \
Emit##width(dst, src, __VA_ARGS__); \
}
#define AX(width, name, ...) \
void name(const Address& dst, XmmRegister src) { \
Emit##width(src, dst, __VA_ARGS__); \
}
// We could add movupd here, but movups does the same and is shorter.
XA(L, movups, 0x10, 0x0F);
XA(L, movsd, 0x10, 0x0F, 0xF2)
XA(L, movss, 0x10, 0x0F, 0xF3)
AX(L, movups, 0x11, 0x0F);
AX(L, movsd, 0x11, 0x0F, 0xF2)
AX(L, movss, 0x11, 0x0F, 0xF3)
XX(L, movhlps, 0x12, 0x0F)
XX(L, unpcklps, 0x14, 0x0F)
XX(L, unpcklpd, 0x14, 0x0F, 0x66)
XX(L, unpckhps, 0x15, 0x0F)
XX(L, unpckhpd, 0x15, 0x0F, 0x66)
XX(L, movlhps, 0x16, 0x0F)
XX(L, movaps, 0x28, 0x0F)
XX(L, comisd, 0x2F, 0x0F, 0x66)
#define DECLARE_XMM(name, code) \
XX(L, name##ps, 0x50 + code, 0x0F) \
XA(L, name##ps, 0x50 + code, 0x0F) \
AX(L, name##ps, 0x50 + code, 0x0F) \
XX(L, name##pd, 0x50 + code, 0x0F, 0x66) \
XA(L, name##pd, 0x50 + code, 0x0F, 0x66) \
AX(L, name##pd, 0x50 + code, 0x0F, 0x66) \
XX(L, name##sd, 0x50 + code, 0x0F, 0xF2) \
XA(L, name##sd, 0x50 + code, 0x0F, 0xF2) \
AX(L, name##sd, 0x50 + code, 0x0F, 0xF2) \
XX(L, name##ss, 0x50 + code, 0x0F, 0xF3) \
XA(L, name##ss, 0x50 + code, 0x0F, 0xF3) \
AX(L, name##ss, 0x50 + code, 0x0F, 0xF3)
XMM_ALU_CODES(DECLARE_XMM)
#undef DECLARE_XMM
XX(L, cvtps2pd, 0x5A, 0x0F)
XX(L, cvtpd2ps, 0x5A, 0x0F, 0x66)
XX(L, cvtsd2ss, 0x5A, 0x0F, 0xF2)
XX(L, cvtss2sd, 0x5A, 0x0F, 0xF3)
XX(L, pxor, 0xEF, 0x0F, 0x66)
XX(L, subpl, 0xFA, 0x0F, 0x66)
XX(L, addpl, 0xFE, 0x0F, 0x66)
#undef XX
#undef AX
#undef XA
#define DECLARE_CMPPS(name, code) \
void cmpps##name(XmmRegister dst, XmmRegister src) { \
EmitL(dst, src, 0xC2, 0x0F); \
AssemblerBuffer::EnsureCapacity ensured(&buffer_); \
EmitUint8(code); \
}
XMM_CONDITIONAL_CODES(DECLARE_CMPPS)
#undef DECLARE_CMPPS
#define DECLARE_SIMPLE(name, opcode) \
void name() { EmitSimple(opcode); }
X86_ZERO_OPERAND_1_BYTE_INSTRUCTIONS(DECLARE_SIMPLE)
#undef DECLARE_SIMPLE
void movl(Register dst, const Immediate& imm);
void movl(const Address& dst, const Immediate& imm);
void movb(const Address& dst, const Immediate& imm);
void movw(Register dst, const Address& src);
void movw(const Address& dst, const Immediate& imm);
void movq(Register dst, const Immediate& imm);
void movq(const Address& dst, const Immediate& imm);
// Destination and source are reversed for some reason.
void movq(Register dst, XmmRegister src) {
EmitQ(src, dst, 0x7E, 0x0F, 0x66);
}
void movl(Register dst, XmmRegister src) {
EmitL(src, dst, 0x7E, 0x0F, 0x66);
}
void movss(XmmRegister dst, XmmRegister src) {
EmitL(src, dst, 0x11, 0x0F, 0xF3);
}
void movsd(XmmRegister dst, XmmRegister src) {
EmitL(src, dst, 0x11, 0x0F, 0xF2);
}
// Use the reversed operand order and the 0x89 bytecode instead of the
// obvious 0x88 encoding for this some, because it is expected by gdb64 older
// than 7.3.1-gg5 when disassembling a function's prologue (movq rbp, rsp)
// for proper unwinding of Dart frames (use --generate_gdb_symbols and -O0).
void movq(Register dst, Register src) { EmitQ(src, dst, 0x89); }
void movq(XmmRegister dst, Register src) {
EmitQ(dst, src, 0x6E, 0x0F, 0x66);
}
void movd(XmmRegister dst, Register src) {
EmitL(dst, src, 0x6E, 0x0F, 0x66);
}
void cvtsi2sdq(XmmRegister dst, Register src) {
EmitQ(dst, src, 0x2A, 0x0F, 0xF2);
}
void cvtsi2sdl(XmmRegister dst, Register src) {
EmitL(dst, src, 0x2A, 0x0F, 0xF2);
}
void cvttsd2siq(Register dst, XmmRegister src) {
EmitQ(dst, src, 0x2C, 0x0F, 0xF2);
}
void cvttsd2sil(Register dst, XmmRegister src) {
EmitL(dst, src, 0x2C, 0x0F, 0xF2);
}
void movmskpd(Register dst, XmmRegister src) {
EmitL(dst, src, 0x50, 0x0F, 0x66);
}
void movmskps(Register dst, XmmRegister src) { EmitL(dst, src, 0x50, 0x0F); }
void pmovmskb(Register dst, XmmRegister src) {
EmitL(dst, src, 0xD7, 0x0F, 0x66);
}
void btl(Register dst, Register src) { EmitL(src, dst, 0xA3, 0x0F); }
void btq(Register dst, Register src) { EmitQ(src, dst, 0xA3, 0x0F); }
void notps(XmmRegister dst, XmmRegister src);
void negateps(XmmRegister dst, XmmRegister src);
void absps(XmmRegister dst, XmmRegister src);
void zerowps(XmmRegister dst, XmmRegister src);
void set1ps(XmmRegister dst, Register tmp, const Immediate& imm);
void shufps(XmmRegister dst, XmmRegister src, const Immediate& mask);
void negatepd(XmmRegister dst, XmmRegister src);
void abspd(XmmRegister dst, XmmRegister src);
void shufpd(XmmRegister dst, XmmRegister src, const Immediate& mask);
enum RoundingMode {
kRoundToNearest = 0x0,
kRoundDown = 0x1,
kRoundUp = 0x2,
kRoundToZero = 0x3
};
void roundsd(XmmRegister dst, XmmRegister src, RoundingMode mode);
void CompareImmediate(Register reg, const Immediate& imm);
void CompareImmediate(const Address& address, const Immediate& imm);
void CompareImmediate(Register reg, int32_t immediate) {
return CompareImmediate(reg, Immediate(immediate));
}
void testl(Register reg, const Immediate& imm) { testq(reg, imm); }
void testb(const Address& address, const Immediate& imm);
void testb(const Address& address, Register reg);
void testq(Register reg, const Immediate& imm);
void TestImmediate(Register dst, const Immediate& imm);
void AndImmediate(Register dst, const Immediate& imm);
void OrImmediate(Register dst, const Immediate& imm);
void XorImmediate(Register dst, const Immediate& imm);
void shldq(Register dst, Register src, Register shifter) {
ASSERT(shifter == RCX);
EmitQ(src, dst, 0xA5, 0x0F);
}
void shrdq(Register dst, Register src, Register shifter) {
ASSERT(shifter == RCX);
EmitQ(src, dst, 0xAD, 0x0F);
}
#define DECLARE_ALU(op, c) \
void op##w(Register dst, Register src) { EmitW(dst, src, c * 8 + 3); } \
void op##l(Register dst, Register src) { EmitL(dst, src, c * 8 + 3); } \
void op##q(Register dst, Register src) { EmitQ(dst, src, c * 8 + 3); } \
void op##w(Register dst, const Address& src) { EmitW(dst, src, c * 8 + 3); } \
void op##l(Register dst, const Address& src) { EmitL(dst, src, c * 8 + 3); } \
void op##q(Register dst, const Address& src) { EmitQ(dst, src, c * 8 + 3); } \
void op##w(const Address& dst, Register src) { EmitW(src, dst, c * 8 + 1); } \
void op##l(const Address& dst, Register src) { EmitL(src, dst, c * 8 + 1); } \
void op##q(const Address& dst, Register src) { EmitQ(src, dst, c * 8 + 1); } \
void op##l(Register dst, const Immediate& imm) { AluL(c, dst, imm); } \
void op##q(Register dst, const Immediate& imm) { \
AluQ(c, c * 8 + 3, dst, imm); \
} \
void op##b(const Address& dst, const Immediate& imm) { AluB(c, dst, imm); } \
void op##w(const Address& dst, const Immediate& imm) { AluW(c, dst, imm); } \
void op##l(const Address& dst, const Immediate& imm) { AluL(c, dst, imm); } \
void op##q(const Address& dst, const Immediate& imm) { \
AluQ(c, c * 8 + 3, dst, imm); \
}
X86_ALU_CODES(DECLARE_ALU)
#undef DECLARE_ALU
#undef ALU_OPS
void cqo();
#define REGULAR_UNARY(name, opcode, modrm) \
void name##q(Register reg) { EmitUnaryQ(reg, opcode, modrm); } \
void name##l(Register reg) { EmitUnaryL(reg, opcode, modrm); } \
void name##q(const Address& address) { EmitUnaryQ(address, opcode, modrm); } \
void name##l(const Address& address) { EmitUnaryL(address, opcode, modrm); }
REGULAR_UNARY(not, 0xF7, 2)
REGULAR_UNARY(neg, 0xF7, 3)
REGULAR_UNARY(mul, 0xF7, 4)
REGULAR_UNARY(imul, 0xF7, 5)
REGULAR_UNARY(div, 0xF7, 6)
REGULAR_UNARY(idiv, 0xF7, 7)
REGULAR_UNARY(inc, 0xFF, 0)
REGULAR_UNARY(dec, 0xFF, 1)
#undef REGULAR_UNARY
void imull(Register reg, const Immediate& imm);
void imulq(Register dst, const Immediate& imm);
void MulImmediate(Register reg,
const Immediate& imm,
OperandSize width = kEightBytes);
void shll(Register reg, const Immediate& imm);
void shll(Register operand, Register shifter);
void shrl(Register reg, const Immediate& imm);
void shrl(Register operand, Register shifter);
void sarl(Register reg, const Immediate& imm);
void sarl(Register operand, Register shifter);
void shldl(Register dst, Register src, const Immediate& imm);
void shlq(Register reg, const Immediate& imm);
void shlq(Register operand, Register shifter);
void shrq(Register reg, const Immediate& imm);
void shrq(Register operand, Register shifter);
void sarq(Register reg, const Immediate& imm);
void sarq(Register operand, Register shifter);
void shldq(Register dst, Register src, const Immediate& imm);
void btq(Register base, int bit);
void enter(const Immediate& imm);
void fldl(const Address& src);
void fstpl(const Address& dst);
void ffree(intptr_t value);
// 'size' indicates size in bytes and must be in the range 1..8.
void nop(int size = 1);
void j(Condition condition, Label* label, JumpDistance distance = kFarJump);
void jmp(Register reg) { EmitUnaryL(reg, 0xFF, 4); }
void jmp(const Address& address) { EmitUnaryL(address, 0xFF, 4); }
void jmp(Label* label, JumpDistance distance = kFarJump);
void jmp(const ExternalLabel* label);
void jmp(const Code& code);
// Issue memory to memory move through a TMP register.
// TODO(koda): Assert that these are not used for heap objects.
void MoveMemoryToMemory(const Address& dst, const Address& src) {
movq(TMP, src);
movq(dst, TMP);
}
void Exchange(Register reg, const Address& mem) {
movq(TMP, mem);
movq(mem, reg);
movq(reg, TMP);
}
void Exchange(const Address& mem1, const Address& mem2) {
movq(TMP, mem1);
xorq(TMP, mem2);
xorq(mem1, TMP);
xorq(mem2, TMP);
}
// Methods for High-level operations and implemented on all architectures.
void Ret() { ret(); }
void CompareRegisters(Register a, Register b);
void BranchIf(Condition condition,
Label* label,
JumpDistance distance = kFarJump) {
j(condition, label, distance);
}
void BranchIfZero(Register src,
Label* label,
JumpDistance distance = kFarJump) {
cmpq(src, Immediate(0));
j(ZERO, label, distance);
}
// Issues a move instruction if 'to' is not the same as 'from'.
void MoveRegister(Register to, Register from);
void PushRegister(Register r);
void PopRegister(Register r);
void PushRegisterPair(Register r0, Register r1) {
PushRegister(r1);
PushRegister(r0);
}
void PopRegisterPair(Register r0, Register r1) {
PopRegister(r0);
PopRegister(r1);
}
// Methods for adding/subtracting an immediate value that may be loaded from
// the constant pool.
// TODO(koda): Assert that these are not used for heap objects.
void AddImmediate(Register reg,
const Immediate& imm,
OperandSize width = kEightBytes);
void AddImmediate(Register reg,
int32_t value,
OperandSize width = kEightBytes) {
AddImmediate(reg, Immediate(value), width);
}
void AddImmediate(const Address& address, const Immediate& imm);
void SubImmediate(Register reg,
const Immediate& imm,
OperandSize width = kEightBytes);
void SubImmediate(const Address& address, const Immediate& imm);
void Drop(intptr_t stack_elements, Register tmp = TMP);
bool constant_pool_allowed() const { return constant_pool_allowed_; }
void set_constant_pool_allowed(bool b) { constant_pool_allowed_ = b; }
// Unlike movq this can affect the flags or use the constant pool.
void LoadImmediate(Register reg, const Immediate& imm);
void LoadImmediate(Register reg, int32_t immediate) {
LoadImmediate(reg, Immediate(immediate));
}
void LoadIsolate(Register dst);
void LoadIsolateGroup(Register dst);
void LoadDispatchTable(Register dst);
void LoadObject(Register dst, const Object& obj);
void LoadUniqueObject(Register dst, const Object& obj);
void LoadNativeEntry(Register dst,
const ExternalLabel* label,
ObjectPoolBuilderEntry::Patchability patchable);
void JmpPatchable(const Code& code, Register pp);
void Jmp(const Code& code, Register pp = PP);
void J(Condition condition, const Code& code, Register pp);
void CallPatchable(const Code& code,
CodeEntryKind entry_kind = CodeEntryKind::kNormal);
void Call(const Code& stub_entry);
void CallToRuntime();
// Emit a call that shares its object pool entries with other calls
// that have the same equivalence marker.
void CallWithEquivalence(const Code& code,
const Object& equivalence,
CodeEntryKind entry_kind = CodeEntryKind::kNormal);
void Call(Address target) { call(target); }
// Unaware of write barrier (use StoreInto* methods for storing to objects).
// TODO(koda): Add StackAddress/HeapAddress types to prevent misuse.
void StoreObject(const Address& dst, const Object& obj);
void PushObject(const Object& object);
void CompareObject(Register reg, const Object& object);
enum CanBeSmi {
kValueIsNotSmi,
kValueCanBeSmi,
};
void LoadCompressed(Register dest,
const Address& slot,
CanBeSmi can_value_be_smi = kValueCanBeSmi);
// Store into a heap object and apply the generational and incremental write
// barriers. All stores into heap objects must pass through this function or,
// if the value can be proven either Smi or old-and-premarked, its NoBarrier
// variants.
// Preserves object and value registers.
void StoreIntoObject(Register object, // Object we are storing into.
const Address& dest, // Where we are storing into.
Register value, // Value we are storing.
CanBeSmi can_be_smi = kValueCanBeSmi);
void StoreIntoArray(Register object, // Object we are storing into.
Register slot, // Where we are storing into.
Register value, // Value we are storing.
CanBeSmi can_be_smi = kValueCanBeSmi);
void StoreIntoObjectNoBarrier(Register object,
const Address& dest,
Register value);
void StoreIntoObjectNoBarrier(Register object,
const Address& dest,
const Object& value);
// Stores a non-tagged value into a heap object.
void StoreInternalPointer(Register object,
const Address& dest,
Register value);
// Stores a Smi value into a heap object field that always contains a Smi.
void StoreIntoSmiField(const Address& dest, Register value);
void ZeroInitSmiField(const Address& dest);
// Increments a Smi field. Leaves flags in same state as an 'addq'.
void IncrementSmiField(const Address& dest, int64_t increment);
void DoubleNegate(XmmRegister dst, XmmRegister src);
void DoubleAbs(XmmRegister dst, XmmRegister src);
void LockCmpxchgq(const Address& address, Register reg) {
lock();
cmpxchgq(address, reg);
}
void LockCmpxchgl(const Address& address, Register reg) {
lock();
cmpxchgl(address, reg);
}
void PushRegisters(const RegisterSet& registers);
void PopRegisters(const RegisterSet& registers);
void CheckCodePointer();
void EnterFrame(intptr_t frame_space);
void LeaveFrame();
void ReserveAlignedFrameSpace(intptr_t frame_space);
// In debug mode, generates code to verify that:
// FP + kExitLinkSlotFromFp == SP
//
// Triggers breakpoint otherwise.
// Clobbers RAX.
void EmitEntryFrameVerification();
// Create a frame for calling into runtime that preserves all volatile
// registers. Frame's RSP is guaranteed to be correctly aligned and
// frame_space bytes are reserved under it.
void EnterCallRuntimeFrame(intptr_t frame_space);
void LeaveCallRuntimeFrame();
void CallRuntime(const RuntimeEntry& entry, intptr_t argument_count);
// Call runtime function. Reserves shadow space on the stack before calling
// if platform ABI requires that.
void CallCFunction(Register reg, bool restore_rsp = false);
void CallCFunction(Address address, bool restore_rsp = false);
void ExtractClassIdFromTags(Register result, Register tags);
void ExtractInstanceSizeFromTags(Register result, Register tags);
// Loading and comparing classes of objects.
void LoadClassId(Register result, Register object);
void LoadClassById(Register result, Register class_id);
void CompareClassId(Register object,
intptr_t class_id,
Register scratch = kNoRegister);
void LoadClassIdMayBeSmi(Register result, Register object);
void LoadTaggedClassIdMayBeSmi(Register result, Register object);
// CheckClassIs fused with optimistic SmiUntag.
// Value in the register object is untagged optimistically.
void SmiUntagOrCheckClass(Register object, intptr_t class_id, Label* smi);
// Misc. functionality.
void SmiTag(Register reg) { addq(reg, reg); }
void SmiUntag(Register reg) { sarq(reg, Immediate(kSmiTagSize)); }
void BranchIfNotSmi(Register reg,
Label* label,
JumpDistance distance = kFarJump) {
testq(reg, Immediate(kSmiTagMask));
j(NOT_ZERO, label, distance);
}
void BranchIfSmi(Register reg,
Label* label,
JumpDistance distance = kFarJump) {
testq(reg, Immediate(kSmiTagMask));
j(ZERO, label, distance);
}
void Align(int alignment, intptr_t offset);
void Bind(Label* label);
// Unconditional jump to a given label.
void Jump(Label* label, JumpDistance distance = kFarJump) {
jmp(label, distance);
}
// Unconditional jump to a given address in memory.
void Jump(const Address& address) { jmp(address); }
// Arch-specific LoadFromOffset to choose the right operation for [sz].
void LoadFromOffset(Register dst,
const Address& address,
OperandSize sz = kEightBytes);
void LoadFromOffset(Register dst,
Register base,
int32_t offset,
OperandSize sz = kEightBytes) {
LoadFromOffset(dst, Address(base, offset), sz);
}
void LoadField(Register dst,
FieldAddress address,
OperandSize sz = kEightBytes) {
LoadFromOffset(dst, address, sz);
}
void LoadFieldFromOffset(Register dst,
Register base,
int32_t offset,
OperandSize sz = kEightBytes) {
LoadFromOffset(dst, FieldAddress(base, offset), sz);
}
void LoadIndexedPayload(Register dst,
Register base,
int32_t payload_offset,
Register index,
ScaleFactor scale,
OperandSize sz = kEightBytes) {
LoadFromOffset(dst, FieldAddress(base, index, scale, payload_offset), sz);
}
void StoreFieldToOffset(Register src,
Register base,
int32_t offset,
OperandSize sz = kEightBytes) {
if (sz != kEightBytes) {
UNIMPLEMENTED();
}
StoreMemoryValue(src, base, offset - kHeapObjectTag);
}
void LoadFromStack(Register dst, intptr_t depth);
void StoreToStack(Register src, intptr_t depth);
void CompareToStack(Register src, intptr_t depth);
void LoadMemoryValue(Register dst, Register base, int32_t offset) {
movq(dst, Address(base, offset));
}
void StoreMemoryValue(Register src, Register base, int32_t offset) {
movq(Address(base, offset), src);
}
void LoadAcquire(Register dst, Register address, int32_t offset = 0) {
// On intel loads have load-acquire behavior (i.e. loads are not re-ordered
// with other loads).
movq(dst, Address(address, offset));
}
void StoreRelease(Register src, Register address, int32_t offset = 0) {
// On intel stores have store-release behavior (i.e. stores are not
// re-ordered with other stores).
movq(Address(address, offset), src);
}
void CompareWithFieldValue(Register value, FieldAddress address) {
cmpq(value, address);
}
void CompareTypeNullabilityWith(Register type, int8_t value) {
cmpb(FieldAddress(type, compiler::target::Type::nullability_offset()),
Immediate(value));
}
void RestoreCodePointer();
void LoadPoolPointer(Register pp = PP);
// Set up a Dart frame on entry with a frame pointer and PC information to
// enable easy access to the RawInstruction object of code corresponding
// to this frame.
// The dart frame layout is as follows:
// ....
// locals space <=== RSP
// saved PP
// code object (used to derive the RawInstruction Object of the dart code)
// saved RBP <=== RBP
// ret PC
// .....
// This code sets this up with the sequence:
// pushq rbp
// movq rbp, rsp
// call L
// L: <code to adjust saved pc if there is any intrinsification code>
// ...
// pushq r15
// .....
void EnterDartFrame(intptr_t frame_size, Register new_pp = kNoRegister);
void LeaveDartFrame(RestorePP restore_pp = kRestoreCallerPP);
// Set up a Dart frame for a function compiled for on-stack replacement.
// The frame layout is a normal Dart frame, but the frame is partially set
// up on entry (it is the frame of the unoptimized code).
void EnterOsrFrame(intptr_t extra_size);
// Set up a stub frame so that the stack traversal code can easily identify
// a stub frame.
// The stub frame layout is as follows:
// .... <=== RSP
// pc (used to derive the RawInstruction Object of the stub)
// saved RBP <=== RBP
// ret PC
// .....
// This code sets this up with the sequence:
// pushq rbp
// movq rbp, rsp
// pushq immediate(0)
// .....
void EnterStubFrame();
void LeaveStubFrame();
// Set up a frame for calling a C function.
// Automatically save the pinned registers in Dart which are not callee-
// saved in the native calling convention.
// Use together with CallCFunction.
void EnterCFrame(intptr_t frame_space);
void LeaveCFrame();
void MonomorphicCheckedEntryJIT();
void MonomorphicCheckedEntryAOT();
void BranchOnMonomorphicCheckedEntryJIT(Label* label);
// If allocation tracing for |cid| is enabled, will jump to |trace| label,
// which will allocate in the runtime where tracing occurs.
void MaybeTraceAllocation(intptr_t cid, Label* trace, JumpDistance distance);
// Inlined allocation of an instance of class 'cls', code has no runtime
// calls. Jump to 'failure' if the instance cannot be allocated here.
// Allocated instance is returned in 'instance_reg'.
// Only the tags field of the object is initialized.
void TryAllocate(const Class& cls,
Label* failure,
JumpDistance distance,
Register instance_reg,
Register temp);
void TryAllocateArray(intptr_t cid,
intptr_t instance_size,
Label* failure,
JumpDistance distance,
Register instance,
Register end_address,
Register temp);
// This emits an PC-relative call of the form "callq *[rip+<offset>]". The
// offset is not yet known and needs therefore relocation to the right place
// before the code can be used.
//
// The neccessary information for the "linker" (i.e. the relocation
// information) is stored in [UntaggedCode::static_calls_target_table_]: an
// entry of the form
//
// (Code::kPcRelativeCall & pc_offset, <target-code>, <target-function>)
//
// will be used during relocation to fix the offset.
//
// The provided [offset_into_target] will be added to calculate the final
// destination. It can be used e.g. for calling into the middle of a
// function.
void GenerateUnRelocatedPcRelativeCall(intptr_t offset_into_target = 0);
// This emits an PC-relative tail call of the form "jmp *[rip+<offset>]".
//
// See also above for the pc-relative call.
void GenerateUnRelocatedPcRelativeTailCall(intptr_t offset_into_target = 0);
// Debugging and bringup support.
void Breakpoint() override { int3(); }
static Address ElementAddressForIntIndex(bool is_external,
intptr_t cid,
intptr_t index_scale,
Register array,
intptr_t index);
static Address ElementAddressForRegIndex(bool is_external,
intptr_t cid,
intptr_t index_scale,
bool index_unboxed,
Register array,
Register index);
void LoadFieldAddressForRegOffset(Register address,
Register instance,
Register offset_in_words_as_smi) {
static_assert(kSmiTagShift == 1, "adjust scale factor");
leaq(address, FieldAddress(instance, offset_in_words_as_smi, TIMES_4, 0));
}
static Address VMTagAddress();
// On some other platforms, we draw a distinction between safe and unsafe
// smis.
static bool IsSafe(const Object& object) { return true; }
static bool IsSafeSmi(const Object& object) { return target::IsSmi(object); }
private:
bool constant_pool_allowed_;
intptr_t FindImmediate(int64_t imm);
bool CanLoadFromObjectPool(const Object& object) const;
void LoadObjectHelper(Register dst, const Object& obj, bool is_unique);
void LoadWordFromPoolIndex(Register dst, intptr_t index);
void AluL(uint8_t modrm_opcode, Register dst, const Immediate& imm);
void AluB(uint8_t modrm_opcode, const Address& dst, const Immediate& imm);
void AluW(uint8_t modrm_opcode, const Address& dst, const Immediate& imm);
void AluL(uint8_t modrm_opcode, const Address& dst, const Immediate& imm);
void AluQ(uint8_t modrm_opcode,
uint8_t opcode,
Register dst,
const Immediate& imm);
void AluQ(uint8_t modrm_opcode,
uint8_t opcode,
const Address& dst,
const Immediate& imm);
void EmitSimple(int opcode, int opcode2 = -1, int opcode3 = -1);
void EmitUnaryQ(Register reg, int opcode, int modrm_code);
void EmitUnaryL(Register reg, int opcode, int modrm_code);
void EmitUnaryQ(const Address& address, int opcode, int modrm_code);
void EmitUnaryL(const Address& address, int opcode, int modrm_code);
// The prefixes are in reverse order due to the rules of default arguments in
// C++.
void EmitQ(int reg,
const Address& address,
int opcode,
int prefix2 = -1,
int prefix1 = -1);
void EmitL(int reg,
const Address& address,
int opcode,
int prefix2 = -1,
int prefix1 = -1);
void EmitW(Register reg,
const Address& address,
int opcode,
int prefix2 = -1,
int prefix1 = -1);
void EmitQ(int dst, int src, int opcode, int prefix2 = -1, int prefix1 = -1);
void EmitL(int dst, int src, int opcode, int prefix2 = -1, int prefix1 = -1);
void EmitW(Register dst,
Register src,
int opcode,
int prefix2 = -1,
int prefix1 = -1);
void CmpPS(XmmRegister dst, XmmRegister src, int condition);
inline void EmitUint8(uint8_t value);
inline void EmitInt32(int32_t value);
inline void EmitUInt32(uint32_t value);
inline void EmitInt64(int64_t value);
inline void EmitRegisterREX(Register reg,
uint8_t rex,
bool force_emit = false);
inline void EmitOperandREX(int rm, const Operand& operand, uint8_t rex);
inline void EmitRegisterOperand(int rm, int reg);
inline void EmitFixup(AssemblerFixup* fixup);
inline void EmitOperandSizeOverride();
inline void EmitRegRegRex(int reg, int base, uint8_t rex = REX_NONE);
void EmitOperand(int rm, const Operand& operand);
void EmitImmediate(const Immediate& imm);
void EmitComplex(int rm, const Operand& operand, const Immediate& immediate);
void EmitSignExtendedInt8(int rm,
const Operand& operand,
const Immediate& immediate);
void EmitLabel(Label* label, intptr_t instruction_size);
void EmitLabelLink(Label* label);
void EmitNearLabelLink(Label* label);
void EmitGenericShift(bool wide, int rm, Register reg, const Immediate& imm);
void EmitGenericShift(bool wide, int rm, Register operand, Register shifter);
enum BarrierFilterMode {
// Filter falls through into the barrier update code. Target label
// is a "after-store" label.
kJumpToNoUpdate,
// Filter falls through to the "after-store" code. Target label
// is barrier update code label.
kJumpToBarrier,
};
void StoreIntoObjectFilter(Register object,
Register value,
Label* label,
CanBeSmi can_be_smi,
BarrierFilterMode barrier_filter_mode);
// Unaware of write barrier (use StoreInto* methods for storing to objects).
void MoveImmediate(const Address& dst, const Immediate& imm);
friend class dart::FlowGraphCompiler;
std::function<void(Register reg)> generate_invoke_write_barrier_wrapper_;
std::function<void()> generate_invoke_array_write_barrier_;
DISALLOW_ALLOCATION();
DISALLOW_COPY_AND_ASSIGN(Assembler);
};
inline void Assembler::EmitUint8(uint8_t value) {
buffer_.Emit<uint8_t>(value);
}
inline void Assembler::EmitInt32(int32_t value) {
buffer_.Emit<int32_t>(value);
}
inline void Assembler::EmitUInt32(uint32_t value) {
buffer_.Emit<uint32_t>(value);
}
inline void Assembler::EmitInt64(int64_t value) {
buffer_.Emit<int64_t>(value);
}
inline void Assembler::EmitRegisterREX(Register reg, uint8_t rex, bool force) {
ASSERT(reg != kNoRegister && reg <= R15);
ASSERT(rex == REX_NONE || rex == REX_W);
rex |= (reg > 7 ? REX_B : REX_NONE);
if (rex != REX_NONE || force) EmitUint8(REX_PREFIX | rex);
}
inline void Assembler::EmitOperandREX(int rm,
const Operand& operand,
uint8_t rex) {
rex |= (rm > 7 ? REX_R : REX_NONE) | operand.rex();
if (rex != REX_NONE) EmitUint8(REX_PREFIX | rex);
}
inline void Assembler::EmitRegRegRex(int reg, int base, uint8_t rex) {
ASSERT(reg != kNoRegister && reg <= R15);
ASSERT(base != kNoRegister && base <= R15);
ASSERT(rex == REX_NONE || rex == REX_W);
if (reg > 7) rex |= REX_R;
if (base > 7) rex |= REX_B;
if (rex != REX_NONE) EmitUint8(REX_PREFIX | rex);
}
inline void Assembler::EmitFixup(AssemblerFixup* fixup) {
buffer_.EmitFixup(fixup);
}
inline void Assembler::EmitOperandSizeOverride() {
EmitUint8(0x66);
}
} // namespace compiler
} // namespace dart
#endif // RUNTIME_VM_COMPILER_ASSEMBLER_ASSEMBLER_X64_H_
| 36.621492 | 80 | 0.623711 |
82fc6fc24ca9e187e0b648ee12a3c3903d15717b | 459 | c | C | Sum Of Even Numbers.c | Wicerradien/C | a0ef1230a916a50918840c88f2eb0d9a8023599c | [
"MIT"
] | null | null | null | Sum Of Even Numbers.c | Wicerradien/C | a0ef1230a916a50918840c88f2eb0d9a8023599c | [
"MIT"
] | null | null | null | Sum Of Even Numbers.c | Wicerradien/C | a0ef1230a916a50918840c88f2eb0d9a8023599c | [
"MIT"
] | null | null | null | //
// main.c
// Sum Of Even Numbers Using Recurtion
//
// Created by Nafiur Rahman Dhrubo on 10/3/20.
//
#include <stdio.h>
int even_Sum (int x);
int main ()
{
int n, sum;
printf("Enter the number : ");
scanf("%d", &n);
printf("Sum of even numbers %d\n", even_Sum(n));
return 0;
}
int even_Sum(int x)
{
if (x == 0)
{
return 0;
}
else if (x % 2 == 0)
{
return 2 * x + even_Sum(x - 1);
}
}
| 14.34375 | 52 | 0.503268 |
963edf34adb61fb8d0b429913adf4fff7c9e958c | 4,890 | c | C | ds1307/ds1307.c | tfateba/drivers | 5d66b17d402ca75ff5fd486bee83315643ccdf0a | [
"Apache-2.0"
] | null | null | null | ds1307/ds1307.c | tfateba/drivers | 5d66b17d402ca75ff5fd486bee83315643ccdf0a | [
"Apache-2.0"
] | null | null | null | ds1307/ds1307.c | tfateba/drivers | 5d66b17d402ca75ff5fd486bee83315643ccdf0a | [
"Apache-2.0"
] | null | null | null | /**
*
* @file ds1307.c
*
* @brief Real time clock driver source file.
*
* @author Theodore Ateba, tf.ateba@gmail.com
*
* @date 21 June 2015
*
*/
/*==========================================================================*/
/* Include files. */
/*==========================================================================*/
/* Drivers files. */
#include "ds1307.h"
#include "iic.h"
/*==========================================================================*/
/* Configuration structure. */
/*==========================================================================*/
/**
* @brief I2C Configuration structure
*/
static const I2CConfig i2cConfig = {
OPMODE_I2C, /**< I2C Operation mode. */
400000, /**< I2C Clock speed. */
FAST_DUTY_CYCLE_2, /**< I2C Duty cycle mode. */
};
/*==========================================================================*/
/* Driver functions. */
/*==========================================================================*/
/**
* @brief Convert BCD to Decimal.
*
* @param[in] val value to convert from BCD to Decimal
* @return res converted decimal value
*/
uint8_t bcd2Dec(uint8_t val) {
uint8_t res = ((val/16*10) + (val % 16));
return res;
}
/**
* @brief Convert Decimal to BCD.
*
* @param[in] val value to convert from Decimal to BCD
* @return res converted BCD value
*/
uint8_t dec2Bcd(uint8_t val) {
uint8_t res = ((val/10*16) + (val%10));
return res;
}
/* TODO: This function must me remove. */
/**
* @brief Send data to the Serial Driver 2.
*
* @param[in] p pointer of data to print
*/
void print(char *dp) {
while (*dp)
sdPut(&SD2, *dp++);
}
/* TODO: This function must also be removed. */
/**
* @brief Print integer to serial driver 2.
*
* @param[in] number integer to print to the serial console
*/
void printn(int16_t number) {
char buf[16], *p;
if (!number)
sdPut(&SD2, '0');
else {
p = buf;
while (number)
*p++ = (number % 10) + '0', number /= 10;
while (p > buf)
sdPut (&SD2, *--p);
}
}
/**
* @brief Configure the I2C Interface 1 and start the Interface.
*/
void ds1307InitInterface(void) {
i2cStart(&I2CD1, &i2cConfig);
palSetPadMode(GPIOB, 8, PAL_MODE_ALTERNATE(4) |
PAL_STM32_OTYPE_OPENDRAIN); /* SCL. */
palSetPadMode(GPIOB, 9, PAL_MODE_ALTERNATE(4) |
PAL_STM32_OTYPE_OPENDRAIN); /* SDA. */
}
/**
* @brief Set the clock and the calendar of the RTC.
*
* @param[in] rtcp pointer to the rtc device
*/
void ds1307SetClock(rtcDriver_t *rtcp) {
msg_t msg;
rtcp->txbuf[0] = DS1307_SECONDS_REG;
rtcp->txbuf[1] = dec2Bcd(rtcp->rtc.seconds);
rtcp->txbuf[2] = dec2Bcd(rtcp->rtc.minutes);
rtcp->txbuf[3] = dec2Bcd(rtcp->rtc.hours);
rtcp->txbuf[4] = dec2Bcd(rtcp->rtc.day);
rtcp->txbuf[5] = dec2Bcd(rtcp->rtc.date);
rtcp->txbuf[6] = dec2Bcd(rtcp->rtc.month);
rtcp->txbuf[7] = dec2Bcd(rtcp->rtc.year - rtcp->refYear);
msg = i2cWriteRegisters(&I2CD1, DS1307_ADDRESS, rtcp->txbuf,
DS1307_MAX_DATA_SIZE);
if (msg != MSG_OK)
print("\n\r Error when setting the DS1307 date over the I2C bus.");
else
print("\n\r DS1307 was setting succefuly.");
}
/* TODO: This function must be removed from here. */
/**
* @brief Print the clock and date read from the DS1307 RTC.
*
* @param[in] calendar structure contening the data to print
*/
void ds1307PrintClock(rtcDriver_t *rtcp) {
print("\n\r");
printn(rtcp->rtc.date);
print("/");
printn( rtcp->rtc.month);
print("/");
printn(rtcp->rtc.year);
print(" ");
printn(rtcp->rtc.hours);
print(":");
printn(rtcp->rtc.minutes);
print(":");
printn(rtcp->rtc.seconds);
}
/**
* @brief Get Clock and Calendar.
*
* @param[out] rtcp pointer to the RTC driver module
*/
void ds1307GetClock(rtcDriver_t *rtcp) {
msg_t msg;
rtcp->txbuf[0] = DS1307_SECONDS_REG; /* Register address of the Seconds. */
msg = i2cReadRegisters(&I2CD1, DS1307_ADDRESS, rtcp->txbuf, rtcp->rxbuf,
DS1307_MAX_DATA_SIZE - 1);
if (msg != MSG_OK) {
rtcp->errors = i2cGetErrors(&I2CD1);
print("\n\r I2C transmission error!");
}
else {
rtcp->rtc.seconds = bcd2Dec(rtcp->rxbuf[0] & 0x7F);
rtcp->rtc.minutes = bcd2Dec(rtcp->rxbuf[1]);
rtcp->rtc.hours = bcd2Dec(rtcp->rxbuf[2] & 0x3F );
rtcp->rtc.day = bcd2Dec(rtcp->rxbuf[3]);
rtcp->rtc.date = bcd2Dec(rtcp->rxbuf[4]);
rtcp->rtc.month = bcd2Dec(rtcp->rxbuf[5]);
rtcp->rtc.year = bcd2Dec(rtcp->rxbuf[6]) + rtcp->refYear;
}
}
| 25.873016 | 78 | 0.51636 |
c582c1e674802e730ed65358a152eae4eeaac53a | 2,731 | h | C | Platform/OSX/Frameworks/OgreDebug.framework/Versions/A/Headers/OgreStableHeaders.h | unconed/NFSpace | bbd544afb32a10bc4ee497e1d58cefe4bbbe7953 | [
"BSD-3-Clause"
] | 91 | 2015-01-19T11:03:56.000Z | 2022-03-12T15:54:06.000Z | Platform/OSX/Frameworks/OgreDebug.framework/Versions/A/Headers/OgreStableHeaders.h | unconed/NFSpace | bbd544afb32a10bc4ee497e1d58cefe4bbbe7953 | [
"BSD-3-Clause"
] | null | null | null | Platform/OSX/Frameworks/OgreDebug.framework/Versions/A/Headers/OgreStableHeaders.h | unconed/NFSpace | bbd544afb32a10bc4ee497e1d58cefe4bbbe7953 | [
"BSD-3-Clause"
] | 9 | 2015-03-16T03:36:50.000Z | 2021-06-17T09:47:26.000Z | /*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2006 Torus Knot Software Ltd
Also see acknowledgements in Readme.html
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
http://www.gnu.org/copyleft/lesser.txt.
You may alternatively use this source under the terms of a specific version of
the OGRE Unrestricted License provided you have obtained such a license from
Torus Knot Software Ltd.
-----------------------------------------------------------------------------
*/
/* Stable headers which will be used for precompilation if the compiler
supports it. Add entries here when headers are unlikely to change.
NB: a change to any of these headers will result in a full rebuild,
so don't add things to this lightly.
*/
#ifndef __OgreStableHeaders__
#define __OgreStableHeaders__
#include "OgrePlatform.h"
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_APPLE
#include "OgreArchive.h"
#include "OgreAxisAlignedBox.h"
#include "OgreBitwise.h"
#include "OgreCamera.h"
#include "OgreColourValue.h"
#include "OgreCommon.h"
#include "OgreDataStream.h"
#include "OgreException.h"
#include "OgreFileSystem.h"
#include "OgreLog.h"
#include "OgreMath.h"
#include "OgreMatrix3.h"
#include "OgreMatrix4.h"
#include "OgreMovableObject.h"
#include "OgreNode.h"
#include "OgrePlane.h"
#include "OgrePrerequisites.h"
#include "OgreQuaternion.h"
#include "OgreResource.h"
#include "OgreSerializer.h"
#include "OgreSharedPtr.h"
#include "OgreSimpleRenderable.h"
#include "OgreSimpleSpline.h"
#include "OgreSingleton.h"
#include "OgreSphere.h"
#include "OgreStdHeaders.h"
#include "OgreString.h"
#include "OgreStringConverter.h"
#include "OgreStringInterface.h"
#include "OgreStringVector.h"
#include "OgreUserDefinedObject.h"
#include "OgreVector2.h"
#include "OgreVector3.h"
#include "OgreVector4.h"
#include "OgreWireBoundingBox.h"
#include "OgreZip.h"
#endif
#endif
| 33.716049 | 85 | 0.738557 |
309d1c20e055e44a892fd9f180426b193f10719d | 162 | h | C | Example/Pods/Target Support Files/Pods-FlightKit_Tests/Pods-FlightKit_Tests-umbrella.h | nderkach/FlightKit | ea84778d5c116a5ddab82f7782ca95777cc6b9ef | [
"MIT"
] | null | null | null | Example/Pods/Target Support Files/Pods-FlightKit_Tests/Pods-FlightKit_Tests-umbrella.h | nderkach/FlightKit | ea84778d5c116a5ddab82f7782ca95777cc6b9ef | [
"MIT"
] | null | null | null | Example/Pods/Target Support Files/Pods-FlightKit_Tests/Pods-FlightKit_Tests-umbrella.h | nderkach/FlightKit | ea84778d5c116a5ddab82f7782ca95777cc6b9ef | [
"MIT"
] | null | null | null | #import <UIKit/UIKit.h>
FOUNDATION_EXPORT double Pods_FlightKit_TestsVersionNumber;
FOUNDATION_EXPORT const unsigned char Pods_FlightKit_TestsVersionString[];
| 23.142857 | 74 | 0.864198 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.