1 /**********************************************************************
3 * This file contains the routines related to Leaky Bucket Algorithm.
4 ***********************************************************************/
7 /*********************************************************************
8 * Function - UpdateTokenCount()
10 * Description - This function calculates the token count for each
11 * channel and updates the same in Adapter strucuture.
13 * Parameters - Adapter: Pointer to the Adapter structure.
16 **********************************************************************/
18 static VOID
UpdateTokenCount(register PMINI_ADAPTER Adapter
)
24 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
, TOKEN_COUNTS
, DBG_LVL_ALL
, "=====>\n");
27 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
, TOKEN_COUNTS
, DBG_LVL_ALL
, "Adapter found NULL!\n");
32 for(i
= 0; i
< NO_OF_QUEUES
; i
++)
34 if(TRUE
== Adapter
->PackInfo
[i
].bValid
&&
35 (1 == Adapter
->PackInfo
[i
].ucDirection
))
37 liCurrentTime
= ((tv
.tv_sec
-
38 Adapter
->PackInfo
[i
].stLastUpdateTokenAt
.tv_sec
)*1000 +
39 (tv
.tv_usec
-Adapter
->PackInfo
[i
].stLastUpdateTokenAt
.tv_usec
)/
43 Adapter
->PackInfo
[i
].uiCurrentTokenCount
+= (ULONG
)
44 ((Adapter
->PackInfo
[i
].uiMaxAllowedRate
) *
45 ((ULONG
)((liCurrentTime
)))/1000);
46 memcpy(&Adapter
->PackInfo
[i
].stLastUpdateTokenAt
,
47 &tv
, sizeof(struct timeval
));
48 Adapter
->PackInfo
[i
].liLastUpdateTokenAt
= liCurrentTime
;
49 if((Adapter
->PackInfo
[i
].uiCurrentTokenCount
) >=
50 Adapter
->PackInfo
[i
].uiMaxBucketSize
)
52 Adapter
->PackInfo
[i
].uiCurrentTokenCount
=
53 Adapter
->PackInfo
[i
].uiMaxBucketSize
;
58 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
, TOKEN_COUNTS
, DBG_LVL_ALL
, "<=====\n");
64 /*********************************************************************
65 * Function - IsPacketAllowedForFlow()
67 * Description - This function checks whether the given packet from the
68 * specified queue can be allowed for transmission by
69 * checking the token count.
71 * Parameters - Adapter : Pointer to the Adpater structure.
72 * - iQIndex : The queue Identifier.
73 * - ulPacketLength: Number of bytes to be transmitted.
75 * Returns - The number of bytes allowed for transmission.
77 ***********************************************************************/
78 static ULONG
GetSFTokenCount(PMINI_ADAPTER Adapter
, PacketInfo
*psSF
)
80 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
, TOKEN_COUNTS
, DBG_LVL_ALL
, "IsPacketAllowedForFlow ===>");
81 /* Validate the parameters */
82 if(NULL
== Adapter
|| (psSF
< Adapter
->PackInfo
&&
83 (uintptr_t)psSF
> (uintptr_t) &Adapter
->PackInfo
[HiPriority
]))
85 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
, TOKEN_COUNTS
, DBG_LVL_ALL
, "IPAFF: Got wrong Parameters:Adapter: %p, QIndex: %zd\n", Adapter
, (psSF
-Adapter
->PackInfo
));
89 if(FALSE
!= psSF
->bValid
&& psSF
->ucDirection
)
91 if(0 != psSF
->uiCurrentTokenCount
)
93 return psSF
->uiCurrentTokenCount
;
97 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
, TOKEN_COUNTS
, DBG_LVL_ALL
, "Not enough tokens in queue %zd Available %u\n",
98 psSF
-Adapter
->PackInfo
, psSF
->uiCurrentTokenCount
);
99 psSF
->uiPendedLast
= 1;
104 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
, TOKEN_COUNTS
, DBG_LVL_ALL
, "IPAFF: Queue %zd not valid\n", psSF
-Adapter
->PackInfo
);
106 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
, TOKEN_COUNTS
, DBG_LVL_ALL
, "IsPacketAllowedForFlow <===");
111 @ingroup tx_functions
112 This function despatches packet from the specified queue.
113 @return Zero(success) or Negative value(failure)
115 static INT
SendPacketFromQueue(PMINI_ADAPTER Adapter
,/**<Logical Adapter*/
116 PacketInfo
*psSF
, /**<Queue identifier*/
117 struct sk_buff
* Packet
) /**<Pointer to the packet to be sent*/
119 INT Status
=STATUS_FAILURE
;
120 UINT uiIndex
=0,PktLen
= 0;
122 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
, SEND_QUEUE
, DBG_LVL_ALL
, "=====>");
123 if(!Adapter
|| !Packet
|| !psSF
)
125 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
, SEND_QUEUE
, DBG_LVL_ALL
, "Got NULL Adapter or Packet");
129 if(psSF
->liDrainCalculated
==0)
131 psSF
->liDrainCalculated
= jiffies
;
133 ///send the packet to the fifo..
134 PktLen
= Packet
->len
;
135 Status
= SetupNextSend(Adapter
, Packet
, psSF
->usVCID_Value
);
138 for(uiIndex
= 0 ; uiIndex
< MIBS_MAX_HIST_ENTRIES
; uiIndex
++)
139 { if((PktLen
<= MIBS_PKTSIZEHIST_RANGE
*(uiIndex
+1)) && (PktLen
> MIBS_PKTSIZEHIST_RANGE
*(uiIndex
)))
140 Adapter
->aTxPktSizeHist
[uiIndex
]++;
143 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
, SEND_QUEUE
, DBG_LVL_ALL
, "<=====");
147 /************************************************************************
148 * Function - CheckAndSendPacketFromIndex()
150 * Description - This function dequeues the data/control packet from the
151 * specified queue for transmission.
153 * Parameters - Adapter : Pointer to the driver control structure.
154 * - iQIndex : The queue Identifier.
158 ****************************************************************************/
159 static VOID
CheckAndSendPacketFromIndex(PMINI_ADAPTER Adapter
, PacketInfo
*psSF
)
161 struct sk_buff
*QueuePacket
=NULL
;
162 char *pControlPacket
= NULL
;
167 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
, TX_PACKETS
, DBG_LVL_ALL
, "%zd ====>", (psSF
-Adapter
->PackInfo
));
168 if((psSF
!= &Adapter
->PackInfo
[HiPriority
]) && Adapter
->LinkUpStatus
&& atomic_read(&psSF
->uiPerSFTxResourceCount
))//Get data packet
170 if(!psSF
->ucDirection
)
173 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
, TX_PACKETS
, DBG_LVL_ALL
, "UpdateTokenCount ");
174 if(Adapter
->IdleMode
|| Adapter
->bPreparingForLowPowerMode
)
175 return; /* in idle mode */
177 // Check for Free Descriptors
178 if(atomic_read(&Adapter
->CurrNumFreeTxDesc
) <= MINIMUM_PENDING_DESCRIPTORS
)
180 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
, TX_PACKETS
, DBG_LVL_ALL
, " No Free Tx Descriptor(%d) is available for Data pkt..",atomic_read(&Adapter
->CurrNumFreeTxDesc
));
184 spin_lock_bh(&psSF
->SFQueueLock
);
185 QueuePacket
=psSF
->FirstTxQueue
;
189 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
, TX_PACKETS
, DBG_LVL_ALL
, "Dequeuing Data Packet");
191 if(psSF
->bEthCSSupport
)
192 iPacketLen
= QueuePacket
->len
;
194 iPacketLen
= QueuePacket
->len
-ETH_HLEN
;
197 if(iPacketLen
<= GetSFTokenCount(Adapter
, psSF
))
199 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
, TX_PACKETS
, DBG_LVL_ALL
, "Allowed bytes %d",
202 DEQUEUEPACKET(psSF
->FirstTxQueue
,psSF
->LastTxQueue
);
203 psSF
->uiCurrentBytesOnHost
-= (QueuePacket
->len
);
204 psSF
->uiCurrentPacketsOnHost
--;
205 atomic_dec(&Adapter
->TotalPacketCount
);
206 spin_unlock_bh(&psSF
->SFQueueLock
);
208 Status
= SendPacketFromQueue(Adapter
, psSF
, QueuePacket
);
209 psSF
->uiPendedLast
= FALSE
;
213 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
, TX_PACKETS
, DBG_LVL_ALL
, "For Queue: %zd\n", psSF
-Adapter
->PackInfo
);
214 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
, TX_PACKETS
, DBG_LVL_ALL
, "\nAvailable Tokens = %d required = %d\n",
215 psSF
->uiCurrentTokenCount
, iPacketLen
);
216 //this part indicates that because of non-availability of the tokens
217 //pkt has not been send out hence setting the pending flag indicating the host to send it out
218 //first next iteration .
219 psSF
->uiPendedLast
= TRUE
;
220 spin_unlock_bh(&psSF
->SFQueueLock
);
225 spin_unlock_bh(&psSF
->SFQueueLock
);
231 if((atomic_read(&Adapter
->CurrNumFreeTxDesc
) > 0 ) &&
232 (atomic_read(&Adapter
->index_rd_txcntrlpkt
) !=
233 atomic_read(&Adapter
->index_wr_txcntrlpkt
))
236 pControlPacket
= Adapter
->txctlpacket
237 [(atomic_read(&Adapter
->index_rd_txcntrlpkt
)%MAX_CNTRL_PKTS
)];
240 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
, TX_PACKETS
, DBG_LVL_ALL
, "Sending Control packet");
241 Status
= SendControlPacket(Adapter
, pControlPacket
);
242 if(STATUS_SUCCESS
==Status
)
244 spin_lock_bh(&psSF
->SFQueueLock
);
245 psSF
->NumOfPacketsSent
++;
246 psSF
->uiSentBytes
+=((PLEADER
)pControlPacket
)->PLength
;
247 psSF
->uiSentPackets
++;
248 atomic_dec(&Adapter
->TotalPacketCount
);
249 psSF
->uiCurrentBytesOnHost
-= ((PLEADER
)pControlPacket
)->PLength
;
250 psSF
->uiCurrentPacketsOnHost
--;
251 atomic_inc(&Adapter
->index_rd_txcntrlpkt
);
252 spin_unlock_bh(&psSF
->SFQueueLock
);
255 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
, TX_PACKETS
, DBG_LVL_ALL
, "SendControlPacket Failed\n");
259 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
, TX_PACKETS
, DBG_LVL_ALL
, " Control Pkt is not available, Indexing is wrong....");
266 /*******************************************************************
267 * Function - transmit_packets()
269 * Description - This function transmits the packets from different
270 * queues, if free descriptors are available on target.
272 * Parameters - Adapter: Pointer to the Adapter structure.
275 ********************************************************************/
276 VOID
transmit_packets(PMINI_ADAPTER Adapter
)
278 UINT uiPrevTotalCount
= 0;
281 BOOLEAN exit_flag
= TRUE
;
283 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
, TX_PACKETS
, DBG_LVL_ALL
, "=====>");
287 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
,TX_PACKETS
, DBG_LVL_ALL
, "Got NULL Adapter");
290 if(Adapter
->device_removed
== TRUE
)
292 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
, TX_PACKETS
, DBG_LVL_ALL
, "Device removed");
296 BCM_DEBUG_PRINT (Adapter
, DBG_TYPE_TX
, TX_PACKETS
, DBG_LVL_ALL
, "\nUpdateTokenCount ====>\n");
298 UpdateTokenCount(Adapter
);
300 BCM_DEBUG_PRINT (Adapter
, DBG_TYPE_TX
, TX_PACKETS
, DBG_LVL_ALL
, "\nPruneQueueAllSF ====>\n");
302 PruneQueueAllSF(Adapter
);
304 uiPrevTotalCount
= atomic_read(&Adapter
->TotalPacketCount
);
306 for(iIndex
=HiPriority
;iIndex
>=0;iIndex
--)
308 if( !uiPrevTotalCount
|| (TRUE
== Adapter
->device_removed
))
311 if(Adapter
->PackInfo
[iIndex
].bValid
&&
312 Adapter
->PackInfo
[iIndex
].uiPendedLast
&&
313 Adapter
->PackInfo
[iIndex
].uiCurrentBytesOnHost
)
315 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
, TX_PACKETS
, DBG_LVL_ALL
, "Calling CheckAndSendPacketFromIndex..");
316 CheckAndSendPacketFromIndex(Adapter
, &Adapter
->PackInfo
[iIndex
]);
321 while(uiPrevTotalCount
> 0 && !Adapter
->device_removed
)
324 //second iteration to parse non-pending queues
325 for(iIndex
=HiPriority
;iIndex
>=0;iIndex
--)
327 if( !uiPrevTotalCount
|| (TRUE
== Adapter
->device_removed
))
330 if(Adapter
->PackInfo
[iIndex
].bValid
&&
331 Adapter
->PackInfo
[iIndex
].uiCurrentBytesOnHost
&&
332 !Adapter
->PackInfo
[iIndex
].uiPendedLast
)
334 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
, TX_PACKETS
, DBG_LVL_ALL
, "Calling CheckAndSendPacketFromIndex..");
335 CheckAndSendPacketFromIndex(Adapter
, &Adapter
->PackInfo
[iIndex
]);
341 if(Adapter
->IdleMode
|| Adapter
->bPreparingForLowPowerMode
)
343 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
, TX_PACKETS
, DBG_LVL_ALL
, "In Idle Mode\n");
346 if(exit_flag
== TRUE
)
348 }/* end of inner while loop */
350 update_per_cid_rx (Adapter
);
351 Adapter
->txtransmit_running
= 0;
352 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
, TX_PACKETS
, DBG_LVL_ALL
, "<======");