3 This file contains the routines related to Quality of Service.
7 static void EThCSGetPktInfo(struct bcm_mini_adapter *Adapter,
9 struct bcm_eth_packet_info *pstEthCsPktInfo);
11 static bool EThCSClassifyPkt(struct bcm_mini_adapter *Adapter,
13 struct bcm_eth_packet_info *pstEthCsPktInfo,
14 struct bcm_classifier_rule *pstClassifierRule,
15 B_UINT8 EthCSCupport);
17 static USHORT IpVersion4(struct bcm_mini_adapter *Adapter, struct iphdr *iphd,
18 struct bcm_classifier_rule *pstClassifierRule);
20 static VOID PruneQueue(struct bcm_mini_adapter *Adapter, INT iIndex);
23 /*******************************************************************
24 * Function - MatchSrcIpAddress()
26 * Description - Checks whether the Source IP address from the packet
27 * matches with that of Queue.
29 * Parameters - pstClassifierRule: Pointer to the packet info structure.
30 * - ulSrcIP : Source IP address from the packet.
32 * Returns - TRUE(If address matches) else FAIL .
33 *********************************************************************/
34 static bool MatchSrcIpAddress(struct bcm_classifier_rule *pstClassifierRule, ULONG ulSrcIP)
36 UCHAR ucLoopIndex = 0;
38 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
40 ulSrcIP = ntohl(ulSrcIP);
41 if (0 == pstClassifierRule->ucIPSourceAddressLength)
43 for (ucLoopIndex = 0; ucLoopIndex < (pstClassifierRule->ucIPSourceAddressLength); ucLoopIndex++) {
44 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "Src Ip Address Mask:0x%x PacketIp:0x%x and Classification:0x%x", (UINT)pstClassifierRule->stSrcIpAddress.ulIpv4Mask[ucLoopIndex], (UINT)ulSrcIP, (UINT)pstClassifierRule->stSrcIpAddress.ulIpv6Addr[ucLoopIndex]);
45 if ((pstClassifierRule->stSrcIpAddress.ulIpv4Mask[ucLoopIndex] & ulSrcIP) ==
46 (pstClassifierRule->stSrcIpAddress.ulIpv4Addr[ucLoopIndex] & pstClassifierRule->stSrcIpAddress.ulIpv4Mask[ucLoopIndex]))
49 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "Src Ip Address Not Matched");
54 /*******************************************************************
55 * Function - MatchDestIpAddress()
57 * Description - Checks whether the Destination IP address from the packet
58 * matches with that of Queue.
60 * Parameters - pstClassifierRule: Pointer to the packet info structure.
61 * - ulDestIP : Destination IP address from the packet.
63 * Returns - TRUE(If address matches) else FAIL .
64 *********************************************************************/
65 static bool MatchDestIpAddress(struct bcm_classifier_rule *pstClassifierRule, ULONG ulDestIP)
67 UCHAR ucLoopIndex = 0;
68 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
70 ulDestIP = ntohl(ulDestIP);
71 if (0 == pstClassifierRule->ucIPDestinationAddressLength)
73 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "Destination Ip Address 0x%x 0x%x 0x%x ", (UINT)ulDestIP, (UINT)pstClassifierRule->stDestIpAddress.ulIpv4Mask[ucLoopIndex], (UINT)pstClassifierRule->stDestIpAddress.ulIpv4Addr[ucLoopIndex]);
75 for (ucLoopIndex = 0; ucLoopIndex < (pstClassifierRule->ucIPDestinationAddressLength); ucLoopIndex++) {
76 if ((pstClassifierRule->stDestIpAddress.ulIpv4Mask[ucLoopIndex] & ulDestIP) ==
77 (pstClassifierRule->stDestIpAddress.ulIpv4Addr[ucLoopIndex] & pstClassifierRule->stDestIpAddress.ulIpv4Mask[ucLoopIndex]))
80 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "Destination Ip Address Not Matched");
85 /************************************************************************
86 * Function - MatchTos()
88 * Description - Checks the TOS from the packet matches with that of queue.
90 * Parameters - pstClassifierRule : Pointer to the packet info structure.
91 * - ucTypeOfService: TOS from the packet.
93 * Returns - TRUE(If address matches) else FAIL.
94 **************************************************************************/
95 static bool MatchTos(struct bcm_classifier_rule *pstClassifierRule, UCHAR ucTypeOfService)
98 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
99 if (3 != pstClassifierRule->ucIPTypeOfServiceLength)
102 if (((pstClassifierRule->ucTosMask & ucTypeOfService) <= pstClassifierRule->ucTosHigh) && ((pstClassifierRule->ucTosMask & ucTypeOfService) >= pstClassifierRule->ucTosLow))
105 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "Type Of Service Not Matched");
110 /***************************************************************************
111 * Function - MatchProtocol()
113 * Description - Checks the protocol from the packet matches with that of queue.
115 * Parameters - pstClassifierRule: Pointer to the packet info structure.
116 * - ucProtocol : Protocol from the packet.
118 * Returns - TRUE(If address matches) else FAIL.
119 ****************************************************************************/
120 bool MatchProtocol(struct bcm_classifier_rule *pstClassifierRule, UCHAR ucProtocol)
122 UCHAR ucLoopIndex = 0;
123 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
124 if (0 == pstClassifierRule->ucProtocolLength)
126 for (ucLoopIndex = 0; ucLoopIndex < pstClassifierRule->ucProtocolLength; ucLoopIndex++) {
127 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "Protocol:0x%X Classification Protocol:0x%X", ucProtocol, pstClassifierRule->ucProtocol[ucLoopIndex]);
128 if (pstClassifierRule->ucProtocol[ucLoopIndex] == ucProtocol)
131 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "Protocol Not Matched");
136 /***********************************************************************
137 * Function - MatchSrcPort()
139 * Description - Checks, Source port from the packet matches with that of queue.
141 * Parameters - pstClassifierRule: Pointer to the packet info structure.
142 * - ushSrcPort : Source port from the packet.
144 * Returns - TRUE(If address matches) else FAIL.
145 ***************************************************************************/
146 bool MatchSrcPort(struct bcm_classifier_rule *pstClassifierRule, USHORT ushSrcPort)
148 UCHAR ucLoopIndex = 0;
150 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
153 if (0 == pstClassifierRule->ucSrcPortRangeLength)
155 for (ucLoopIndex = 0; ucLoopIndex < pstClassifierRule->ucSrcPortRangeLength; ucLoopIndex++) {
156 if (ushSrcPort <= pstClassifierRule->usSrcPortRangeHi[ucLoopIndex] &&
157 ushSrcPort >= pstClassifierRule->usSrcPortRangeLo[ucLoopIndex])
160 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "Src Port: %x Not Matched ", ushSrcPort);
165 /***********************************************************************
166 * Function - MatchDestPort()
168 * Description - Checks, Destination port from packet matches with that of queue.
170 * Parameters - pstClassifierRule: Pointer to the packet info structure.
171 * - ushDestPort : Destination port from the packet.
173 * Returns - TRUE(If address matches) else FAIL.
174 ***************************************************************************/
175 bool MatchDestPort(struct bcm_classifier_rule *pstClassifierRule, USHORT ushDestPort)
177 UCHAR ucLoopIndex = 0;
178 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
180 if (0 == pstClassifierRule->ucDestPortRangeLength)
183 for (ucLoopIndex = 0; ucLoopIndex < pstClassifierRule->ucDestPortRangeLength; ucLoopIndex++) {
184 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "Matching Port:0x%X 0x%X 0x%X", ushDestPort, pstClassifierRule->usDestPortRangeLo[ucLoopIndex], pstClassifierRule->usDestPortRangeHi[ucLoopIndex]);
186 if (ushDestPort <= pstClassifierRule->usDestPortRangeHi[ucLoopIndex] &&
187 ushDestPort >= pstClassifierRule->usDestPortRangeLo[ucLoopIndex])
190 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "Dest Port: %x Not Matched", ushDestPort);
194 @ingroup tx_functions
195 Compares IPV4 Ip address and port number
198 static USHORT IpVersion4(struct bcm_mini_adapter *Adapter,
200 struct bcm_classifier_rule *pstClassifierRule)
202 struct bcm_transport_header *xprt_hdr = NULL;
203 bool bClassificationSucceed = false;
205 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "========>");
207 xprt_hdr = (struct bcm_transport_header *)((PUCHAR)iphd + sizeof(struct iphdr));
210 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "Trying to see Direction = %d %d",
211 pstClassifierRule->ucDirection,
212 pstClassifierRule->usVCID_Value);
214 //Checking classifier validity
215 if (!pstClassifierRule->bUsed || pstClassifierRule->ucDirection == DOWNLINK_DIR)
218 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "is IPv6 check!");
219 if (pstClassifierRule->bIpv6Protocol)
222 //**************Checking IP header parameter**************************//
223 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "Trying to match Source IP Address");
224 if (!MatchSrcIpAddress(pstClassifierRule, iphd->saddr))
226 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "Source IP Address Matched");
228 if (!MatchDestIpAddress(pstClassifierRule, iphd->daddr))
230 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "Destination IP Address Matched");
232 if (!MatchTos(pstClassifierRule, iphd->tos)) {
233 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "TOS Match failed\n");
236 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "TOS Matched");
238 if (!MatchProtocol(pstClassifierRule, iphd->protocol))
240 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "Protocol Matched");
242 //if protocol is not TCP or UDP then no need of comparing source port and destination port
243 if (iphd->protocol != TCP && iphd->protocol != UDP) {
244 bClassificationSucceed = TRUE;
247 //******************Checking Transport Layer Header field if present *****************//
248 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "Source Port %04x",
249 (iphd->protocol == UDP) ? xprt_hdr->uhdr.source : xprt_hdr->thdr.source);
251 if (!MatchSrcPort(pstClassifierRule,
252 ntohs((iphd->protocol == UDP) ?
253 xprt_hdr->uhdr.source : xprt_hdr->thdr.source)))
255 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "Src Port Matched");
257 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "Destination Port %04x",
258 (iphd->protocol == UDP) ? xprt_hdr->uhdr.dest :
259 xprt_hdr->thdr.dest);
260 if (!MatchDestPort(pstClassifierRule,
261 ntohs((iphd->protocol == UDP) ?
262 xprt_hdr->uhdr.dest : xprt_hdr->thdr.dest)))
264 bClassificationSucceed = TRUE;
267 if (TRUE == bClassificationSucceed) {
268 INT iMatchedSFQueueIndex = 0;
269 iMatchedSFQueueIndex = SearchSfid(Adapter, pstClassifierRule->ulSFID);
270 if (iMatchedSFQueueIndex >= NO_OF_QUEUES)
271 bClassificationSucceed = false;
272 else if (false == Adapter->PackInfo[iMatchedSFQueueIndex].bActive)
273 bClassificationSucceed = false;
276 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "IpVersion4 <==========");
278 return bClassificationSucceed;
281 VOID PruneQueueAllSF(struct bcm_mini_adapter *Adapter)
285 for (iIndex = 0; iIndex < HiPriority; iIndex++) {
286 if (!Adapter->PackInfo[iIndex].bValid)
289 PruneQueue(Adapter, iIndex);
295 @ingroup tx_functions
296 This function checks if the max queue size for a queue
297 is less than number of bytes in the queue. If so -
298 drops packets from the Head till the number of bytes is
299 less than or equal to max queue size for the queue.
301 static VOID PruneQueue(struct bcm_mini_adapter *Adapter, INT iIndex)
303 struct sk_buff* PacketToDrop = NULL;
304 struct net_device_stats *netstats;
306 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, PRUNE_QUEUE, DBG_LVL_ALL, "=====> Index %d", iIndex);
308 if (iIndex == HiPriority)
311 if (!Adapter || (iIndex < 0) || (iIndex > HiPriority))
314 /* To Store the netdevice statistic */
315 netstats = &Adapter->dev->stats;
317 spin_lock_bh(&Adapter->PackInfo[iIndex].SFQueueLock);
320 // while((UINT)Adapter->PackInfo[iIndex].uiCurrentPacketsOnHost >
321 // SF_MAX_ALLOWED_PACKETS_TO_BACKUP) {
323 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, PRUNE_QUEUE, DBG_LVL_ALL, "uiCurrentBytesOnHost:%x uiMaxBucketSize :%x",
324 Adapter->PackInfo[iIndex].uiCurrentBytesOnHost,
325 Adapter->PackInfo[iIndex].uiMaxBucketSize);
327 PacketToDrop = Adapter->PackInfo[iIndex].FirstTxQueue;
329 if (PacketToDrop == NULL)
331 if ((Adapter->PackInfo[iIndex].uiCurrentPacketsOnHost < SF_MAX_ALLOWED_PACKETS_TO_BACKUP) &&
332 ((1000*(jiffies - *((B_UINT32 *)(PacketToDrop->cb)+SKB_CB_LATENCY_OFFSET))/HZ) <= Adapter->PackInfo[iIndex].uiMaxLatency))
336 if (netif_msg_tx_err(Adapter))
337 pr_info(PFX "%s: tx queue %d overlimit\n",
338 Adapter->dev->name, iIndex);
340 netstats->tx_dropped++;
342 DEQUEUEPACKET(Adapter->PackInfo[iIndex].FirstTxQueue,
343 Adapter->PackInfo[iIndex].LastTxQueue);
344 /// update current bytes and packets count
345 Adapter->PackInfo[iIndex].uiCurrentBytesOnHost -=
347 Adapter->PackInfo[iIndex].uiCurrentPacketsOnHost--;
348 /// update dropped bytes and packets counts
349 Adapter->PackInfo[iIndex].uiDroppedCountBytes += PacketToDrop->len;
350 Adapter->PackInfo[iIndex].uiDroppedCountPackets++;
351 dev_kfree_skb(PacketToDrop);
355 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, PRUNE_QUEUE, DBG_LVL_ALL, "Dropped Bytes:%x Dropped Packets:%x",
356 Adapter->PackInfo[iIndex].uiDroppedCountBytes,
357 Adapter->PackInfo[iIndex].uiDroppedCountPackets);
359 atomic_dec(&Adapter->TotalPacketCount);
362 spin_unlock_bh(&Adapter->PackInfo[iIndex].SFQueueLock);
364 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, PRUNE_QUEUE, DBG_LVL_ALL, "TotalPacketCount:%x",
365 atomic_read(&Adapter->TotalPacketCount));
366 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, PRUNE_QUEUE, DBG_LVL_ALL, "<=====");
369 VOID flush_all_queues(struct bcm_mini_adapter *Adapter)
372 UINT uiTotalPacketLength;
373 struct sk_buff* PacketToDrop = NULL;
375 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "=====>");
377 // down(&Adapter->data_packet_queue_lock);
378 for (iQIndex = LowPriority; iQIndex < HiPriority; iQIndex++) {
379 struct net_device_stats *netstats = &Adapter->dev->stats;
381 spin_lock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
382 while (Adapter->PackInfo[iQIndex].FirstTxQueue) {
383 PacketToDrop = Adapter->PackInfo[iQIndex].FirstTxQueue;
385 uiTotalPacketLength = PacketToDrop->len;
386 netstats->tx_dropped++;
388 uiTotalPacketLength = 0;
390 DEQUEUEPACKET(Adapter->PackInfo[iQIndex].FirstTxQueue,
391 Adapter->PackInfo[iQIndex].LastTxQueue);
394 dev_kfree_skb(PacketToDrop);
396 /// update current bytes and packets count
397 Adapter->PackInfo[iQIndex].uiCurrentBytesOnHost -= uiTotalPacketLength;
398 Adapter->PackInfo[iQIndex].uiCurrentPacketsOnHost--;
400 /// update dropped bytes and packets counts
401 Adapter->PackInfo[iQIndex].uiDroppedCountBytes += uiTotalPacketLength;
402 Adapter->PackInfo[iQIndex].uiDroppedCountPackets++;
404 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Dropped Bytes:%x Dropped Packets:%x",
405 Adapter->PackInfo[iQIndex].uiDroppedCountBytes,
406 Adapter->PackInfo[iQIndex].uiDroppedCountPackets);
407 atomic_dec(&Adapter->TotalPacketCount);
409 spin_unlock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
411 // up(&Adapter->data_packet_queue_lock);
412 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "<=====");
415 USHORT ClassifyPacket(struct bcm_mini_adapter *Adapter, struct sk_buff* skb)
418 struct bcm_classifier_rule *pstClassifierRule = NULL;
419 struct bcm_eth_packet_info stEthCsPktInfo;
420 PVOID pvEThPayload = NULL;
421 struct iphdr *pIpHeader = NULL;
423 USHORT usIndex = Adapter->usBestEffortQueueIndex;
424 bool bFragmentedPkt = false, bClassificationSucceed = false;
425 USHORT usCurrFragment = 0;
427 struct bcm_tcp_header *pTcpHeader;
428 UCHAR IpHeaderLength;
429 UCHAR TcpHeaderLength;
431 pvEThPayload = skb->data;
432 *((UINT32*) (skb->cb) +SKB_CB_TCPACK_OFFSET) = 0;
433 EThCSGetPktInfo(Adapter, pvEThPayload, &stEthCsPktInfo);
435 switch (stEthCsPktInfo.eNwpktEthFrameType) {
436 case eEth802LLCFrame:
437 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "ClassifyPacket : 802LLCFrame\n");
438 pIpHeader = pvEThPayload + sizeof(struct bcm_eth_llc_frame);
440 case eEth802LLCSNAPFrame:
441 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "ClassifyPacket : 802LLC SNAP Frame\n");
442 pIpHeader = pvEThPayload + sizeof(struct bcm_eth_llc_snap_frame);
444 case eEth802QVLANFrame:
445 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "ClassifyPacket : 802.1Q VLANFrame\n");
446 pIpHeader = pvEThPayload + sizeof(struct bcm_eth_q_frame);
449 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "ClassifyPacket : ETH Other Frame\n");
450 pIpHeader = pvEThPayload + sizeof(struct bcm_ethernet2_frame);
453 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "ClassifyPacket : Unrecognized ETH Frame\n");
454 pIpHeader = pvEThPayload + sizeof(struct bcm_ethernet2_frame);
458 if (stEthCsPktInfo.eNwpktIPFrameType == eIPv4Packet) {
459 usCurrFragment = (ntohs(pIpHeader->frag_off) & IP_OFFSET);
460 if ((ntohs(pIpHeader->frag_off) & IP_MF) || usCurrFragment)
461 bFragmentedPkt = TRUE;
463 if (bFragmentedPkt) {
464 //Fragmented Packet. Get Frag Classifier Entry.
465 pstClassifierRule = GetFragIPClsEntry(Adapter, pIpHeader->id, pIpHeader->saddr);
466 if (pstClassifierRule) {
467 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "It is next Fragmented pkt");
468 bClassificationSucceed = TRUE;
470 if (!(ntohs(pIpHeader->frag_off) & IP_MF)) {
471 //Fragmented Last packet . Remove Frag Classifier Entry
472 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "This is the last fragmented Pkt");
473 DelFragIPClsEntry(Adapter, pIpHeader->id, pIpHeader->saddr);
478 for (uiLoopIndex = MAX_CLASSIFIERS - 1; uiLoopIndex >= 0; uiLoopIndex--) {
479 if (bClassificationSucceed)
481 //Iterate through all classifiers which are already in order of priority
482 //to classify the packet until match found
484 if (false == Adapter->astClassifierTable[uiLoopIndex].bUsed) {
485 bClassificationSucceed = false;
488 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "Adapter->PackInfo[%d].bvalid=True\n", uiLoopIndex);
490 if (0 == Adapter->astClassifierTable[uiLoopIndex].ucDirection) {
491 bClassificationSucceed = false;//cannot be processed for classification.
492 break; // it is a down link connection
495 pstClassifierRule = &Adapter->astClassifierTable[uiLoopIndex];
497 uiSfIndex = SearchSfid(Adapter, pstClassifierRule->ulSFID);
498 if (uiSfIndex >= NO_OF_QUEUES) {
499 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "Queue Not Valid. SearchSfid for this classifier Failed\n");
503 if (Adapter->PackInfo[uiSfIndex].bEthCSSupport) {
505 if (eEthUnsupportedFrame == stEthCsPktInfo.eNwpktEthFrameType) {
506 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, " ClassifyPacket : Packet Not a Valid Supported Ethernet Frame\n");
507 bClassificationSucceed = false;
513 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "Performing ETH CS Classification on Classifier Rule ID : %x Service Flow ID : %lx\n", pstClassifierRule->uiClassifierRuleIndex, Adapter->PackInfo[uiSfIndex].ulSFID);
514 bClassificationSucceed = EThCSClassifyPkt(Adapter, skb, &stEthCsPktInfo, pstClassifierRule, Adapter->PackInfo[uiSfIndex].bEthCSSupport);
516 if (!bClassificationSucceed) {
517 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "ClassifyPacket : Ethernet CS Classification Failed\n");
520 } else { // No ETH Supported on this SF
521 if (eEthOtherFrame != stEthCsPktInfo.eNwpktEthFrameType) {
522 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, " ClassifyPacket : Packet Not a 802.3 Ethernet Frame... hence not allowed over non-ETH CS SF\n");
523 bClassificationSucceed = false;
528 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "Proceeding to IP CS Clasification");
530 if (Adapter->PackInfo[uiSfIndex].bIPCSSupport) {
532 if (stEthCsPktInfo.eNwpktIPFrameType == eNonIPPacket) {
533 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, " ClassifyPacket : Packet is Not an IP Packet\n");
534 bClassificationSucceed = false;
537 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "Dump IP Header :\n");
538 DumpFullPacket((PUCHAR)pIpHeader, 20);
540 if (stEthCsPktInfo.eNwpktIPFrameType == eIPv4Packet)
541 bClassificationSucceed = IpVersion4(Adapter, pIpHeader, pstClassifierRule);
542 else if (stEthCsPktInfo.eNwpktIPFrameType == eIPv6Packet)
543 bClassificationSucceed = IpVersion6(Adapter, pIpHeader, pstClassifierRule);
549 if (bClassificationSucceed == TRUE) {
550 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "CF id : %d, SF ID is =%lu", pstClassifierRule->uiClassifierRuleIndex, pstClassifierRule->ulSFID);
552 //Store The matched Classifier in SKB
553 *((UINT32*)(skb->cb)+SKB_CB_CLASSIFICATION_OFFSET) = pstClassifierRule->uiClassifierRuleIndex;
554 if ((TCP == pIpHeader->protocol) && !bFragmentedPkt && (ETH_AND_IP_HEADER_LEN + TCP_HEADER_LEN <= skb->len)) {
555 IpHeaderLength = pIpHeader->ihl;
556 pTcpHeader = (struct bcm_tcp_header *)(((PUCHAR)pIpHeader)+(IpHeaderLength*4));
557 TcpHeaderLength = GET_TCP_HEADER_LEN(pTcpHeader->HeaderLength);
559 if ((pTcpHeader->ucFlags & TCP_ACK) &&
560 (ntohs(pIpHeader->tot_len) == (IpHeaderLength*4)+(TcpHeaderLength*4)))
561 *((UINT32*) (skb->cb) + SKB_CB_TCPACK_OFFSET) = TCP_ACK;
564 usIndex = SearchSfid(Adapter, pstClassifierRule->ulSFID);
565 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "index is =%d", usIndex);
567 //If this is the first fragment of a Fragmented pkt, add this CF. Only This CF should be used for all other fragment of this Pkt.
568 if (bFragmentedPkt && (usCurrFragment == 0)) {
569 //First Fragment of Fragmented Packet. Create Frag CLS Entry
570 struct bcm_fragmented_packet_info stFragPktInfo;
571 stFragPktInfo.bUsed = TRUE;
572 stFragPktInfo.ulSrcIpAddress = pIpHeader->saddr;
573 stFragPktInfo.usIpIdentification = pIpHeader->id;
574 stFragPktInfo.pstMatchedClassifierEntry = pstClassifierRule;
575 stFragPktInfo.bOutOfOrderFragment = false;
576 AddFragIPClsEntry(Adapter, &stFragPktInfo);
582 if (bClassificationSucceed)
585 return INVALID_QUEUE_INDEX;
588 static bool EthCSMatchSrcMACAddress(struct bcm_classifier_rule *pstClassifierRule, PUCHAR Mac)
591 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
592 if (pstClassifierRule->ucEthCSSrcMACLen == 0)
594 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "%s\n", __FUNCTION__);
595 for (i = 0; i < MAC_ADDRESS_SIZE; i++) {
596 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "SRC MAC[%x] = %x ClassifierRuleSrcMAC = %x Mask : %x\n", i, Mac[i], pstClassifierRule->au8EThCSSrcMAC[i], pstClassifierRule->au8EThCSSrcMACMask[i]);
597 if ((pstClassifierRule->au8EThCSSrcMAC[i] & pstClassifierRule->au8EThCSSrcMACMask[i]) !=
598 (Mac[i] & pstClassifierRule->au8EThCSSrcMACMask[i]))
604 static bool EthCSMatchDestMACAddress(struct bcm_classifier_rule *pstClassifierRule, PUCHAR Mac)
607 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
608 if (pstClassifierRule->ucEthCSDestMACLen == 0)
610 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "%s\n", __FUNCTION__);
611 for (i = 0; i < MAC_ADDRESS_SIZE; i++) {
612 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "SRC MAC[%x] = %x ClassifierRuleSrcMAC = %x Mask : %x\n", i, Mac[i], pstClassifierRule->au8EThCSDestMAC[i], pstClassifierRule->au8EThCSDestMACMask[i]);
613 if ((pstClassifierRule->au8EThCSDestMAC[i] & pstClassifierRule->au8EThCSDestMACMask[i]) !=
614 (Mac[i] & pstClassifierRule->au8EThCSDestMACMask[i]))
620 static bool EthCSMatchEThTypeSAP(struct bcm_classifier_rule *pstClassifierRule, struct sk_buff* skb, struct bcm_eth_packet_info *pstEthCsPktInfo)
622 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
623 if ((pstClassifierRule->ucEtherTypeLen == 0) ||
624 (pstClassifierRule->au8EthCSEtherType[0] == 0))
627 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "%s SrcEtherType:%x CLS EtherType[0]:%x\n", __FUNCTION__, pstEthCsPktInfo->usEtherType, pstClassifierRule->au8EthCSEtherType[0]);
628 if (pstClassifierRule->au8EthCSEtherType[0] == 1) {
629 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "%s CLS EtherType[1]:%x EtherType[2]:%x\n", __FUNCTION__, pstClassifierRule->au8EthCSEtherType[1], pstClassifierRule->au8EthCSEtherType[2]);
631 if (memcmp(&pstEthCsPktInfo->usEtherType, &pstClassifierRule->au8EthCSEtherType[1], 2) == 0)
637 if (pstClassifierRule->au8EthCSEtherType[0] == 2) {
638 if (eEth802LLCFrame != pstEthCsPktInfo->eNwpktEthFrameType)
641 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "%s EthCS DSAP:%x EtherType[2]:%x\n", __FUNCTION__, pstEthCsPktInfo->ucDSAP, pstClassifierRule->au8EthCSEtherType[2]);
642 if (pstEthCsPktInfo->ucDSAP == pstClassifierRule->au8EthCSEtherType[2])
653 static bool EthCSMatchVLANRules(struct bcm_classifier_rule *pstClassifierRule, struct sk_buff* skb, struct bcm_eth_packet_info *pstEthCsPktInfo)
655 bool bClassificationSucceed = false;
657 B_UINT8 uPriority = 0;
658 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
660 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "%s CLS UserPrio:%x CLS VLANID:%x\n", __FUNCTION__, ntohs(*((USHORT *)pstClassifierRule->usUserPriority)), pstClassifierRule->usVLANID);
662 /* In case FW didn't receive the TLV, the priority field should be ignored */
663 if (pstClassifierRule->usValidityBitMap & (1<<PKT_CLASSIFICATION_USER_PRIORITY_VALID)) {
664 if (pstEthCsPktInfo->eNwpktEthFrameType != eEth802QVLANFrame)
667 uPriority = (ntohs(*(USHORT *)(skb->data + sizeof(struct bcm_eth_header))) & 0xF000) >> 13;
669 if ((uPriority >= pstClassifierRule->usUserPriority[0]) && (uPriority <= pstClassifierRule->usUserPriority[1]))
670 bClassificationSucceed = TRUE;
672 if (!bClassificationSucceed)
676 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "ETH CS 802.1 D User Priority Rule Matched\n");
678 bClassificationSucceed = false;
680 if (pstClassifierRule->usValidityBitMap & (1<<PKT_CLASSIFICATION_VLANID_VALID)) {
681 if (pstEthCsPktInfo->eNwpktEthFrameType != eEth802QVLANFrame)
684 usVLANID = ntohs(*(USHORT *)(skb->data + sizeof(struct bcm_eth_header))) & 0xFFF;
686 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "%s Pkt VLANID %x Priority: %d\n", __FUNCTION__, usVLANID, uPriority);
688 if (usVLANID == ((pstClassifierRule->usVLANID & 0xFFF0) >> 4))
689 bClassificationSucceed = TRUE;
691 if (!bClassificationSucceed)
695 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "ETH CS 802.1 Q VLAN ID Rule Matched\n");
701 static bool EThCSClassifyPkt(struct bcm_mini_adapter *Adapter, struct sk_buff* skb,
702 struct bcm_eth_packet_info *pstEthCsPktInfo,
703 struct bcm_classifier_rule *pstClassifierRule,
704 B_UINT8 EthCSCupport)
706 bool bClassificationSucceed = false;
707 bClassificationSucceed = EthCSMatchSrcMACAddress(pstClassifierRule, ((struct bcm_eth_header *)(skb->data))->au8SourceAddress);
708 if (!bClassificationSucceed)
710 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "ETH CS SrcMAC Matched\n");
712 bClassificationSucceed = EthCSMatchDestMACAddress(pstClassifierRule, ((struct bcm_eth_header *)(skb->data))->au8DestinationAddress);
713 if (!bClassificationSucceed)
715 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "ETH CS DestMAC Matched\n");
717 //classify on ETHType/802.2SAP TLV
718 bClassificationSucceed = EthCSMatchEThTypeSAP(pstClassifierRule, skb, pstEthCsPktInfo);
719 if (!bClassificationSucceed)
722 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "ETH CS EthType/802.2SAP Matched\n");
724 //classify on 802.1VLAN Header Parameters
726 bClassificationSucceed = EthCSMatchVLANRules(pstClassifierRule, skb, pstEthCsPktInfo);
727 if (!bClassificationSucceed)
729 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "ETH CS 802.1 VLAN Rules Matched\n");
731 return bClassificationSucceed;
734 static void EThCSGetPktInfo(struct bcm_mini_adapter *Adapter, PVOID pvEthPayload,
735 struct bcm_eth_packet_info *pstEthCsPktInfo)
737 USHORT u16Etype = ntohs(((struct bcm_eth_header *)pvEthPayload)->u16Etype);
739 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "EthCSGetPktInfo : Eth Hdr Type : %X\n", u16Etype);
740 if (u16Etype > 0x5dc) {
741 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "EthCSGetPktInfo : ETH2 Frame\n");
743 if (u16Etype == ETHERNET_FRAMETYPE_802QVLAN) {
745 pstEthCsPktInfo->eNwpktEthFrameType = eEth802QVLANFrame;
746 u16Etype = ((struct bcm_eth_q_frame *)pvEthPayload)->EthType;
747 //((ETH_CS_802_Q_FRAME*)pvEthPayload)->UserPriority
749 pstEthCsPktInfo->eNwpktEthFrameType = eEthOtherFrame;
750 u16Etype = ntohs(u16Etype);
754 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "802.2 LLC Frame\n");
755 pstEthCsPktInfo->eNwpktEthFrameType = eEth802LLCFrame;
756 pstEthCsPktInfo->ucDSAP = ((struct bcm_eth_llc_frame *)pvEthPayload)->DSAP;
757 if (pstEthCsPktInfo->ucDSAP == 0xAA && ((struct bcm_eth_llc_frame *)pvEthPayload)->SSAP == 0xAA) {
759 pstEthCsPktInfo->eNwpktEthFrameType = eEth802LLCSNAPFrame;
760 u16Etype = ((struct bcm_eth_llc_snap_frame *)pvEthPayload)->usEtherType;
763 if (u16Etype == ETHERNET_FRAMETYPE_IPV4)
764 pstEthCsPktInfo->eNwpktIPFrameType = eIPv4Packet;
765 else if (u16Etype == ETHERNET_FRAMETYPE_IPV6)
766 pstEthCsPktInfo->eNwpktIPFrameType = eIPv6Packet;
768 pstEthCsPktInfo->eNwpktIPFrameType = eNonIPPacket;
770 pstEthCsPktInfo->usEtherType = ((struct bcm_eth_header *)pvEthPayload)->u16Etype;
771 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "EthCsPktInfo->eNwpktIPFrameType : %x\n", pstEthCsPktInfo->eNwpktIPFrameType);
772 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "EthCsPktInfo->eNwpktEthFrameType : %x\n", pstEthCsPktInfo->eNwpktEthFrameType);
773 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "EthCsPktInfo->usEtherType : %x\n", pstEthCsPktInfo->usEtherType);