3 static UINT CreateSFToClassifierRuleMapping(B_UINT16 uiVcid, B_UINT16 uiClsId, struct bcm_phs_table *psServiceFlowTable, struct bcm_phs_rule *psPhsRule, B_UINT8 u8AssociatedPHSI);
5 static UINT CreateClassiferToPHSRuleMapping(B_UINT16 uiVcid, B_UINT16 uiClsId, struct bcm_phs_entry *pstServiceFlowEntry, struct bcm_phs_rule *psPhsRule, B_UINT8 u8AssociatedPHSI);
7 static UINT CreateClassifierPHSRule(B_UINT16 uiClsId, struct bcm_phs_classifier_table *psaClassifiertable, struct bcm_phs_rule *psPhsRule, enum bcm_phs_classifier_context eClsContext, B_UINT8 u8AssociatedPHSI);
9 static UINT UpdateClassifierPHSRule(B_UINT16 uiClsId, struct bcm_phs_classifier_entry *pstClassifierEntry, struct bcm_phs_classifier_table *psaClassifiertable, struct bcm_phs_rule *psPhsRule, B_UINT8 u8AssociatedPHSI);
11 static bool ValidatePHSRuleComplete(struct bcm_phs_rule *psPhsRule);
13 static bool DerefPhsRule(B_UINT16 uiClsId, struct bcm_phs_classifier_table *psaClassifiertable, struct bcm_phs_rule *pstPhsRule);
15 static UINT GetClassifierEntry(struct bcm_phs_classifier_table *pstClassifierTable, B_UINT32 uiClsid, enum bcm_phs_classifier_context eClsContext, struct bcm_phs_classifier_entry **ppstClassifierEntry);
17 static UINT GetPhsRuleEntry(struct bcm_phs_classifier_table *pstClassifierTable, B_UINT32 uiPHSI, enum bcm_phs_classifier_context eClsContext, struct bcm_phs_rule **ppstPhsRule);
19 static void free_phs_serviceflow_rules(struct bcm_phs_table *psServiceFlowRulesTable);
21 static int phs_compress(struct bcm_phs_rule *phs_members, unsigned char *in_buf,
22 unsigned char *out_buf, unsigned int *header_size, UINT *new_header_size);
24 static int verify_suppress_phsf(unsigned char *in_buffer, unsigned char *out_buffer,
25 unsigned char *phsf, unsigned char *phsm, unsigned int phss, unsigned int phsv, UINT *new_header_size);
27 static int phs_decompress(unsigned char *in_buf, unsigned char *out_buf,
28 struct bcm_phs_rule *phs_rules, UINT *header_size);
30 static ULONG PhsCompress(void *pvContext,
36 UINT *pNewHeaderSize);
38 static ULONG PhsDeCompress(void *pvContext,
43 UINT *pOutHeaderSize);
49 * Function: PHSTransmit
50 * Description: This routine handle PHS(Payload Header Suppression for Tx path.
51 * It extracts a fragment of the NDIS_PACKET containing the header
52 * to be suppressed. It then suppresses the header by invoking PHS exported compress routine.
53 * The header data after suppression is copied back to the NDIS_PACKET.
55 * Input parameters: IN struct bcm_mini_adapter *Adapter - Miniport Adapter Context
56 * IN Packet - NDIS packet containing data to be transmitted
57 * IN USHORT Vcid - vcid pertaining to connection on which the packet is being sent.Used to
58 * identify PHS rule to be applied.
59 * B_UINT16 uiClassifierRuleID - Classifier Rule ID
60 * BOOLEAN bHeaderSuppressionEnabled - indicates if header suprression is enabled for SF.
62 * Return: STATUS_SUCCESS - If the send was successful.
63 * Other - If an error occurred.
66 int PHSTransmit(struct bcm_mini_adapter *Adapter,
67 struct sk_buff **pPacket,
69 B_UINT16 uiClassifierRuleID,
70 bool bHeaderSuppressionEnabled,
75 UINT unPHSPktHdrBytesCopied = 0;
76 UINT unPhsOldHdrSize = 0;
77 UINT unPHSNewPktHeaderLen = 0;
78 /* Pointer to PHS IN Hdr Buffer */
79 PUCHAR pucPHSPktHdrInBuf = Adapter->stPhsTxContextInfo.ucaHdrSuppressionInBuf;
80 /* Pointer to PHS OUT Hdr Buffer */
81 PUCHAR pucPHSPktHdrOutBuf = Adapter->stPhsTxContextInfo.ucaHdrSuppressionOutBuf;
83 UINT BytesToRemove = 0;
86 UINT numBytesCompressed = 0;
87 struct sk_buff *newPacket = NULL;
88 struct sk_buff *Packet = *pPacket;
90 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "In PHSTransmit");
93 BytesToRemove = ETH_HLEN;
95 * Accumulate the header upto the size we support suppression
99 usPacketType = ((struct ethhdr *)(Packet->data))->h_proto;
101 pucPHSPktHdrInBuf = Packet->data + BytesToRemove;
102 /* considering data after ethernet header */
103 if ((*PacketLen - BytesToRemove) < MAX_PHS_LENGTHS)
104 unPHSPktHdrBytesCopied = (*PacketLen - BytesToRemove);
106 unPHSPktHdrBytesCopied = MAX_PHS_LENGTHS;
108 if ((unPHSPktHdrBytesCopied > 0) &&
109 (unPHSPktHdrBytesCopied <= MAX_PHS_LENGTHS)) {
112 * Step 2 Suppress Header using PHS and fill into intermediate ucaPHSPktHdrOutBuf.
113 * Suppress only if IP Header and PHS Enabled For the Service Flow
115 if (((usPacketType == ETHERNET_FRAMETYPE_IPV4) ||
116 (usPacketType == ETHERNET_FRAMETYPE_IPV6)) &&
117 (bHeaderSuppressionEnabled)) {
119 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "\nTrying to PHS Compress Using Classifier rule 0x%X", uiClassifierRuleID);
120 unPHSNewPktHeaderLen = unPHSPktHdrBytesCopied;
121 ulPhsStatus = PhsCompress(&Adapter->stBCMPhsContext,
127 &unPHSNewPktHeaderLen);
128 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "\nPHS Old header Size : %d New Header Size %d\n", unPhsOldHdrSize, unPHSNewPktHeaderLen);
130 if (unPHSNewPktHeaderLen == unPhsOldHdrSize) {
132 if (ulPhsStatus == STATUS_PHS_COMPRESSED)
133 bPHSI = *pucPHSPktHdrOutBuf;
135 ulPhsStatus = STATUS_PHS_NOCOMPRESSION;
138 if (ulPhsStatus == STATUS_PHS_COMPRESSED) {
140 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "PHS Sending packet Compressed");
142 if (skb_cloned(Packet)) {
143 newPacket = skb_copy(Packet, GFP_ATOMIC);
145 if (newPacket == NULL)
146 return STATUS_FAILURE;
148 dev_kfree_skb(Packet);
149 *pPacket = Packet = newPacket;
150 pucPHSPktHdrInBuf = Packet->data + BytesToRemove;
153 numBytesCompressed = unPhsOldHdrSize - (unPHSNewPktHeaderLen + PHSI_LEN);
155 memcpy(pucPHSPktHdrInBuf + numBytesCompressed, pucPHSPktHdrOutBuf, unPHSNewPktHeaderLen + PHSI_LEN);
156 memcpy(Packet->data + numBytesCompressed, Packet->data, BytesToRemove);
157 skb_pull(Packet, numBytesCompressed);
159 return STATUS_SUCCESS;
161 /* if one byte headroom is not available, increase it through skb_cow */
162 if (!(skb_headroom(Packet) > 0)) {
164 if (skb_cow(Packet, 1)) {
165 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "SKB Cow Failed\n");
166 return STATUS_FAILURE;
172 * CAUTION: The MAC Header is getting corrupted
173 * here for IP CS - can be saved by copying 14
174 * Bytes. not needed .... hence corrupting it.
176 *(Packet->data + BytesToRemove) = bPHSI;
177 return STATUS_SUCCESS;
181 if (!bHeaderSuppressionEnabled)
182 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "\nHeader Suppression Disabled For SF: No PHS\n");
184 return STATUS_SUCCESS;
188 /* BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,"PHSTransmit : Dumping data packet After PHS"); */
189 return STATUS_SUCCESS;
192 int PHSReceive(struct bcm_mini_adapter *Adapter,
194 struct sk_buff *packet,
196 UCHAR *pucEthernetHdr,
197 UINT bHeaderSuppressionEnabled)
199 u32 nStandardPktHdrLen = 0;
200 u32 nTotalsuppressedPktHdrBytes = 0;
202 PUCHAR pucInBuff = NULL;
203 UINT TotalBytesAdded = 0;
205 if (!bHeaderSuppressionEnabled) {
206 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL, "\nPhs Disabled for incoming packet");
210 pucInBuff = packet->data;
212 /* Restore PHS suppressed header */
213 nStandardPktHdrLen = packet->len;
214 ulPhsStatus = PhsDeCompress(&Adapter->stBCMPhsContext,
217 Adapter->ucaPHSPktRestoreBuf,
218 &nTotalsuppressedPktHdrBytes,
219 &nStandardPktHdrLen);
221 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL, "\nSuppressed PktHdrLen : 0x%x Restored PktHdrLen : 0x%x",
222 nTotalsuppressedPktHdrBytes, nStandardPktHdrLen);
224 if (ulPhsStatus != STATUS_PHS_COMPRESSED) {
226 return STATUS_SUCCESS;
228 TotalBytesAdded = nStandardPktHdrLen - nTotalsuppressedPktHdrBytes - PHSI_LEN;
230 if (TotalBytesAdded) {
231 if (skb_headroom(packet) >= (SKB_RESERVE_ETHERNET_HEADER + TotalBytesAdded))
232 skb_push(packet, TotalBytesAdded);
234 if (skb_cow(packet, skb_headroom(packet) + TotalBytesAdded)) {
235 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "cow failed in receive\n");
236 return STATUS_FAILURE;
239 skb_push(packet, TotalBytesAdded);
243 memcpy(packet->data, Adapter->ucaPHSPktRestoreBuf, nStandardPktHdrLen);
246 return STATUS_SUCCESS;
249 void DumpFullPacket(UCHAR *pBuf, UINT nPktLen)
251 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
253 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "Dumping Data Packet");
254 BCM_DEBUG_PRINT_BUFFER(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, pBuf, nPktLen);
258 * Procedure: phs_init
260 * Description: This routine is responsible for allocating memory for classifier and
264 * pPhsdeviceExtension - ptr to Device extension containing PHS Classifier rules and PHS Rules , RX, TX buffer etc
267 * TRUE(1) -If allocation of memory was successful.
268 * FALSE -If allocation of memory fails.
270 int phs_init(struct bcm_phs_extension *pPhsdeviceExtension, struct bcm_mini_adapter *Adapter)
273 struct bcm_phs_table *pstServiceFlowTable;
275 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nPHS:phs_init function");
277 if (pPhsdeviceExtension->pstServiceFlowPhsRulesTable)
280 pPhsdeviceExtension->pstServiceFlowPhsRulesTable = kzalloc(sizeof(struct bcm_phs_table), GFP_KERNEL);
282 if (!pPhsdeviceExtension->pstServiceFlowPhsRulesTable) {
283 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nAllocation ServiceFlowPhsRulesTable failed");
287 pstServiceFlowTable = pPhsdeviceExtension->pstServiceFlowPhsRulesTable;
288 for (i = 0; i < MAX_SERVICEFLOWS; i++) {
289 struct bcm_phs_entry sServiceFlow = pstServiceFlowTable->stSFList[i];
290 sServiceFlow.pstClassifierTable = kzalloc(sizeof(struct bcm_phs_classifier_table), GFP_KERNEL);
291 if (!sServiceFlow.pstClassifierTable) {
292 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nAllocation failed");
293 free_phs_serviceflow_rules(pPhsdeviceExtension->pstServiceFlowPhsRulesTable);
294 pPhsdeviceExtension->pstServiceFlowPhsRulesTable = NULL;
299 pPhsdeviceExtension->CompressedTxBuffer = kmalloc(PHS_BUFFER_SIZE, GFP_KERNEL);
300 if (pPhsdeviceExtension->CompressedTxBuffer == NULL) {
301 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nAllocation failed");
302 free_phs_serviceflow_rules(pPhsdeviceExtension->pstServiceFlowPhsRulesTable);
303 pPhsdeviceExtension->pstServiceFlowPhsRulesTable = NULL;
307 pPhsdeviceExtension->UnCompressedRxBuffer = kmalloc(PHS_BUFFER_SIZE, GFP_KERNEL);
308 if (pPhsdeviceExtension->UnCompressedRxBuffer == NULL) {
309 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nAllocation failed");
310 kfree(pPhsdeviceExtension->CompressedTxBuffer);
311 free_phs_serviceflow_rules(pPhsdeviceExtension->pstServiceFlowPhsRulesTable);
312 pPhsdeviceExtension->pstServiceFlowPhsRulesTable = NULL;
316 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\n phs_init Successful");
317 return STATUS_SUCCESS;
320 int PhsCleanup(IN struct bcm_phs_extension *pPHSDeviceExt)
322 if (pPHSDeviceExt->pstServiceFlowPhsRulesTable) {
323 free_phs_serviceflow_rules(pPHSDeviceExt->pstServiceFlowPhsRulesTable);
324 pPHSDeviceExt->pstServiceFlowPhsRulesTable = NULL;
327 kfree(pPHSDeviceExt->CompressedTxBuffer);
328 pPHSDeviceExt->CompressedTxBuffer = NULL;
330 kfree(pPHSDeviceExt->UnCompressedRxBuffer);
331 pPHSDeviceExt->UnCompressedRxBuffer = NULL;
338 * PhsUpdateClassifierRule
340 * Routine Description:
341 * Exported function to add or modify a PHS Rule.
344 * IN void* pvContext - PHS Driver Specific Context
345 * IN B_UINT16 uiVcid - The Service Flow ID for which the PHS rule applies
346 * IN B_UINT16 uiClsId - The Classifier ID within the Service Flow for which the PHS rule applies.
347 * IN struct bcm_phs_rule *psPhsRule - The PHS Rule strcuture to be added to the PHS Rule table.
354 ULONG PhsUpdateClassifierRule(IN void *pvContext,
356 IN B_UINT16 uiClsId ,
357 IN struct bcm_phs_rule *psPhsRule,
358 IN B_UINT8 u8AssociatedPHSI)
362 struct bcm_phs_entry *pstServiceFlowEntry = NULL;
363 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
364 struct bcm_phs_extension *pDeviceExtension = (struct bcm_phs_extension *)pvContext;
366 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "PHS With Corr2 Changes\n");
368 if (pDeviceExtension == NULL) {
369 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "Invalid Device Extension\n");
370 return ERR_PHS_INVALID_DEVICE_EXETENSION;
373 if (u8AssociatedPHSI == 0)
374 return ERR_PHS_INVALID_PHS_RULE;
376 /* Retrieve the SFID Entry Index for requested Service Flow */
377 nSFIndex = GetServiceFlowEntry(pDeviceExtension->pstServiceFlowPhsRulesTable,
378 uiVcid, &pstServiceFlowEntry);
380 if (nSFIndex == PHS_INVALID_TABLE_INDEX) {
381 /* This is a new SF. Create a mapping entry for this */
382 lStatus = CreateSFToClassifierRuleMapping(uiVcid, uiClsId,
383 pDeviceExtension->pstServiceFlowPhsRulesTable, psPhsRule, u8AssociatedPHSI);
387 /* SF already Exists Add PHS Rule to existing SF */
388 lStatus = CreateClassiferToPHSRuleMapping(uiVcid, uiClsId,
389 pstServiceFlowEntry, psPhsRule, u8AssociatedPHSI);
397 * Routine Description:
398 * Deletes the specified phs Rule within Vcid
401 * IN void* pvContext - PHS Driver Specific Context
402 * IN B_UINT16 uiVcid - The Service Flow ID for which the PHS rule applies
403 * IN B_UINT8 u8PHSI - the PHS Index identifying PHS rule to be deleted.
410 ULONG PhsDeletePHSRule(IN void *pvContext, IN B_UINT16 uiVcid, IN B_UINT8 u8PHSI)
412 UINT nSFIndex = 0, nClsidIndex = 0;
413 struct bcm_phs_entry *pstServiceFlowEntry = NULL;
414 struct bcm_phs_classifier_table *pstClassifierRulesTable = NULL;
415 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
416 struct bcm_phs_extension *pDeviceExtension = (struct bcm_phs_extension *)pvContext;
418 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "======>\n");
420 if (pDeviceExtension) {
421 /* Retrieve the SFID Entry Index for requested Service Flow */
422 nSFIndex = GetServiceFlowEntry(pDeviceExtension->pstServiceFlowPhsRulesTable, uiVcid, &pstServiceFlowEntry);
424 if (nSFIndex == PHS_INVALID_TABLE_INDEX) {
425 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "SFID Match Failed\n");
426 return ERR_SF_MATCH_FAIL;
429 pstClassifierRulesTable = pstServiceFlowEntry->pstClassifierTable;
430 if (pstClassifierRulesTable) {
431 for (nClsidIndex = 0; nClsidIndex < MAX_PHSRULE_PER_SF; nClsidIndex++) {
432 if (pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].bUsed && pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule) {
433 if (pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8PHSI == u8PHSI) {
435 if (pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt)
436 pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt--;
438 if (0 == pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt)
439 kfree(pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule);
441 memset(&pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex], 0,
442 sizeof(struct bcm_phs_classifier_entry));
452 * PhsDeleteClassifierRule
454 * Routine Description:
455 * Exported function to Delete a PHS Rule for the SFID,CLSID Pair.
458 * IN void* pvContext - PHS Driver Specific Context
459 * IN B_UINT16 uiVcid - The Service Flow ID for which the PHS rule applies
460 * IN B_UINT16 uiClsId - The Classifier ID within the Service Flow for which the PHS rule applies.
467 ULONG PhsDeleteClassifierRule(IN void *pvContext, IN B_UINT16 uiVcid, IN B_UINT16 uiClsId)
469 UINT nSFIndex = 0, nClsidIndex = 0;
470 struct bcm_phs_entry *pstServiceFlowEntry = NULL;
471 struct bcm_phs_classifier_entry *pstClassifierEntry = NULL;
472 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
473 struct bcm_phs_extension *pDeviceExtension = (struct bcm_phs_extension *)pvContext;
475 if (pDeviceExtension) {
476 /* Retrieve the SFID Entry Index for requested Service Flow */
477 nSFIndex = GetServiceFlowEntry(pDeviceExtension->pstServiceFlowPhsRulesTable, uiVcid, &pstServiceFlowEntry);
478 if (nSFIndex == PHS_INVALID_TABLE_INDEX) {
479 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "SFID Match Failed\n");
480 return ERR_SF_MATCH_FAIL;
483 nClsidIndex = GetClassifierEntry(pstServiceFlowEntry->pstClassifierTable,
484 uiClsId, eActiveClassifierRuleContext, &pstClassifierEntry);
486 if ((nClsidIndex != PHS_INVALID_TABLE_INDEX) && (!pstClassifierEntry->bUnclassifiedPHSRule)) {
487 if (pstClassifierEntry->pstPhsRule) {
488 if (pstClassifierEntry->pstPhsRule->u8RefCnt)
489 pstClassifierEntry->pstPhsRule->u8RefCnt--;
491 if (0 == pstClassifierEntry->pstPhsRule->u8RefCnt)
492 kfree(pstClassifierEntry->pstPhsRule);
494 memset(pstClassifierEntry, 0, sizeof(struct bcm_phs_classifier_entry));
497 nClsidIndex = GetClassifierEntry(pstServiceFlowEntry->pstClassifierTable,
498 uiClsId, eOldClassifierRuleContext, &pstClassifierEntry);
500 if ((nClsidIndex != PHS_INVALID_TABLE_INDEX) && (!pstClassifierEntry->bUnclassifiedPHSRule)) {
501 kfree(pstClassifierEntry->pstPhsRule);
502 memset(pstClassifierEntry, 0, sizeof(struct bcm_phs_classifier_entry));
511 * Routine Description:
512 * Exported function to Delete a all PHS Rules for the SFID.
515 * IN void* pvContext - PHS Driver Specific Context
516 * IN B_UINT16 uiVcid - The Service Flow ID for which the PHS rules need to be deleted
523 ULONG PhsDeleteSFRules(IN void *pvContext, IN B_UINT16 uiVcid)
525 UINT nSFIndex = 0, nClsidIndex = 0;
526 struct bcm_phs_entry *pstServiceFlowEntry = NULL;
527 struct bcm_phs_classifier_table *pstClassifierRulesTable = NULL;
528 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
529 struct bcm_phs_extension *pDeviceExtension = (struct bcm_phs_extension *)pvContext;
531 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "====>\n");
533 if (pDeviceExtension) {
534 /* Retrieve the SFID Entry Index for requested Service Flow */
535 nSFIndex = GetServiceFlowEntry(pDeviceExtension->pstServiceFlowPhsRulesTable,
536 uiVcid, &pstServiceFlowEntry);
537 if (nSFIndex == PHS_INVALID_TABLE_INDEX) {
538 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "SFID Match Failed\n");
539 return ERR_SF_MATCH_FAIL;
542 pstClassifierRulesTable = pstServiceFlowEntry->pstClassifierTable;
543 if (pstClassifierRulesTable) {
544 for (nClsidIndex = 0; nClsidIndex < MAX_PHSRULE_PER_SF; nClsidIndex++) {
545 if (pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule) {
547 if (pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt)
548 pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt--;
550 if (0 == pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt)
551 kfree(pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule);
553 pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule = NULL;
555 memset(&pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex], 0, sizeof(struct bcm_phs_classifier_entry));
556 if (pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex].pstPhsRule) {
558 if (pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt)
559 pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt--;
561 if (0 == pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt)
562 kfree(pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex].pstPhsRule);
564 pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex].pstPhsRule = NULL;
566 memset(&pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex], 0, sizeof(struct bcm_phs_classifier_entry));
569 pstServiceFlowEntry->bUsed = false;
570 pstServiceFlowEntry->uiVcid = 0;
579 * Routine Description:
580 * Exported function to compress the data using PHS.
583 * IN void* pvContext - PHS Driver Specific Context.
584 * IN B_UINT16 uiVcid - The Service Flow ID to which current packet header compression applies.
585 * IN UINT uiClsId - The Classifier ID to which current packet header compression applies.
586 * IN void *pvInputBuffer - The Input buffer containg packet header data
587 * IN void *pvOutputBuffer - The output buffer returned by this function after PHS
588 * IN UINT *pOldHeaderSize - The actual size of the header before PHS
589 * IN UINT *pNewHeaderSize - The new size of the header after applying PHS
596 static ULONG PhsCompress(IN void *pvContext,
599 IN void *pvInputBuffer,
600 OUT void *pvOutputBuffer,
601 OUT UINT *pOldHeaderSize,
602 OUT UINT *pNewHeaderSize)
604 UINT nSFIndex = 0, nClsidIndex = 0;
605 struct bcm_phs_entry *pstServiceFlowEntry = NULL;
606 struct bcm_phs_classifier_entry *pstClassifierEntry = NULL;
607 struct bcm_phs_rule *pstPhsRule = NULL;
609 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
610 struct bcm_phs_extension *pDeviceExtension = (struct bcm_phs_extension *)pvContext;
612 if (pDeviceExtension == NULL) {
613 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "Invalid Device Extension\n");
614 lStatus = STATUS_PHS_NOCOMPRESSION;
618 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "Suppressing header\n");
620 /* Retrieve the SFID Entry Index for requested Service Flow */
621 nSFIndex = GetServiceFlowEntry(pDeviceExtension->pstServiceFlowPhsRulesTable,
622 uiVcid, &pstServiceFlowEntry);
623 if (nSFIndex == PHS_INVALID_TABLE_INDEX) {
624 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "SFID Match Failed\n");
625 lStatus = STATUS_PHS_NOCOMPRESSION;
629 nClsidIndex = GetClassifierEntry(pstServiceFlowEntry->pstClassifierTable,
630 uiClsId, eActiveClassifierRuleContext, &pstClassifierEntry);
632 if (nClsidIndex == PHS_INVALID_TABLE_INDEX) {
633 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "No PHS Rule Defined For Classifier\n");
634 lStatus = STATUS_PHS_NOCOMPRESSION;
638 /* get rule from SF id,Cls ID pair and proceed */
639 pstPhsRule = pstClassifierEntry->pstPhsRule;
640 if (!ValidatePHSRuleComplete(pstPhsRule)) {
641 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "PHS Rule Defined For Classifier But Not Complete\n");
642 lStatus = STATUS_PHS_NOCOMPRESSION;
646 /* Compress Packet */
647 lStatus = phs_compress(pstPhsRule, (PUCHAR)pvInputBuffer,
648 (PUCHAR)pvOutputBuffer, pOldHeaderSize, pNewHeaderSize);
650 if (lStatus == STATUS_PHS_COMPRESSED) {
651 pstPhsRule->PHSModifiedBytes += *pOldHeaderSize - *pNewHeaderSize - 1;
652 pstPhsRule->PHSModifiedNumPackets++;
654 pstPhsRule->PHSErrorNumPackets++;
662 * Routine Description:
663 * Exported function to restore the packet header in Rx path.
666 * IN void* pvContext - PHS Driver Specific Context.
667 * IN B_UINT16 uiVcid - The Service Flow ID to which current packet header restoration applies.
668 * IN void *pvInputBuffer - The Input buffer containg suppressed packet header data
669 * OUT void *pvOutputBuffer - The output buffer returned by this function after restoration
670 * OUT UINT *pHeaderSize - The packet header size after restoration is returned in this parameter.
677 static ULONG PhsDeCompress(IN void *pvContext,
679 IN void *pvInputBuffer,
680 OUT void *pvOutputBuffer,
681 OUT UINT *pInHeaderSize,
682 OUT UINT *pOutHeaderSize)
684 UINT nSFIndex = 0, nPhsRuleIndex = 0;
685 struct bcm_phs_entry *pstServiceFlowEntry = NULL;
686 struct bcm_phs_rule *pstPhsRule = NULL;
688 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
689 struct bcm_phs_extension *pDeviceExtension = (struct bcm_phs_extension *)pvContext;
692 if (pDeviceExtension == NULL) {
693 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL, "Invalid Device Extension\n");
694 return ERR_PHS_INVALID_DEVICE_EXETENSION;
697 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL, "Restoring header\n");
699 phsi = *((unsigned char *)(pvInputBuffer));
700 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL, "PHSI To Be Used For restore : %x\n", phsi);
701 if (phsi == UNCOMPRESSED_PACKET)
702 return STATUS_PHS_NOCOMPRESSION;
704 /* Retrieve the SFID Entry Index for requested Service Flow */
705 nSFIndex = GetServiceFlowEntry(pDeviceExtension->pstServiceFlowPhsRulesTable,
706 uiVcid, &pstServiceFlowEntry);
707 if (nSFIndex == PHS_INVALID_TABLE_INDEX) {
708 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL, "SFID Match Failed During Lookup\n");
709 return ERR_SF_MATCH_FAIL;
712 nPhsRuleIndex = GetPhsRuleEntry(pstServiceFlowEntry->pstClassifierTable, phsi,
713 eActiveClassifierRuleContext, &pstPhsRule);
714 if (nPhsRuleIndex == PHS_INVALID_TABLE_INDEX) {
715 /* Phs Rule does not exist in active rules table. Lets try in the old rules table. */
716 nPhsRuleIndex = GetPhsRuleEntry(pstServiceFlowEntry->pstClassifierTable,
717 phsi, eOldClassifierRuleContext, &pstPhsRule);
718 if (nPhsRuleIndex == PHS_INVALID_TABLE_INDEX)
719 return ERR_PHSRULE_MATCH_FAIL;
722 *pInHeaderSize = phs_decompress((PUCHAR)pvInputBuffer,
723 (PUCHAR)pvOutputBuffer, pstPhsRule, pOutHeaderSize);
725 pstPhsRule->PHSModifiedBytes += *pOutHeaderSize - *pInHeaderSize - 1;
727 pstPhsRule->PHSModifiedNumPackets++;
728 return STATUS_PHS_COMPRESSED;
732 * Procedure: free_phs_serviceflow_rules
734 * Description: This routine is responsible for freeing memory allocated for PHS rules.
737 * rules - ptr to S_SERVICEFLOW_TABLE structure.
740 * Does not return any value.
742 static void free_phs_serviceflow_rules(struct bcm_phs_table *psServiceFlowRulesTable)
745 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
747 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "=======>\n");
749 if (psServiceFlowRulesTable) {
750 for (i = 0; i < MAX_SERVICEFLOWS; i++) {
751 struct bcm_phs_entry stServiceFlowEntry = psServiceFlowRulesTable->stSFList[i];
752 struct bcm_phs_classifier_table *pstClassifierRulesTable = stServiceFlowEntry.pstClassifierTable;
754 if (pstClassifierRulesTable) {
755 for (j = 0; j < MAX_PHSRULE_PER_SF; j++) {
756 if (pstClassifierRulesTable->stActivePhsRulesList[j].pstPhsRule) {
758 if (pstClassifierRulesTable->stActivePhsRulesList[j].pstPhsRule->u8RefCnt)
759 pstClassifierRulesTable->stActivePhsRulesList[j].pstPhsRule->u8RefCnt--;
761 if (0 == pstClassifierRulesTable->stActivePhsRulesList[j].pstPhsRule->u8RefCnt)
762 kfree(pstClassifierRulesTable->stActivePhsRulesList[j].pstPhsRule);
764 pstClassifierRulesTable->stActivePhsRulesList[j].pstPhsRule = NULL;
767 if (pstClassifierRulesTable->stOldPhsRulesList[j].pstPhsRule) {
769 if (pstClassifierRulesTable->stOldPhsRulesList[j].pstPhsRule->u8RefCnt)
770 pstClassifierRulesTable->stOldPhsRulesList[j].pstPhsRule->u8RefCnt--;
772 if (0 == pstClassifierRulesTable->stOldPhsRulesList[j].pstPhsRule->u8RefCnt)
773 kfree(pstClassifierRulesTable->stOldPhsRulesList[j].pstPhsRule);
775 pstClassifierRulesTable->stOldPhsRulesList[j].pstPhsRule = NULL;
778 kfree(pstClassifierRulesTable);
779 stServiceFlowEntry.pstClassifierTable = pstClassifierRulesTable = NULL;
784 kfree(psServiceFlowRulesTable);
785 psServiceFlowRulesTable = NULL;
788 static bool ValidatePHSRuleComplete(IN struct bcm_phs_rule *psPhsRule)
791 if (!psPhsRule->u8PHSI) {
792 /* PHSI is not valid */
796 if (!psPhsRule->u8PHSS) {
797 /* PHSS Is Undefined */
801 /* Check if PHSF is defines for the PHS Rule */
802 if (!psPhsRule->u8PHSFLength) /* If any part of PHSF is valid then Rule contains valid PHSF */
810 UINT GetServiceFlowEntry(IN struct bcm_phs_table *psServiceFlowTable,
812 struct bcm_phs_entry **ppstServiceFlowEntry)
816 for (i = 0; i < MAX_SERVICEFLOWS; i++) {
817 if (psServiceFlowTable->stSFList[i].bUsed) {
818 if (psServiceFlowTable->stSFList[i].uiVcid == uiVcid) {
819 *ppstServiceFlowEntry = &psServiceFlowTable->stSFList[i];
825 *ppstServiceFlowEntry = NULL;
826 return PHS_INVALID_TABLE_INDEX;
829 static UINT GetClassifierEntry(IN struct bcm_phs_classifier_table *pstClassifierTable,
830 IN B_UINT32 uiClsid, enum bcm_phs_classifier_context eClsContext,
831 OUT struct bcm_phs_classifier_entry **ppstClassifierEntry)
834 struct bcm_phs_classifier_entry *psClassifierRules = NULL;
836 for (i = 0; i < MAX_PHSRULE_PER_SF; i++) {
838 if (eClsContext == eActiveClassifierRuleContext)
839 psClassifierRules = &pstClassifierTable->stActivePhsRulesList[i];
841 psClassifierRules = &pstClassifierTable->stOldPhsRulesList[i];
843 if (psClassifierRules->bUsed) {
844 if (psClassifierRules->uiClassifierRuleId == uiClsid) {
845 *ppstClassifierEntry = psClassifierRules;
851 *ppstClassifierEntry = NULL;
852 return PHS_INVALID_TABLE_INDEX;
855 static UINT GetPhsRuleEntry(IN struct bcm_phs_classifier_table *pstClassifierTable,
856 IN B_UINT32 uiPHSI, enum bcm_phs_classifier_context eClsContext,
857 OUT struct bcm_phs_rule **ppstPhsRule)
860 struct bcm_phs_classifier_entry *pstClassifierRule = NULL;
862 for (i = 0; i < MAX_PHSRULE_PER_SF; i++) {
863 if (eClsContext == eActiveClassifierRuleContext)
864 pstClassifierRule = &pstClassifierTable->stActivePhsRulesList[i];
866 pstClassifierRule = &pstClassifierTable->stOldPhsRulesList[i];
868 if (pstClassifierRule->bUsed) {
869 if (pstClassifierRule->u8PHSI == uiPHSI) {
870 *ppstPhsRule = pstClassifierRule->pstPhsRule;
877 return PHS_INVALID_TABLE_INDEX;
880 static UINT CreateSFToClassifierRuleMapping(IN B_UINT16 uiVcid, IN B_UINT16 uiClsId,
881 IN struct bcm_phs_table *psServiceFlowTable,
882 struct bcm_phs_rule *psPhsRule,
883 B_UINT8 u8AssociatedPHSI)
885 struct bcm_phs_classifier_table *psaClassifiertable = NULL;
888 bool bFreeEntryFound = false;
890 /* Check for a free entry in SFID table */
891 for (iSfIndex = 0; iSfIndex < MAX_SERVICEFLOWS; iSfIndex++) {
892 if (!psServiceFlowTable->stSFList[iSfIndex].bUsed) {
893 bFreeEntryFound = TRUE;
898 if (!bFreeEntryFound)
899 return ERR_SFTABLE_FULL;
901 psaClassifiertable = psServiceFlowTable->stSFList[iSfIndex].pstClassifierTable;
902 uiStatus = CreateClassifierPHSRule(uiClsId, psaClassifiertable, psPhsRule,
903 eActiveClassifierRuleContext, u8AssociatedPHSI);
904 if (uiStatus == PHS_SUCCESS) {
905 /* Add entry at free index to the SF */
906 psServiceFlowTable->stSFList[iSfIndex].bUsed = TRUE;
907 psServiceFlowTable->stSFList[iSfIndex].uiVcid = uiVcid;
913 static UINT CreateClassiferToPHSRuleMapping(IN B_UINT16 uiVcid,
915 IN struct bcm_phs_entry *pstServiceFlowEntry,
916 struct bcm_phs_rule *psPhsRule,
917 B_UINT8 u8AssociatedPHSI)
919 struct bcm_phs_classifier_entry *pstClassifierEntry = NULL;
920 UINT uiStatus = PHS_SUCCESS;
921 UINT nClassifierIndex = 0;
922 struct bcm_phs_classifier_table *psaClassifiertable = NULL;
923 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
925 psaClassifiertable = pstServiceFlowEntry->pstClassifierTable;
927 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "==>");
929 /* Check if the supplied Classifier already exists */
930 nClassifierIndex = GetClassifierEntry(
931 pstServiceFlowEntry->pstClassifierTable,
933 eActiveClassifierRuleContext,
934 &pstClassifierEntry);
936 if (nClassifierIndex == PHS_INVALID_TABLE_INDEX) {
938 * The Classifier doesn't exist. So its a new classifier being added.
939 * Add new entry to associate PHS Rule to the Classifier
942 uiStatus = CreateClassifierPHSRule(uiClsId, psaClassifiertable,
944 eActiveClassifierRuleContext,
950 * The Classifier exists.The PHS Rule for this classifier
954 if (pstClassifierEntry->u8PHSI == psPhsRule->u8PHSI) {
955 if (pstClassifierEntry->pstPhsRule == NULL)
956 return ERR_PHS_INVALID_PHS_RULE;
959 * This rule already exists if any fields are changed for this PHS
962 /* If any part of PHSF is valid then we update PHSF */
963 if (psPhsRule->u8PHSFLength) {
965 memcpy(pstClassifierEntry->pstPhsRule->u8PHSF,
966 psPhsRule->u8PHSF, MAX_PHS_LENGTHS);
969 if (psPhsRule->u8PHSFLength) {
971 pstClassifierEntry->pstPhsRule->u8PHSFLength = psPhsRule->u8PHSFLength;
974 if (psPhsRule->u8PHSMLength) {
976 memcpy(pstClassifierEntry->pstPhsRule->u8PHSM,
977 psPhsRule->u8PHSM, MAX_PHS_LENGTHS);
980 if (psPhsRule->u8PHSMLength) {
981 /* update PHSM Len */
982 pstClassifierEntry->pstPhsRule->u8PHSMLength =
983 psPhsRule->u8PHSMLength;
986 if (psPhsRule->u8PHSS) {
988 pstClassifierEntry->pstPhsRule->u8PHSS = psPhsRule->u8PHSS;
992 pstClassifierEntry->pstPhsRule->u8PHSV = psPhsRule->u8PHSV;
994 /* A new rule is being set for this classifier. */
995 uiStatus = UpdateClassifierPHSRule(uiClsId, pstClassifierEntry,
996 psaClassifiertable, psPhsRule, u8AssociatedPHSI);
1002 static UINT CreateClassifierPHSRule(IN B_UINT16 uiClsId,
1003 struct bcm_phs_classifier_table *psaClassifiertable,
1004 struct bcm_phs_rule *psPhsRule,
1005 enum bcm_phs_classifier_context eClsContext,
1006 B_UINT8 u8AssociatedPHSI)
1008 UINT iClassifierIndex = 0;
1009 bool bFreeEntryFound = false;
1010 struct bcm_phs_classifier_entry *psClassifierRules = NULL;
1011 UINT nStatus = PHS_SUCCESS;
1012 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
1014 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "Inside CreateClassifierPHSRule");
1016 if (psaClassifiertable == NULL)
1017 return ERR_INVALID_CLASSIFIERTABLE_FOR_SF;
1019 if (eClsContext == eOldClassifierRuleContext) {
1021 * If An Old Entry for this classifier ID already exists in the
1022 * old rules table replace it.
1026 GetClassifierEntry(psaClassifiertable, uiClsId,
1027 eClsContext, &psClassifierRules);
1029 if (iClassifierIndex != PHS_INVALID_TABLE_INDEX) {
1031 * The Classifier already exists in the old rules table
1032 * Lets replace the old classifier with the new one.
1034 bFreeEntryFound = TRUE;
1038 if (!bFreeEntryFound) {
1039 /* Continue to search for a free location to add the rule */
1040 for (iClassifierIndex = 0; iClassifierIndex <
1041 MAX_PHSRULE_PER_SF; iClassifierIndex++) {
1042 if (eClsContext == eActiveClassifierRuleContext)
1043 psClassifierRules = &psaClassifiertable->stActivePhsRulesList[iClassifierIndex];
1045 psClassifierRules = &psaClassifiertable->stOldPhsRulesList[iClassifierIndex];
1047 if (!psClassifierRules->bUsed) {
1048 bFreeEntryFound = TRUE;
1054 if (!bFreeEntryFound) {
1056 if (eClsContext == eActiveClassifierRuleContext)
1057 return ERR_CLSASSIFIER_TABLE_FULL;
1059 /* Lets replace the oldest rule if we are looking in old Rule table */
1060 if (psaClassifiertable->uiOldestPhsRuleIndex >= MAX_PHSRULE_PER_SF)
1061 psaClassifiertable->uiOldestPhsRuleIndex = 0;
1063 iClassifierIndex = psaClassifiertable->uiOldestPhsRuleIndex;
1064 psClassifierRules = &psaClassifiertable->stOldPhsRulesList[iClassifierIndex];
1066 (psaClassifiertable->uiOldestPhsRuleIndex)++;
1070 if (eClsContext == eOldClassifierRuleContext) {
1072 if (psClassifierRules->pstPhsRule == NULL) {
1074 psClassifierRules->pstPhsRule = kmalloc(sizeof(struct bcm_phs_rule), GFP_KERNEL);
1076 if (NULL == psClassifierRules->pstPhsRule)
1077 return ERR_PHSRULE_MEMALLOC_FAIL;
1080 psClassifierRules->bUsed = TRUE;
1081 psClassifierRules->uiClassifierRuleId = uiClsId;
1082 psClassifierRules->u8PHSI = psPhsRule->u8PHSI;
1083 psClassifierRules->bUnclassifiedPHSRule = psPhsRule->bUnclassifiedPHSRule;
1085 /* Update The PHS rule */
1086 memcpy(psClassifierRules->pstPhsRule, psPhsRule, sizeof(struct bcm_phs_rule));
1088 nStatus = UpdateClassifierPHSRule(uiClsId, psClassifierRules,
1089 psaClassifiertable, psPhsRule, u8AssociatedPHSI);
1094 static UINT UpdateClassifierPHSRule(IN B_UINT16 uiClsId,
1095 IN struct bcm_phs_classifier_entry *pstClassifierEntry,
1096 struct bcm_phs_classifier_table *psaClassifiertable,
1097 struct bcm_phs_rule *psPhsRule,
1098 B_UINT8 u8AssociatedPHSI)
1100 struct bcm_phs_rule *pstAddPhsRule = NULL;
1101 UINT nPhsRuleIndex = 0;
1102 bool bPHSRuleOrphaned = false;
1103 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
1105 psPhsRule->u8RefCnt = 0;
1107 /* Step 1 Deref Any Exisiting PHS Rule in this classifier Entry */
1108 bPHSRuleOrphaned = DerefPhsRule(uiClsId, psaClassifiertable,
1109 pstClassifierEntry->pstPhsRule);
1111 /* Step 2 Search if there is a PHS Rule with u8AssociatedPHSI in Classifier table for this SF */
1112 nPhsRuleIndex = GetPhsRuleEntry(psaClassifiertable, u8AssociatedPHSI,
1113 eActiveClassifierRuleContext, &pstAddPhsRule);
1114 if (PHS_INVALID_TABLE_INDEX == nPhsRuleIndex) {
1116 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nAdding New PHSRuleEntry For Classifier");
1118 if (psPhsRule->u8PHSI == 0) {
1119 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nError PHSI is Zero\n");
1120 return ERR_PHS_INVALID_PHS_RULE;
1123 /* Step 2.a PHS Rule Does Not Exist .Create New PHS Rule for uiClsId */
1124 if (false == bPHSRuleOrphaned) {
1126 pstClassifierEntry->pstPhsRule = kmalloc(sizeof(struct bcm_phs_rule), GFP_KERNEL);
1127 if (NULL == pstClassifierEntry->pstPhsRule)
1128 return ERR_PHSRULE_MEMALLOC_FAIL;
1130 memcpy(pstClassifierEntry->pstPhsRule, psPhsRule, sizeof(struct bcm_phs_rule));
1132 /* Step 2.b PHS Rule Exists Tie uiClsId with the existing PHS Rule */
1133 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nTying Classifier to Existing PHS Rule");
1134 if (bPHSRuleOrphaned) {
1135 kfree(pstClassifierEntry->pstPhsRule);
1136 pstClassifierEntry->pstPhsRule = NULL;
1138 pstClassifierEntry->pstPhsRule = pstAddPhsRule;
1141 pstClassifierEntry->bUsed = TRUE;
1142 pstClassifierEntry->u8PHSI = pstClassifierEntry->pstPhsRule->u8PHSI;
1143 pstClassifierEntry->uiClassifierRuleId = uiClsId;
1144 pstClassifierEntry->pstPhsRule->u8RefCnt++;
1145 pstClassifierEntry->bUnclassifiedPHSRule = pstClassifierEntry->pstPhsRule->bUnclassifiedPHSRule;
1150 static bool DerefPhsRule(IN B_UINT16 uiClsId, struct bcm_phs_classifier_table *psaClassifiertable, struct bcm_phs_rule *pstPhsRule)
1152 if (pstPhsRule == NULL)
1155 if (pstPhsRule->u8RefCnt)
1156 pstPhsRule->u8RefCnt--;
1158 if (0 == pstPhsRule->u8RefCnt) {
1160 * if(pstPhsRule->u8PHSI)
1161 * Store the currently active rule into the old rules list
1162 * CreateClassifierPHSRule(uiClsId,psaClassifiertable,pstPhsRule,eOldClassifierRuleContext,pstPhsRule->u8PHSI);
1169 void DumpPhsRules(struct bcm_phs_extension *pDeviceExtension)
1172 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
1174 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\n Dumping PHS Rules :\n");
1176 for (i = 0; i < MAX_SERVICEFLOWS; i++) {
1178 struct bcm_phs_entry stServFlowEntry =
1179 pDeviceExtension->pstServiceFlowPhsRulesTable->stSFList[i];
1180 if (stServFlowEntry.bUsed) {
1182 for (j = 0; j < MAX_PHSRULE_PER_SF; j++) {
1184 for (l = 0; l < 2; l++) {
1185 struct bcm_phs_classifier_entry stClsEntry;
1188 stClsEntry = stServFlowEntry.pstClassifierTable->stActivePhsRulesList[j];
1189 if (stClsEntry.bUsed)
1190 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n Active PHS Rule :\n");
1192 stClsEntry = stServFlowEntry.pstClassifierTable->stOldPhsRulesList[j];
1193 if (stClsEntry.bUsed)
1194 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n Old PHS Rule :\n");
1197 if (stClsEntry.bUsed) {
1198 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\n VCID : %#X", stServFlowEntry.uiVcid);
1199 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n ClassifierID : %#X", stClsEntry.uiClassifierRuleId);
1200 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSRuleID : %#X", stClsEntry.u8PHSI);
1201 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n****************PHS Rule********************\n");
1202 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSI : %#X", stClsEntry.pstPhsRule->u8PHSI);
1203 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSFLength : %#X ", stClsEntry.pstPhsRule->u8PHSFLength);
1204 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSF : ");
1206 for (k = 0 ; k < stClsEntry.pstPhsRule->u8PHSFLength; k++)
1207 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "%#X ", stClsEntry.pstPhsRule->u8PHSF[k]);
1208 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSMLength : %#X", stClsEntry.pstPhsRule->u8PHSMLength);
1209 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSM :");
1211 for (k = 0; k < stClsEntry.pstPhsRule->u8PHSMLength; k++)
1212 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "%#X ", stClsEntry.pstPhsRule->u8PHSM[k]);
1213 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSS : %#X ", stClsEntry.pstPhsRule->u8PHSS);
1214 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSV : %#X", stClsEntry.pstPhsRule->u8PHSV);
1215 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\n********************************************\n");
1224 * Procedure: phs_decompress
1226 * Description: This routine restores the static fields within the packet.
1229 * in_buf - ptr to incoming packet buffer.
1230 * out_buf - ptr to output buffer where the suppressed header is copied.
1231 * decomp_phs_rules - ptr to PHS rule.
1232 * header_size - ptr to field which holds the phss or phsf_length.
1235 * size -The number of bytes of dynamic fields present with in the incoming packet
1237 * 0 -If PHS rule is NULL.If PHSI is 0 indicateing packet as uncompressed.
1239 static int phs_decompress(unsigned char *in_buf,
1240 unsigned char *out_buf,
1241 struct bcm_phs_rule *decomp_phs_rules,
1245 struct bcm_phs_rule *tmp_memb;
1247 unsigned char *phsf, *phsm;
1248 int in_buf_len = *header_size - 1;
1249 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
1253 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL, "====>\n");
1256 if ((decomp_phs_rules == NULL))
1259 tmp_memb = decomp_phs_rules;
1261 * BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_RECEIVE,DBG_LVL_ALL,"\nDECOMP:In phs_decompress PHSI 1 %d",phsi));
1262 * header_size = tmp_memb->u8PHSFLength;
1264 phss = tmp_memb->u8PHSS;
1265 phsf = tmp_memb->u8PHSF;
1266 phsm = tmp_memb->u8PHSM;
1268 if (phss > MAX_PHS_LENGTHS)
1269 phss = MAX_PHS_LENGTHS;
1272 * BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_RECEIVE,DBG_LVL_ALL,"\nDECOMP:
1273 * In phs_decompress PHSI %d phss %d index %d",phsi,phss,index));
1275 while ((phss > 0) && (size < in_buf_len)) {
1276 bit = ((*phsm << i) & SUPPRESS);
1278 if (bit == SUPPRESS) {
1280 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL, "\nDECOMP:In phss %d phsf %d output %d",
1281 phss, *phsf, *out_buf);
1284 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL, "\nDECOMP:In phss %d input %d output %d",
1285 phss, *in_buf, *out_buf);
1293 *header_size = *header_size + 1;
1295 if (i > MAX_NO_BIT) {
1305 * Procedure: phs_compress
1307 * Description: This routine suppresses the static fields within the packet.Before
1308 * that it will verify the fields to be suppressed with the corresponding fields in the
1309 * phsf. For verification it checks the phsv field of PHS rule. If set and verification
1310 * succeeds it suppresses the field.If any one static field is found different none of
1311 * the static fields are suppressed then the packet is sent as uncompressed packet with
1315 * phs_rule - ptr to PHS rule.
1316 * in_buf - ptr to incoming packet buffer.
1317 * out_buf - ptr to output buffer where the suppressed header is copied.
1318 * header_size - ptr to field which holds the phss.
1321 * size-The number of bytes copied into the output buffer i.e dynamic fields
1322 * 0 -If PHS rule is NULL.If PHSV field is not set.If the verification fails.
1324 static int phs_compress(struct bcm_phs_rule *phs_rule,
1325 unsigned char *in_buf,
1326 unsigned char *out_buf,
1328 UINT *new_header_size)
1330 unsigned char *old_addr = out_buf;
1332 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
1334 if (phs_rule == NULL) {
1335 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "\nphs_compress(): phs_rule null!");
1336 *out_buf = ZERO_PHSI;
1337 return STATUS_PHS_NOCOMPRESSION;
1340 if (phs_rule->u8PHSS <= *new_header_size)
1341 *header_size = phs_rule->u8PHSS;
1343 *header_size = *new_header_size;
1347 suppress = verify_suppress_phsf(in_buf, out_buf, phs_rule->u8PHSF,
1348 phs_rule->u8PHSM, phs_rule->u8PHSS,
1349 phs_rule->u8PHSV, new_header_size);
1351 if (suppress == STATUS_PHS_COMPRESSED) {
1352 *old_addr = (unsigned char)phs_rule->u8PHSI;
1353 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "\nCOMP:In phs_compress phsi %d", phs_rule->u8PHSI);
1355 *old_addr = ZERO_PHSI;
1356 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "\nCOMP:In phs_compress PHSV Verification failed");
1363 * Procedure: verify_suppress_phsf
1365 * Description: This routine verifies the fields of the packet and if all the
1366 * static fields are equal it adds the phsi of that PHS rule.If any static
1367 * field differs it woun't suppress any field.
1370 * rules_set - ptr to classifier_rules.
1371 * in_buffer - ptr to incoming packet buffer.
1372 * out_buffer - ptr to output buffer where the suppressed header is copied.
1373 * phsf - ptr to phsf.
1374 * phsm - ptr to phsm.
1375 * phss - variable holding phss.
1378 * size-The number of bytes copied into the output buffer i.e dynamic fields.
1379 * 0 -Packet has failed the verification.
1381 static int verify_suppress_phsf(unsigned char *in_buffer,
1382 unsigned char *out_buffer,
1383 unsigned char *phsf,
1384 unsigned char *phsm,
1387 UINT *new_header_size)
1389 unsigned int size = 0;
1391 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
1393 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "\nCOMP:In verify_phsf PHSM - 0x%X", *phsm);
1395 if (phss > (*new_header_size))
1396 phss = *new_header_size;
1399 bit = ((*phsm << i) & SUPPRESS);
1400 if (bit == SUPPRESS) {
1401 if (*in_buffer != *phsf) {
1402 if (phsv == VERIFY) {
1403 BCM_DEBUG_PRINT(Adapter,
1407 "\nCOMP:In verify_phsf failed for field %d buf %d phsf %d",
1411 return STATUS_PHS_NOCOMPRESSION;
1414 BCM_DEBUG_PRINT(Adapter,
1418 "\nCOMP:In verify_phsf success for field %d buf %d phsf %d",
1423 *out_buffer = *in_buffer;
1424 BCM_DEBUG_PRINT(Adapter,
1428 "\nCOMP:In copying_header input %d out %d",
1440 if (i > MAX_NO_BIT) {
1445 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "\nCOMP:In verify_phsf success");
1446 *new_header_size = size;
1447 return STATUS_PHS_COMPRESSED;