wlan_bearer/wlanldd/wlan_common/umac_common/inc/umacpacketscheduler.h
changeset 0 c40eb8fe8501
equal deleted inserted replaced
-1:000000000000 0:c40eb8fe8501
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   Declaration of the WlanPacketScheduler class.
       
    15 *
       
    16 */
       
    17 
       
    18 /*
       
    19 * %version: 21 %
       
    20 */
       
    21 
       
    22 #ifndef T_WLANPACKETSCHEDULER_H
       
    23 #define T_WLANPACKETSCHEDULER_H
       
    24 
       
    25 #ifndef RD_WLAN_DDK
       
    26 #include <wha.h>
       
    27 #else
       
    28 #include <wlanwha.h>
       
    29 #endif
       
    30 
       
    31 #include "802dot11.h"
       
    32 
       
    33 #include "umaccarray.h"
       
    34 
       
    35 class MWlanPacketSchedulerClient;
       
    36 class WlanContextImpl;
       
    37 class TDataBuffer;
       
    38 
       
    39 /**
       
    40  *  802.11 Packet scheduler
       
    41  *  When packet transmit is possible the packets are transmitted 
       
    42  *  in the priority order 
       
    43  *
       
    44  *  @lib wlanumac.lib
       
    45  *  @since S60 v3.1
       
    46  */
       
    47 class WlanPacketScheduler
       
    48     {
       
    49     // stores context information about a packet
       
    50     struct SPacketIdCntx
       
    51         {
       
    52         // free or not
       
    53         TBool           iFree;
       
    54         // id of the send queue
       
    55         WHA::TQueueId   iQueueId;
       
    56         // frame id used by the packet scheduler client
       
    57         TUint32         iFrameId;
       
    58         // frame meta header used by the packet scheduler client
       
    59         const TDataBuffer* iMetaHeader;
       
    60         // requested Tx rate
       
    61         WHA::TRate      iRequestedTxRate;
       
    62         // ETrue if this is a multicast data frame
       
    63         TBool           iMulticastData;
       
    64         // time when the packet transmit request was submitted to WHA layer
       
    65         TInt64          iSendReqTimeStamp;
       
    66         // ETrue if the use of the special rate policy is requested for the
       
    67         // transmission of this frame
       
    68         TBool           iUseSpecialRatePolicy;
       
    69         };
       
    70 
       
    71     struct SElement
       
    72         {
       
    73         // free or not
       
    74         TBool           iFree;
       
    75         // start of packet buffer to send
       
    76         const TAny*     iPacket;
       
    77         // length of the packet buffer to send
       
    78         TUint32         iLength;
       
    79         // link to packet id context
       
    80         SPacketIdCntx*  iPacketIdCntx;
       
    81         };
       
    82 
       
    83     class TPacketIdCntxsPredicate
       
    84         {
       
    85         public:
       
    86 
       
    87             TPacketIdCntxsPredicate() : iKey( ETrue ) {};
       
    88 
       
    89             TBool operator() ( const SPacketIdCntx& aEntry ) const
       
    90                 {
       
    91                 return aEntry.iFree == iKey;
       
    92                 }
       
    93 
       
    94         private:
       
    95 
       
    96             // Prohibit copy constructor.
       
    97             TPacketIdCntxsPredicate( const TPacketIdCntxsPredicate& );
       
    98             // Prohibit assigment operator.
       
    99             TPacketIdCntxsPredicate& operator= ( const TPacketIdCntxsPredicate& );
       
   100 
       
   101             const TBool iKey;
       
   102         };
       
   103 
       
   104     class TElementPredicate
       
   105         {
       
   106         public:
       
   107 
       
   108             TElementPredicate() : iKey( ETrue ) {};
       
   109             explicit TElementPredicate( TBool aKey ) : iKey( aKey ) {};
       
   110 
       
   111             TBool operator() ( const SElement& aEntry ) const
       
   112                 {
       
   113                 return aEntry.iFree == iKey;
       
   114                 }
       
   115 
       
   116         private:
       
   117 
       
   118             // Prohibit copy constructor.
       
   119             TElementPredicate( const TElementPredicate& );
       
   120             // Prohibit assigment operator.
       
   121             TElementPredicate& operator= ( const TElementPredicate& );
       
   122 
       
   123             const TBool iKey;
       
   124         };
       
   125 
       
   126     /**
       
   127      * max number of packet IDs existing any given time
       
   128      */
       
   129     static const TUint32   KMaxNumOfPacketIds = 60;
       
   130     
       
   131     /**
       
   132      * storage type for packet ID contexes
       
   133      */
       
   134     typedef Carray<
       
   135         SPacketIdCntx, 
       
   136         KMaxNumOfPacketIds, 
       
   137         EFalse,                 // no delete pointees
       
   138         NoCopy<SPacketIdCntx>   // disallow copying
       
   139         > TPacketIdCntxs;
       
   140     
       
   141     /**
       
   142      * number of packets supported in the storage
       
   143      * (4 user data - 1 per AC, 1 Wlan Mgmt Client and 1 internal packet)
       
   144      */
       
   145     static const TUint32   KNumOfElements = 6;
       
   146     
       
   147     /**
       
   148      * storage type for packet contexts
       
   149      */
       
   150     typedef Carray<
       
   151         SElement, 
       
   152         KNumOfElements, 
       
   153         EFalse,             // no delete pointees
       
   154         NoCopy<SElement>    // disallow copying
       
   155         > TPacketElements;
       
   156     
       
   157     /**
       
   158      * state of the transmit queue
       
   159      */
       
   160     enum TQueueState
       
   161         {
       
   162         EQueueFull,
       
   163         EQueueNotFull
       
   164         };
       
   165     
       
   166     /**
       
   167      * mapper for transmit queue state
       
   168      */
       
   169     typedef Carray<
       
   170         TQueueState, 
       
   171         WHA::EQueueIdMax, 
       
   172         EFalse,             // no delete pointees
       
   173         NoCopy<TQueueState> // disallow copying
       
   174         > TQueueStates;
       
   175 
       
   176 public:
       
   177 
       
   178     /**
       
   179      * Constructor.
       
   180      *
       
   181      * @since S60 3.1
       
   182      * @param aWlanPacketSchedulerClient reference to Packet Scheduler Client
       
   183      */
       
   184     explicit WlanPacketScheduler( 
       
   185         MWlanPacketSchedulerClient& aWlanPacketSchedulerClient );
       
   186 
       
   187     /**
       
   188      * Pushes a packet to be sent to storage.
       
   189      * NOTE: if no space is available in the storage the operation fails
       
   190      * and packet scheduler informs the client by using a method call
       
   191      * when it should call this method again
       
   192      *
       
   193      * @since S60 3.1
       
   194      * @param aCtxImpl the one and only global state machine context
       
   195      * @param aPacket the packet to transmit
       
   196      * @param aLength length of the packet
       
   197      * @param aQueueId id of the queue to use when sending the packet
       
   198      * @param aPacketId frame type
       
   199      * @param aMetaHeader frame meta header
       
   200      * @param aMore ETrue if another frame is also ready to be transmitted
       
   201      *              EFalse otherwise
       
   202      * @param aMulticastData ETrue if this is a multicast data frame
       
   203      * @param aUseSpecialRatePolicy ETrue if use of the special Tx rate
       
   204      *        policy is requested for this frame Tx
       
   205      * @return ETrue packet was accepted, EFalse otherwise
       
   206      */
       
   207     TBool Push( 
       
   208         WlanContextImpl& aCtxImpl,
       
   209         const TAny* aPacket, 
       
   210         TUint32 aLength, 
       
   211         WHA::TQueueId aQueueId,
       
   212         TUint32 aPacketId,
       
   213         const TDataBuffer* aMetaHeader,
       
   214         TBool aMore,
       
   215         TBool aMulticastData,
       
   216         TBool aUseSpecialRatePolicy );
       
   217 
       
   218     /**
       
   219      * Removes all pending packet transmission entrys 
       
   220      * meaning the scheduler is empty after this call
       
   221      *
       
   222      * @since S60 3.1
       
   223      * @param aCtxImpl the one and only global state machine context
       
   224      */
       
   225     void Flush( WlanContextImpl& aCtxImpl );
       
   226 
       
   227     /**
       
   228      * Schedules a packet and sends it if possible.
       
   229      * If no packets to schedule exist, does nothing
       
   230      * If packet is sent, it is removed from the storage
       
   231      *
       
   232      * @since S60 3.1
       
   233      * @param aCtxImpl the one and only global state machine context
       
   234      * @param aMore ETrue if another frame is also ready to be transmitted
       
   235      *              EFalse otherwise
       
   236      */
       
   237     void SchedulePackets( WlanContextImpl& aCtxImpl, TBool aMore );
       
   238 
       
   239     /**
       
   240      * Packet transfer event
       
   241      *
       
   242      * @since S60 3.1
       
   243      * @param aCtxImpl the one and only global state machine context
       
   244      */
       
   245     void SendPacketTransfer( 
       
   246         WlanContextImpl& aCtxImpl, 
       
   247         WHA::TPacketId aPacketId );
       
   248 
       
   249     /**
       
   250      * Packet processed from WLAN device transmit queue event
       
   251      *
       
   252      * @since S60 3.1
       
   253      * @param aCtxImpl the one and only global state machine context
       
   254      */
       
   255     void SendPacketComplete(
       
   256         WlanContextImpl& aCtxImpl, 
       
   257         WHA::TStatus aStatus,
       
   258         WHA::TPacketId aPacketId,
       
   259         WHA::TRate aRate,
       
   260         TUint32 aPacketQueueDelay,
       
   261         TUint32 aMediaDelay,        
       
   262         TUint8 aAckFailures );
       
   263 
       
   264     /**
       
   265      * Gets WHA layer transmission status
       
   266      *
       
   267      * @param aCtxImpl the one and only global state machine context
       
   268      * @param aTxQueueState State (full / not full) of every WHA transmit queue
       
   269      * @return ETrue if the Tx pipeline is active, i.e. Tx frame submission
       
   270      *         is allowed
       
   271      *         EFalse if the Tx pipeline is not active, i.e. Tx frame submission
       
   272      *         is not allowed
       
   273      */
       
   274     TBool GetWhaTxStatus(
       
   275         const WlanContextImpl& aCtxImpl, 
       
   276         TWhaTxQueueState& aTxQueueState ) const;
       
   277     
       
   278     /**
       
   279      * Are there unsent Tx packets, i.e. packets not yet completed by WHA 
       
   280      * layer
       
   281      *
       
   282      * @since S60 3.2
       
   283      * @return ETrue if there are packets not yet completed by WHA layer
       
   284      *         EFalse otherwise
       
   285      */
       
   286     inline TBool UnsentPackets() const;
       
   287 
       
   288 private:
       
   289 
       
   290     // Prohibit copy constructor 
       
   291     WlanPacketScheduler( const WlanPacketScheduler& );
       
   292     // Prohibit assigment operator 
       
   293     WlanPacketScheduler& operator= ( const WlanPacketScheduler& );  
       
   294 
       
   295     /**
       
   296      * Evalutes if multiple packets are ready for transmitting.
       
   297      * Checks does a packet exist in a non-full queue   
       
   298      *
       
   299      * @since S60 3.1
       
   300      * @return ETrue multiple packets ready for transmitting exists, 
       
   301      *         EFalse otherwise
       
   302      */
       
   303     TBool MultipleReadyPacketsPending();
       
   304 
       
   305     /**
       
   306      * Sets current packet pointer to point 
       
   307      * to next current packet if such exists
       
   308      *
       
   309      * @since S60 3.1
       
   310      */
       
   311     void SetNextCurrent();
       
   312 
       
   313     /**
       
   314      * Extracts a free element slot
       
   315      *
       
   316      * @since S60 3.1
       
   317      * @return free element slot, NULL upon failure
       
   318      */
       
   319     SElement* FreeElementSlot();
       
   320 
       
   321     /**
       
   322      * Extracts a free packet ID context
       
   323      *
       
   324      * @since S60 3.1
       
   325      * @return free packet ID context, NULL upon failure
       
   326      */
       
   327     SPacketIdCntx* FreePacketIdCntx();
       
   328 
       
   329     /**
       
   330      * Sets the current packet pointer point to a new packet to be transmitted,
       
   331      * if one exists in a queue defined by supplied parameter.
       
   332      * This method is called after packet has been processed from WLAN device's
       
   333      * transmit queue. As the current packet pointer is always supposed to 
       
   334      * point to the highest priority packet that is in a non-full queue this 
       
   335      * method might or might not set the current packet pointer
       
   336      *
       
   337      * @since S60 3.1
       
   338      * @param aCompletedCntx    packet ID context of a packet processed from 
       
   339      *                          WLAN devices transmit queue
       
   340      */
       
   341     void SetCurrentPacket( const SPacketIdCntx& aCompletedCntx );
       
   342 
       
   343     /**
       
   344      * Sets the state of the tx pipeline to active
       
   345      *
       
   346      * @since S60 3.1
       
   347      * @param aQueueId id of the queue
       
   348      */
       
   349     inline void StartTxPipeLine();
       
   350 
       
   351     /**
       
   352      * Sets the state of the given queue to full
       
   353      *
       
   354      * @since S60 3.1
       
   355      * @param aQueueId id of the queue
       
   356      */
       
   357     inline void TranmsitQueueFull( WHA::TQueueId aQueueId );
       
   358 
       
   359     /**
       
   360      * Sets the state of the tx pipeline to stop
       
   361      *
       
   362      * @since S60 3.1
       
   363      * @param aQueueId id of the queue
       
   364      */
       
   365     inline void StopTxPipeLine();
       
   366 
       
   367     /**
       
   368      * Evaluates can the packet scheduler accept 
       
   369      * any more packets or is it full
       
   370      *
       
   371      * @since S60 3.1
       
   372      * @return ETrue if the scheduler is full 
       
   373      * and can not accept any more packets, EFalse otherwise
       
   374      */
       
   375     inline TBool Full() const;
       
   376     
       
   377     /**
       
   378      * Returns the priority of the provided WHA Queue
       
   379      *
       
   380      * @param aQueueId id of the WHA queue
       
   381      * @return Priority of the provided queue
       
   382      */
       
   383     static inline TUint Priority( WHA::TQueueId aQueueId );
       
   384 
       
   385 private: // data
       
   386 
       
   387     /**
       
   388      * this flag is set when we need to signal the Packet Scheduler client
       
   389      * when packet push is again possible
       
   390      */
       
   391     static const TUint32  KSignalPushPacket = (1 << 0);
       
   392 
       
   393     /**
       
   394      * packet scheduler client
       
   395      */
       
   396     MWlanPacketSchedulerClient& iPacketSchedulerClient;
       
   397     
       
   398     /**
       
   399      * points to highest priority packet of queue that is not full 
       
   400      */
       
   401     SElement*       iCurrent;
       
   402     /**
       
   403      * is tx pipeline active or stopped
       
   404      */
       
   405     TBool           iTxPipelineActive;
       
   406     /**
       
   407      * number of packets stored inside scheduler
       
   408      */
       
   409     TUint32         iNumOfPackets;
       
   410     /**
       
   411      * number of packets not yet completed by WHA layer
       
   412      */
       
   413     TUint32         iNumOfNotCompletedPackets;
       
   414     /**
       
   415      * packet ID contexts
       
   416      */    
       
   417     TPacketIdCntxs  iPacketIdCntxs;
       
   418     /**
       
   419      * packet contexts
       
   420      */    
       
   421     TPacketElements iPacketElements;
       
   422     /**
       
   423      * transmit queue states
       
   424      */
       
   425     TQueueStates    iQueueStates;   
       
   426     /**
       
   427      * holds internal state
       
   428      */    
       
   429     TUint32         iFlags;
       
   430     };
       
   431 
       
   432 #include "umacpacketscheduler.inl"
       
   433 
       
   434 
       
   435 #endif // T_WLANPACKETSCHEDULER_H