Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1 | #include "headers.h" |
| 2 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 3 | static UINT CreateSFToClassifierRuleMapping(B_UINT16 uiVcid, B_UINT16 uiClsId, struct bcm_phs_table *psServiceFlowTable, struct bcm_phs_rule *psPhsRule, B_UINT8 u8AssociatedPHSI); |
Stephen Hemminger | 9dd47ee | 2010-11-01 12:24:00 -0400 | [diff] [blame] | 4 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 5 | static UINT CreateClassiferToPHSRuleMapping(B_UINT16 uiVcid, B_UINT16 uiClsId, struct bcm_phs_entry *pstServiceFlowEntry, struct bcm_phs_rule *psPhsRule, B_UINT8 u8AssociatedPHSI); |
Stephen Hemminger | 9dd47ee | 2010-11-01 12:24:00 -0400 | [diff] [blame] | 6 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 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); |
Stephen Hemminger | 9dd47ee | 2010-11-01 12:24:00 -0400 | [diff] [blame] | 8 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 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); |
Stephen Hemminger | 9dd47ee | 2010-11-01 12:24:00 -0400 | [diff] [blame] | 10 | |
Lisa Nguyen | 3abd6f1 | 2013-10-28 01:35:59 -0700 | [diff] [blame] | 11 | static bool ValidatePHSRuleComplete(struct bcm_phs_rule *psPhsRule); |
Stephen Hemminger | 9dd47ee | 2010-11-01 12:24:00 -0400 | [diff] [blame] | 12 | |
Lisa Nguyen | 3abd6f1 | 2013-10-28 01:35:59 -0700 | [diff] [blame] | 13 | static bool DerefPhsRule(B_UINT16 uiClsId, struct bcm_phs_classifier_table *psaClassifiertable, struct bcm_phs_rule *pstPhsRule); |
Stephen Hemminger | 9dd47ee | 2010-11-01 12:24:00 -0400 | [diff] [blame] | 14 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 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); |
Stephen Hemminger | 9dd47ee | 2010-11-01 12:24:00 -0400 | [diff] [blame] | 16 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 17 | static UINT GetPhsRuleEntry(struct bcm_phs_classifier_table *pstClassifierTable, B_UINT32 uiPHSI, enum bcm_phs_classifier_context eClsContext, struct bcm_phs_rule **ppstPhsRule); |
Stephen Hemminger | 9dd47ee | 2010-11-01 12:24:00 -0400 | [diff] [blame] | 18 | |
Kevin McKinney | da4d150 | 2012-12-20 00:31:29 -0500 | [diff] [blame] | 19 | static void free_phs_serviceflow_rules(struct bcm_phs_table *psServiceFlowRulesTable); |
Stephen Hemminger | 9dd47ee | 2010-11-01 12:24:00 -0400 | [diff] [blame] | 20 | |
Kevin McKinney | a903d65 | 2012-12-20 00:31:34 -0500 | [diff] [blame] | 21 | static int phs_compress(struct bcm_phs_rule *phs_members, unsigned char *in_buf, |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 22 | unsigned char *out_buf, unsigned int *header_size, UINT *new_header_size); |
Stephen Hemminger | 9dd47ee | 2010-11-01 12:24:00 -0400 | [diff] [blame] | 23 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 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); |
Stephen Hemminger | 9dd47ee | 2010-11-01 12:24:00 -0400 | [diff] [blame] | 26 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 27 | static int phs_decompress(unsigned char *in_buf, unsigned char *out_buf, |
| 28 | struct bcm_phs_rule *phs_rules, UINT *header_size); |
Stephen Hemminger | 9dd47ee | 2010-11-01 12:24:00 -0400 | [diff] [blame] | 29 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 30 | static ULONG PhsCompress(void *pvContext, |
| 31 | B_UINT16 uiVcid, |
| 32 | B_UINT16 uiClsId, |
| 33 | void *pvInputBuffer, |
| 34 | void *pvOutputBuffer, |
| 35 | UINT *pOldHeaderSize, |
| 36 | UINT *pNewHeaderSize); |
Stephen Hemminger | 9dd47ee | 2010-11-01 12:24:00 -0400 | [diff] [blame] | 37 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 38 | static ULONG PhsDeCompress(void *pvContext, |
| 39 | B_UINT16 uiVcid, |
| 40 | void *pvInputBuffer, |
| 41 | void *pvOutputBuffer, |
| 42 | UINT *pInHeaderSize, |
| 43 | UINT *pOutHeaderSize); |
Stephen Hemminger | 9dd47ee | 2010-11-01 12:24:00 -0400 | [diff] [blame] | 44 | |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 45 | #define IN |
| 46 | #define OUT |
| 47 | |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 48 | /* |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 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. |
| 54 | * |
| 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. |
| 61 | * |
| 62 | * Return: STATUS_SUCCESS - If the send was successful. |
| 63 | * Other - If an error occurred. |
| 64 | */ |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 65 | |
Kevin McKinney | 2979460 | 2012-05-26 12:05:12 -0400 | [diff] [blame] | 66 | int PHSTransmit(struct bcm_mini_adapter *Adapter, |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 67 | struct sk_buff **pPacket, |
| 68 | USHORT Vcid, |
| 69 | B_UINT16 uiClassifierRuleID, |
Lisa Nguyen | 3abd6f1 | 2013-10-28 01:35:59 -0700 | [diff] [blame] | 70 | bool bHeaderSuppressionEnabled, |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 71 | UINT *PacketLen, |
| 72 | UCHAR bEthCSSupport) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 73 | { |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 74 | /* PHS Sepcific */ |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 75 | UINT unPHSPktHdrBytesCopied = 0; |
| 76 | UINT unPhsOldHdrSize = 0; |
| 77 | UINT unPHSNewPktHeaderLen = 0; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 78 | /* Pointer to PHS IN Hdr Buffer */ |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 79 | PUCHAR pucPHSPktHdrInBuf = Adapter->stPhsTxContextInfo.ucaHdrSuppressionInBuf; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 80 | /* Pointer to PHS OUT Hdr Buffer */ |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 81 | PUCHAR pucPHSPktHdrOutBuf = Adapter->stPhsTxContextInfo.ucaHdrSuppressionOutBuf; |
| 82 | UINT usPacketType; |
| 83 | UINT BytesToRemove = 0; |
Lisa Nguyen | 3abd6f1 | 2013-10-28 01:35:59 -0700 | [diff] [blame] | 84 | bool bPHSI = 0; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 85 | LONG ulPhsStatus = 0; |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 86 | UINT numBytesCompressed = 0; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 87 | struct sk_buff *newPacket = NULL; |
| 88 | struct sk_buff *Packet = *pPacket; |
| 89 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 90 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "In PHSTransmit"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 91 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 92 | if (!bEthCSSupport) |
| 93 | BytesToRemove = ETH_HLEN; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 94 | /* |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 95 | * Accumulate the header upto the size we support suppression |
| 96 | * from NDIS packet |
| 97 | */ |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 98 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 99 | usPacketType = ((struct ethhdr *)(Packet->data))->h_proto; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 100 | |
| 101 | pucPHSPktHdrInBuf = Packet->data + BytesToRemove; |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 102 | /* considering data after ethernet header */ |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 103 | if ((*PacketLen - BytesToRemove) < MAX_PHS_LENGTHS) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 104 | unPHSPktHdrBytesCopied = (*PacketLen - BytesToRemove); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 105 | else |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 106 | unPHSPktHdrBytesCopied = MAX_PHS_LENGTHS; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 107 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 108 | if ((unPHSPktHdrBytesCopied > 0) && |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 109 | (unPHSPktHdrBytesCopied <= MAX_PHS_LENGTHS)) { |
| 110 | |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 111 | /* |
| 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 |
| 114 | */ |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 115 | if (((usPacketType == ETHERNET_FRAMETYPE_IPV4) || |
| 116 | (usPacketType == ETHERNET_FRAMETYPE_IPV6)) && |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 117 | (bHeaderSuppressionEnabled)) { |
| 118 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 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, |
| 122 | Vcid, |
| 123 | uiClassifierRuleID, |
| 124 | pucPHSPktHdrInBuf, |
| 125 | pucPHSPktHdrOutBuf, |
| 126 | &unPhsOldHdrSize, |
| 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); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 129 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 130 | if (unPHSNewPktHeaderLen == unPhsOldHdrSize) { |
| 131 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 132 | if (ulPhsStatus == STATUS_PHS_COMPRESSED) |
| 133 | bPHSI = *pucPHSPktHdrOutBuf; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 134 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 135 | ulPhsStatus = STATUS_PHS_NOCOMPRESSION; |
| 136 | } |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 137 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 138 | if (ulPhsStatus == STATUS_PHS_COMPRESSED) { |
| 139 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 140 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "PHS Sending packet Compressed"); |
| 141 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 142 | if (skb_cloned(Packet)) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 143 | newPacket = skb_copy(Packet, GFP_ATOMIC); |
| 144 | |
| 145 | if (newPacket == NULL) |
| 146 | return STATUS_FAILURE; |
| 147 | |
| 148 | dev_kfree_skb(Packet); |
| 149 | *pPacket = Packet = newPacket; |
| 150 | pucPHSPktHdrInBuf = Packet->data + BytesToRemove; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 153 | numBytesCompressed = unPhsOldHdrSize - (unPHSNewPktHeaderLen + PHSI_LEN); |
| 154 | |
| 155 | memcpy(pucPHSPktHdrInBuf + numBytesCompressed, pucPHSPktHdrOutBuf, unPHSNewPktHeaderLen + PHSI_LEN); |
| 156 | memcpy(Packet->data + numBytesCompressed, Packet->data, BytesToRemove); |
| 157 | skb_pull(Packet, numBytesCompressed); |
| 158 | |
| 159 | return STATUS_SUCCESS; |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 160 | } else { |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 161 | /* if one byte headroom is not available, increase it through skb_cow */ |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 162 | if (!(skb_headroom(Packet) > 0)) { |
| 163 | |
| 164 | if (skb_cow(Packet, 1)) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 165 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "SKB Cow Failed\n"); |
| 166 | return STATUS_FAILURE; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 167 | } |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 168 | } |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 169 | skb_push(Packet, 1); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 170 | |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 171 | /* |
| 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. |
| 175 | */ |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 176 | *(Packet->data + BytesToRemove) = bPHSI; |
| 177 | return STATUS_SUCCESS; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 178 | } |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 179 | } else { |
| 180 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 181 | if (!bHeaderSuppressionEnabled) |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 182 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "\nHeader Suppression Disabled For SF: No PHS\n"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 183 | |
| 184 | return STATUS_SUCCESS; |
| 185 | } |
| 186 | } |
| 187 | |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 188 | /* BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,"PHSTransmit : Dumping data packet After PHS"); */ |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 189 | return STATUS_SUCCESS; |
| 190 | } |
| 191 | |
Kevin McKinney | 2979460 | 2012-05-26 12:05:12 -0400 | [diff] [blame] | 192 | int PHSReceive(struct bcm_mini_adapter *Adapter, |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 193 | USHORT usVcid, |
| 194 | struct sk_buff *packet, |
| 195 | UINT *punPacketLen, |
| 196 | UCHAR *pucEthernetHdr, |
| 197 | UINT bHeaderSuppressionEnabled) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 198 | { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 199 | u32 nStandardPktHdrLen = 0; |
| 200 | u32 nTotalsuppressedPktHdrBytes = 0; |
| 201 | int ulPhsStatus = 0; |
| 202 | PUCHAR pucInBuff = NULL; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 203 | UINT TotalBytesAdded = 0; |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 204 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 205 | if (!bHeaderSuppressionEnabled) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 206 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL, "\nPhs Disabled for incoming packet"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 207 | return ulPhsStatus; |
| 208 | } |
| 209 | |
| 210 | pucInBuff = packet->data; |
| 211 | |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 212 | /* Restore PHS suppressed header */ |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 213 | nStandardPktHdrLen = packet->len; |
| 214 | ulPhsStatus = PhsDeCompress(&Adapter->stBCMPhsContext, |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 215 | usVcid, |
| 216 | pucInBuff, |
| 217 | Adapter->ucaPHSPktRestoreBuf, |
| 218 | &nTotalsuppressedPktHdrBytes, |
| 219 | &nStandardPktHdrLen); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 220 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 221 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL, "\nSuppressed PktHdrLen : 0x%x Restored PktHdrLen : 0x%x", |
| 222 | nTotalsuppressedPktHdrBytes, nStandardPktHdrLen); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 223 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 224 | if (ulPhsStatus != STATUS_PHS_COMPRESSED) { |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 225 | skb_pull(packet, 1); |
| 226 | return STATUS_SUCCESS; |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 227 | } else { |
Peter Meerwald | b38e274 | 2012-06-13 20:44:35 +0200 | [diff] [blame] | 228 | TotalBytesAdded = nStandardPktHdrLen - nTotalsuppressedPktHdrBytes - PHSI_LEN; |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 229 | |
| 230 | if (TotalBytesAdded) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 231 | if (skb_headroom(packet) >= (SKB_RESERVE_ETHERNET_HEADER + TotalBytesAdded)) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 232 | skb_push(packet, TotalBytesAdded); |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 233 | else { |
| 234 | if (skb_cow(packet, skb_headroom(packet) + TotalBytesAdded)) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 235 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "cow failed in receive\n"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 236 | return STATUS_FAILURE; |
| 237 | } |
| 238 | |
| 239 | skb_push(packet, TotalBytesAdded); |
| 240 | } |
| 241 | } |
| 242 | |
Stephen Hemminger | 082e889 | 2010-11-01 09:35:21 -0400 | [diff] [blame] | 243 | memcpy(packet->data, Adapter->ucaPHSPktRestoreBuf, nStandardPktHdrLen); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | return STATUS_SUCCESS; |
| 247 | } |
| 248 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 249 | void DumpFullPacket(UCHAR *pBuf, UINT nPktLen) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 250 | { |
Kevin McKinney | 2979460 | 2012-05-26 12:05:12 -0400 | [diff] [blame] | 251 | struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 252 | |
| 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); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 257 | /* |
| 258 | * Procedure: phs_init |
| 259 | * |
| 260 | * Description: This routine is responsible for allocating memory for classifier and |
| 261 | * PHS rules. |
| 262 | * |
| 263 | * Arguments: |
| 264 | * pPhsdeviceExtension - ptr to Device extension containing PHS Classifier rules and PHS Rules , RX, TX buffer etc |
| 265 | * |
| 266 | * Returns: |
Kevin McKinney | 175c512 | 2013-02-20 23:25:30 -0500 | [diff] [blame] | 267 | * TRUE(1) -If allocation of memory was successful. |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 268 | * FALSE -If allocation of memory fails. |
| 269 | */ |
Kevin McKinney | 60dadf9 | 2012-12-20 00:31:28 -0500 | [diff] [blame] | 270 | int phs_init(struct bcm_phs_extension *pPhsdeviceExtension, struct bcm_mini_adapter *Adapter) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 271 | { |
| 272 | int i; |
Kevin McKinney | da4d150 | 2012-12-20 00:31:29 -0500 | [diff] [blame] | 273 | struct bcm_phs_table *pstServiceFlowTable; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 274 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 275 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nPHS:phs_init function"); |
| 276 | |
| 277 | if (pPhsdeviceExtension->pstServiceFlowPhsRulesTable) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 278 | return -EINVAL; |
| 279 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 280 | pPhsdeviceExtension->pstServiceFlowPhsRulesTable = kzalloc(sizeof(struct bcm_phs_table), GFP_KERNEL); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 281 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 282 | if (!pPhsdeviceExtension->pstServiceFlowPhsRulesTable) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 283 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nAllocation ServiceFlowPhsRulesTable failed"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 284 | return -ENOMEM; |
| 285 | } |
| 286 | |
| 287 | pstServiceFlowTable = pPhsdeviceExtension->pstServiceFlowPhsRulesTable; |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 288 | for (i = 0; i < MAX_SERVICEFLOWS; i++) { |
Kevin McKinney | db134a6 | 2012-12-20 00:31:30 -0500 | [diff] [blame] | 289 | struct bcm_phs_entry sServiceFlow = pstServiceFlowTable->stSFList[i]; |
Kevin McKinney | a700dbd | 2012-12-20 00:31:31 -0500 | [diff] [blame] | 290 | sServiceFlow.pstClassifierTable = kzalloc(sizeof(struct bcm_phs_classifier_table), GFP_KERNEL); |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 291 | if (!sServiceFlow.pstClassifierTable) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 292 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nAllocation failed"); |
| 293 | free_phs_serviceflow_rules(pPhsdeviceExtension->pstServiceFlowPhsRulesTable); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 294 | pPhsdeviceExtension->pstServiceFlowPhsRulesTable = NULL; |
| 295 | return -ENOMEM; |
| 296 | } |
| 297 | } |
| 298 | |
Stephen Hemminger | 082e889 | 2010-11-01 09:35:21 -0400 | [diff] [blame] | 299 | pPhsdeviceExtension->CompressedTxBuffer = kmalloc(PHS_BUFFER_SIZE, GFP_KERNEL); |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 300 | if (pPhsdeviceExtension->CompressedTxBuffer == NULL) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 301 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nAllocation failed"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 302 | free_phs_serviceflow_rules(pPhsdeviceExtension->pstServiceFlowPhsRulesTable); |
| 303 | pPhsdeviceExtension->pstServiceFlowPhsRulesTable = NULL; |
| 304 | return -ENOMEM; |
| 305 | } |
| 306 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 307 | pPhsdeviceExtension->UnCompressedRxBuffer = kmalloc(PHS_BUFFER_SIZE, GFP_KERNEL); |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 308 | if (pPhsdeviceExtension->UnCompressedRxBuffer == NULL) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 309 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nAllocation failed"); |
Stephen Hemminger | 082e889 | 2010-11-01 09:35:21 -0400 | [diff] [blame] | 310 | kfree(pPhsdeviceExtension->CompressedTxBuffer); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 311 | free_phs_serviceflow_rules(pPhsdeviceExtension->pstServiceFlowPhsRulesTable); |
| 312 | pPhsdeviceExtension->pstServiceFlowPhsRulesTable = NULL; |
| 313 | return -ENOMEM; |
| 314 | } |
| 315 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 316 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\n phs_init Successful"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 317 | return STATUS_SUCCESS; |
| 318 | } |
| 319 | |
Kevin McKinney | 60dadf9 | 2012-12-20 00:31:28 -0500 | [diff] [blame] | 320 | int PhsCleanup(IN struct bcm_phs_extension *pPHSDeviceExt) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 321 | { |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 322 | if (pPHSDeviceExt->pstServiceFlowPhsRulesTable) { |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 323 | free_phs_serviceflow_rules(pPHSDeviceExt->pstServiceFlowPhsRulesTable); |
| 324 | pPHSDeviceExt->pstServiceFlowPhsRulesTable = NULL; |
| 325 | } |
| 326 | |
Stephen Hemminger | 082e889 | 2010-11-01 09:35:21 -0400 | [diff] [blame] | 327 | kfree(pPHSDeviceExt->CompressedTxBuffer); |
| 328 | pPHSDeviceExt->CompressedTxBuffer = NULL; |
| 329 | |
| 330 | kfree(pPHSDeviceExt->UnCompressedRxBuffer); |
| 331 | pPHSDeviceExt->UnCompressedRxBuffer = NULL; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 332 | |
| 333 | return 0; |
| 334 | } |
| 335 | |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 336 | /* |
| 337 | * PHS functions |
| 338 | * PhsUpdateClassifierRule |
| 339 | * |
| 340 | * Routine Description: |
| 341 | * Exported function to add or modify a PHS Rule. |
| 342 | * |
| 343 | * Arguments: |
| 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. |
| 348 | * |
| 349 | * Return Value: |
| 350 | * |
| 351 | * 0 if successful, |
| 352 | * >0 Error. |
| 353 | */ |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 354 | ULONG PhsUpdateClassifierRule(IN void *pvContext, |
| 355 | IN B_UINT16 uiVcid , |
| 356 | IN B_UINT16 uiClsId , |
| 357 | IN struct bcm_phs_rule *psPhsRule, |
| 358 | IN B_UINT8 u8AssociatedPHSI) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 359 | { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 360 | ULONG lStatus = 0; |
| 361 | UINT nSFIndex = 0; |
Kevin McKinney | db134a6 | 2012-12-20 00:31:30 -0500 | [diff] [blame] | 362 | struct bcm_phs_entry *pstServiceFlowEntry = NULL; |
Kevin McKinney | 2979460 | 2012-05-26 12:05:12 -0400 | [diff] [blame] | 363 | struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 364 | struct bcm_phs_extension *pDeviceExtension = (struct bcm_phs_extension *)pvContext; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 365 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 366 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "PHS With Corr2 Changes\n"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 367 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 368 | if (pDeviceExtension == NULL) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 369 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "Invalid Device Extension\n"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 370 | return ERR_PHS_INVALID_DEVICE_EXETENSION; |
| 371 | } |
| 372 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 373 | if (u8AssociatedPHSI == 0) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 374 | return ERR_PHS_INVALID_PHS_RULE; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 375 | |
| 376 | /* Retrieve the SFID Entry Index for requested Service Flow */ |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 377 | nSFIndex = GetServiceFlowEntry(pDeviceExtension->pstServiceFlowPhsRulesTable, |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 378 | uiVcid, &pstServiceFlowEntry); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 379 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 380 | if (nSFIndex == PHS_INVALID_TABLE_INDEX) { |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 381 | /* This is a new SF. Create a mapping entry for this */ |
| 382 | lStatus = CreateSFToClassifierRuleMapping(uiVcid, uiClsId, |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 383 | pDeviceExtension->pstServiceFlowPhsRulesTable, psPhsRule, u8AssociatedPHSI); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 384 | return lStatus; |
| 385 | } |
| 386 | |
| 387 | /* SF already Exists Add PHS Rule to existing SF */ |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 388 | lStatus = CreateClassiferToPHSRuleMapping(uiVcid, uiClsId, |
| 389 | pstServiceFlowEntry, psPhsRule, u8AssociatedPHSI); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 390 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 391 | return lStatus; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 392 | } |
| 393 | |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 394 | /* |
| 395 | * PhsDeletePHSRule |
| 396 | * |
| 397 | * Routine Description: |
| 398 | * Deletes the specified phs Rule within Vcid |
| 399 | * |
| 400 | * Arguments: |
| 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. |
| 404 | * |
| 405 | * Return Value: |
| 406 | * |
| 407 | * 0 if successful, |
| 408 | * >0 Error. |
| 409 | */ |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 410 | ULONG PhsDeletePHSRule(IN void *pvContext, IN B_UINT16 uiVcid, IN B_UINT8 u8PHSI) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 411 | { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 412 | ULONG lStatus = 0; |
| 413 | UINT nSFIndex = 0, nClsidIndex = 0; |
Kevin McKinney | db134a6 | 2012-12-20 00:31:30 -0500 | [diff] [blame] | 414 | struct bcm_phs_entry *pstServiceFlowEntry = NULL; |
Kevin McKinney | a700dbd | 2012-12-20 00:31:31 -0500 | [diff] [blame] | 415 | struct bcm_phs_classifier_table *pstClassifierRulesTable = NULL; |
Kevin McKinney | 2979460 | 2012-05-26 12:05:12 -0400 | [diff] [blame] | 416 | struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 417 | struct bcm_phs_extension *pDeviceExtension = (struct bcm_phs_extension *)pvContext; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 418 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 419 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "======>\n"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 420 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 421 | if (pDeviceExtension) { |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 422 | /* Retrieve the SFID Entry Index for requested Service Flow */ |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 423 | nSFIndex = GetServiceFlowEntry(pDeviceExtension->pstServiceFlowPhsRulesTable, uiVcid, &pstServiceFlowEntry); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 424 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 425 | if (nSFIndex == PHS_INVALID_TABLE_INDEX) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 426 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "SFID Match Failed\n"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 427 | return ERR_SF_MATCH_FAIL; |
| 428 | } |
| 429 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 430 | pstClassifierRulesTable = pstServiceFlowEntry->pstClassifierTable; |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 431 | if (pstClassifierRulesTable) { |
| 432 | for (nClsidIndex = 0; nClsidIndex < MAX_PHSRULE_PER_SF; nClsidIndex++) { |
| 433 | if (pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].bUsed && pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule) { |
| 434 | if (pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8PHSI == u8PHSI) { |
| 435 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 436 | if (pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt) |
Stephen Hemminger | 082e889 | 2010-11-01 09:35:21 -0400 | [diff] [blame] | 437 | pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt--; |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 438 | |
| 439 | if (0 == pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt) |
Stephen Hemminger | 082e889 | 2010-11-01 09:35:21 -0400 | [diff] [blame] | 440 | kfree(pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule); |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 441 | |
Stephen Hemminger | 082e889 | 2010-11-01 09:35:21 -0400 | [diff] [blame] | 442 | memset(&pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex], 0, |
Kevin McKinney | 2212e93 | 2012-12-20 00:31:32 -0500 | [diff] [blame] | 443 | sizeof(struct bcm_phs_classifier_entry)); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 444 | } |
| 445 | } |
| 446 | } |
| 447 | } |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 448 | } |
| 449 | return lStatus; |
| 450 | } |
| 451 | |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 452 | /* |
| 453 | * PhsDeleteClassifierRule |
| 454 | * |
| 455 | * Routine Description: |
| 456 | * Exported function to Delete a PHS Rule for the SFID,CLSID Pair. |
| 457 | * |
| 458 | * Arguments: |
| 459 | * IN void* pvContext - PHS Driver Specific Context |
| 460 | * IN B_UINT16 uiVcid - The Service Flow ID for which the PHS rule applies |
| 461 | * IN B_UINT16 uiClsId - The Classifier ID within the Service Flow for which the PHS rule applies. |
| 462 | * |
| 463 | * Return Value: |
| 464 | * |
| 465 | * 0 if successful, |
| 466 | * >0 Error. |
| 467 | */ |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 468 | ULONG PhsDeleteClassifierRule(IN void *pvContext, IN B_UINT16 uiVcid, IN B_UINT16 uiClsId) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 469 | { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 470 | ULONG lStatus = 0; |
| 471 | UINT nSFIndex = 0, nClsidIndex = 0; |
Kevin McKinney | db134a6 | 2012-12-20 00:31:30 -0500 | [diff] [blame] | 472 | struct bcm_phs_entry *pstServiceFlowEntry = NULL; |
Kevin McKinney | 2212e93 | 2012-12-20 00:31:32 -0500 | [diff] [blame] | 473 | struct bcm_phs_classifier_entry *pstClassifierEntry = NULL; |
Kevin McKinney | 2979460 | 2012-05-26 12:05:12 -0400 | [diff] [blame] | 474 | struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 475 | struct bcm_phs_extension *pDeviceExtension = (struct bcm_phs_extension *)pvContext; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 476 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 477 | if (pDeviceExtension) { |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 478 | /* Retrieve the SFID Entry Index for requested Service Flow */ |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 479 | nSFIndex = GetServiceFlowEntry(pDeviceExtension->pstServiceFlowPhsRulesTable, uiVcid, &pstServiceFlowEntry); |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 480 | if (nSFIndex == PHS_INVALID_TABLE_INDEX) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 481 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "SFID Match Failed\n"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 482 | return ERR_SF_MATCH_FAIL; |
| 483 | } |
| 484 | |
| 485 | nClsidIndex = GetClassifierEntry(pstServiceFlowEntry->pstClassifierTable, |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 486 | uiClsId, eActiveClassifierRuleContext, &pstClassifierEntry); |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 487 | |
| 488 | if ((nClsidIndex != PHS_INVALID_TABLE_INDEX) && (!pstClassifierEntry->bUnclassifiedPHSRule)) { |
| 489 | if (pstClassifierEntry->pstPhsRule) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 490 | if (pstClassifierEntry->pstPhsRule->u8RefCnt) |
| 491 | pstClassifierEntry->pstPhsRule->u8RefCnt--; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 492 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 493 | if (0 == pstClassifierEntry->pstPhsRule->u8RefCnt) |
| 494 | kfree(pstClassifierEntry->pstPhsRule); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 495 | } |
Kevin McKinney | 2212e93 | 2012-12-20 00:31:32 -0500 | [diff] [blame] | 496 | memset(pstClassifierEntry, 0, sizeof(struct bcm_phs_classifier_entry)); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | nClsidIndex = GetClassifierEntry(pstServiceFlowEntry->pstClassifierTable, |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 500 | uiClsId, eOldClassifierRuleContext, &pstClassifierEntry); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 501 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 502 | if ((nClsidIndex != PHS_INVALID_TABLE_INDEX) && (!pstClassifierEntry->bUnclassifiedPHSRule)) { |
Stephen Hemminger | 082e889 | 2010-11-01 09:35:21 -0400 | [diff] [blame] | 503 | kfree(pstClassifierEntry->pstPhsRule); |
Kevin McKinney | 2212e93 | 2012-12-20 00:31:32 -0500 | [diff] [blame] | 504 | memset(pstClassifierEntry, 0, sizeof(struct bcm_phs_classifier_entry)); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 505 | } |
| 506 | } |
| 507 | return lStatus; |
| 508 | } |
| 509 | |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 510 | /* |
| 511 | * PhsDeleteSFRules |
| 512 | * |
| 513 | * Routine Description: |
| 514 | * Exported function to Delete a all PHS Rules for the SFID. |
| 515 | * |
| 516 | * Arguments: |
| 517 | * IN void* pvContext - PHS Driver Specific Context |
| 518 | * IN B_UINT16 uiVcid - The Service Flow ID for which the PHS rules need to be deleted |
| 519 | * |
| 520 | * Return Value: |
| 521 | * |
| 522 | * 0 if successful, |
| 523 | * >0 Error. |
| 524 | */ |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 525 | ULONG PhsDeleteSFRules(IN void *pvContext, IN B_UINT16 uiVcid) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 526 | { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 527 | ULONG lStatus = 0; |
| 528 | UINT nSFIndex = 0, nClsidIndex = 0; |
Kevin McKinney | db134a6 | 2012-12-20 00:31:30 -0500 | [diff] [blame] | 529 | struct bcm_phs_entry *pstServiceFlowEntry = NULL; |
Kevin McKinney | a700dbd | 2012-12-20 00:31:31 -0500 | [diff] [blame] | 530 | struct bcm_phs_classifier_table *pstClassifierRulesTable = NULL; |
Kevin McKinney | 2979460 | 2012-05-26 12:05:12 -0400 | [diff] [blame] | 531 | struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 532 | struct bcm_phs_extension *pDeviceExtension = (struct bcm_phs_extension *)pvContext; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 533 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 534 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "====>\n"); |
| 535 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 536 | if (pDeviceExtension) { |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 537 | /* Retrieve the SFID Entry Index for requested Service Flow */ |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 538 | nSFIndex = GetServiceFlowEntry(pDeviceExtension->pstServiceFlowPhsRulesTable, |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 539 | uiVcid, &pstServiceFlowEntry); |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 540 | if (nSFIndex == PHS_INVALID_TABLE_INDEX) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 541 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "SFID Match Failed\n"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 542 | return ERR_SF_MATCH_FAIL; |
| 543 | } |
| 544 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 545 | pstClassifierRulesTable = pstServiceFlowEntry->pstClassifierTable; |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 546 | if (pstClassifierRulesTable) { |
| 547 | for (nClsidIndex = 0; nClsidIndex < MAX_PHSRULE_PER_SF; nClsidIndex++) { |
| 548 | if (pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule) { |
| 549 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 550 | if (pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt) |
| 551 | pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt--; |
| 552 | |
| 553 | if (0 == pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt) |
Stephen Hemminger | 082e889 | 2010-11-01 09:35:21 -0400 | [diff] [blame] | 554 | kfree(pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule); |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 555 | |
| 556 | pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule = NULL; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 557 | } |
Kevin McKinney | 2212e93 | 2012-12-20 00:31:32 -0500 | [diff] [blame] | 558 | memset(&pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex], 0, sizeof(struct bcm_phs_classifier_entry)); |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 559 | if (pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex].pstPhsRule) { |
| 560 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 561 | if (pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt) |
| 562 | pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt--; |
| 563 | |
| 564 | if (0 == pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt) |
| 565 | kfree(pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex].pstPhsRule); |
| 566 | |
| 567 | pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex].pstPhsRule = NULL; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 568 | } |
Kevin McKinney | 2212e93 | 2012-12-20 00:31:32 -0500 | [diff] [blame] | 569 | memset(&pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex], 0, sizeof(struct bcm_phs_classifier_entry)); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 570 | } |
| 571 | } |
Lisa Nguyen | f70c8a9 | 2013-10-28 01:36:19 -0700 | [diff] [blame] | 572 | pstServiceFlowEntry->bUsed = false; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 573 | pstServiceFlowEntry->uiVcid = 0; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | return lStatus; |
| 577 | } |
| 578 | |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 579 | /* |
| 580 | * PhsCompress |
| 581 | * |
| 582 | * Routine Description: |
| 583 | * Exported function to compress the data using PHS. |
| 584 | * |
| 585 | * Arguments: |
| 586 | * IN void* pvContext - PHS Driver Specific Context. |
| 587 | * IN B_UINT16 uiVcid - The Service Flow ID to which current packet header compression applies. |
| 588 | * IN UINT uiClsId - The Classifier ID to which current packet header compression applies. |
| 589 | * IN void *pvInputBuffer - The Input buffer containg packet header data |
| 590 | * IN void *pvOutputBuffer - The output buffer returned by this function after PHS |
| 591 | * IN UINT *pOldHeaderSize - The actual size of the header before PHS |
| 592 | * IN UINT *pNewHeaderSize - The new size of the header after applying PHS |
| 593 | * |
| 594 | * Return Value: |
| 595 | * |
| 596 | * 0 if successful, |
| 597 | * >0 Error. |
| 598 | */ |
Shalin Mehta | f2be635 | 2013-09-17 00:42:17 -0700 | [diff] [blame] | 599 | static ULONG PhsCompress(IN void *pvContext, |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 600 | IN B_UINT16 uiVcid, |
| 601 | IN B_UINT16 uiClsId, |
| 602 | IN void *pvInputBuffer, |
| 603 | OUT void *pvOutputBuffer, |
| 604 | OUT UINT *pOldHeaderSize, |
| 605 | OUT UINT *pNewHeaderSize) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 606 | { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 607 | UINT nSFIndex = 0, nClsidIndex = 0; |
Kevin McKinney | db134a6 | 2012-12-20 00:31:30 -0500 | [diff] [blame] | 608 | struct bcm_phs_entry *pstServiceFlowEntry = NULL; |
Kevin McKinney | 2212e93 | 2012-12-20 00:31:32 -0500 | [diff] [blame] | 609 | struct bcm_phs_classifier_entry *pstClassifierEntry = NULL; |
Kevin McKinney | a903d65 | 2012-12-20 00:31:34 -0500 | [diff] [blame] | 610 | struct bcm_phs_rule *pstPhsRule = NULL; |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 611 | ULONG lStatus = 0; |
Kevin McKinney | 2979460 | 2012-05-26 12:05:12 -0400 | [diff] [blame] | 612 | struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 613 | struct bcm_phs_extension *pDeviceExtension = (struct bcm_phs_extension *)pvContext; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 614 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 615 | if (pDeviceExtension == NULL) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 616 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "Invalid Device Extension\n"); |
| 617 | lStatus = STATUS_PHS_NOCOMPRESSION; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 618 | return lStatus; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 621 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "Suppressing header\n"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 622 | |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 623 | /* Retrieve the SFID Entry Index for requested Service Flow */ |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 624 | nSFIndex = GetServiceFlowEntry(pDeviceExtension->pstServiceFlowPhsRulesTable, |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 625 | uiVcid, &pstServiceFlowEntry); |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 626 | if (nSFIndex == PHS_INVALID_TABLE_INDEX) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 627 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "SFID Match Failed\n"); |
| 628 | lStatus = STATUS_PHS_NOCOMPRESSION; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 629 | return lStatus; |
| 630 | } |
| 631 | |
| 632 | nClsidIndex = GetClassifierEntry(pstServiceFlowEntry->pstClassifierTable, |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 633 | uiClsId, eActiveClassifierRuleContext, &pstClassifierEntry); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 634 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 635 | if (nClsidIndex == PHS_INVALID_TABLE_INDEX) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 636 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "No PHS Rule Defined For Classifier\n"); |
| 637 | lStatus = STATUS_PHS_NOCOMPRESSION; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 638 | return lStatus; |
| 639 | } |
| 640 | |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 641 | /* get rule from SF id,Cls ID pair and proceed */ |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 642 | pstPhsRule = pstClassifierEntry->pstPhsRule; |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 643 | if (!ValidatePHSRuleComplete(pstPhsRule)) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 644 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "PHS Rule Defined For Classifier But Not Complete\n"); |
| 645 | lStatus = STATUS_PHS_NOCOMPRESSION; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 646 | return lStatus; |
| 647 | } |
| 648 | |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 649 | /* Compress Packet */ |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 650 | lStatus = phs_compress(pstPhsRule, (PUCHAR)pvInputBuffer, |
| 651 | (PUCHAR)pvOutputBuffer, pOldHeaderSize, pNewHeaderSize); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 652 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 653 | if (lStatus == STATUS_PHS_COMPRESSED) { |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 654 | pstPhsRule->PHSModifiedBytes += *pOldHeaderSize - *pNewHeaderSize - 1; |
| 655 | pstPhsRule->PHSModifiedNumPackets++; |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 656 | } else |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 657 | pstPhsRule->PHSErrorNumPackets++; |
| 658 | |
| 659 | return lStatus; |
| 660 | } |
| 661 | |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 662 | /* |
| 663 | * PhsDeCompress |
| 664 | * |
| 665 | * Routine Description: |
| 666 | * Exported function to restore the packet header in Rx path. |
| 667 | * |
| 668 | * Arguments: |
| 669 | * IN void* pvContext - PHS Driver Specific Context. |
| 670 | * IN B_UINT16 uiVcid - The Service Flow ID to which current packet header restoration applies. |
| 671 | * IN void *pvInputBuffer - The Input buffer containg suppressed packet header data |
| 672 | * OUT void *pvOutputBuffer - The output buffer returned by this function after restoration |
| 673 | * OUT UINT *pHeaderSize - The packet header size after restoration is returned in this parameter. |
| 674 | * |
| 675 | * Return Value: |
| 676 | * |
| 677 | * 0 if successful, |
| 678 | * >0 Error. |
| 679 | */ |
Shalin Mehta | f2be635 | 2013-09-17 00:42:17 -0700 | [diff] [blame] | 680 | static ULONG PhsDeCompress(IN void *pvContext, |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 681 | IN B_UINT16 uiVcid, |
| 682 | IN void *pvInputBuffer, |
| 683 | OUT void *pvOutputBuffer, |
| 684 | OUT UINT *pInHeaderSize, |
| 685 | OUT UINT *pOutHeaderSize) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 686 | { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 687 | UINT nSFIndex = 0, nPhsRuleIndex = 0; |
Kevin McKinney | db134a6 | 2012-12-20 00:31:30 -0500 | [diff] [blame] | 688 | struct bcm_phs_entry *pstServiceFlowEntry = NULL; |
Kevin McKinney | a903d65 | 2012-12-20 00:31:34 -0500 | [diff] [blame] | 689 | struct bcm_phs_rule *pstPhsRule = NULL; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 690 | UINT phsi; |
Kevin McKinney | 2979460 | 2012-05-26 12:05:12 -0400 | [diff] [blame] | 691 | struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 692 | struct bcm_phs_extension *pDeviceExtension = (struct bcm_phs_extension *)pvContext; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 693 | |
| 694 | *pInHeaderSize = 0; |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 695 | if (pDeviceExtension == NULL) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 696 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL, "Invalid Device Extension\n"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 697 | return ERR_PHS_INVALID_DEVICE_EXETENSION; |
| 698 | } |
| 699 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 700 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL, "Restoring header\n"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 701 | |
| 702 | phsi = *((unsigned char *)(pvInputBuffer)); |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 703 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL, "PHSI To Be Used For restore : %x\n", phsi); |
| 704 | if (phsi == UNCOMPRESSED_PACKET) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 705 | return STATUS_PHS_NOCOMPRESSION; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 706 | |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 707 | /* Retrieve the SFID Entry Index for requested Service Flow */ |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 708 | nSFIndex = GetServiceFlowEntry(pDeviceExtension->pstServiceFlowPhsRulesTable, |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 709 | uiVcid, &pstServiceFlowEntry); |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 710 | if (nSFIndex == PHS_INVALID_TABLE_INDEX) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 711 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL, "SFID Match Failed During Lookup\n"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 712 | return ERR_SF_MATCH_FAIL; |
| 713 | } |
| 714 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 715 | nPhsRuleIndex = GetPhsRuleEntry(pstServiceFlowEntry->pstClassifierTable, phsi, |
| 716 | eActiveClassifierRuleContext, &pstPhsRule); |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 717 | if (nPhsRuleIndex == PHS_INVALID_TABLE_INDEX) { |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 718 | /* Phs Rule does not exist in active rules table. Lets try in the old rules table. */ |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 719 | nPhsRuleIndex = GetPhsRuleEntry(pstServiceFlowEntry->pstClassifierTable, |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 720 | phsi, eOldClassifierRuleContext, &pstPhsRule); |
| 721 | if (nPhsRuleIndex == PHS_INVALID_TABLE_INDEX) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 722 | return ERR_PHSRULE_MATCH_FAIL; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | *pInHeaderSize = phs_decompress((PUCHAR)pvInputBuffer, |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 726 | (PUCHAR)pvOutputBuffer, pstPhsRule, pOutHeaderSize); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 727 | |
| 728 | pstPhsRule->PHSModifiedBytes += *pOutHeaderSize - *pInHeaderSize - 1; |
| 729 | |
| 730 | pstPhsRule->PHSModifiedNumPackets++; |
| 731 | return STATUS_PHS_COMPRESSED; |
| 732 | } |
| 733 | |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 734 | /* |
| 735 | * Procedure: free_phs_serviceflow_rules |
| 736 | * |
| 737 | * Description: This routine is responsible for freeing memory allocated for PHS rules. |
| 738 | * |
| 739 | * Arguments: |
| 740 | * rules - ptr to S_SERVICEFLOW_TABLE structure. |
| 741 | * |
| 742 | * Returns: |
| 743 | * Does not return any value. |
| 744 | */ |
Kevin McKinney | da4d150 | 2012-12-20 00:31:29 -0500 | [diff] [blame] | 745 | static void free_phs_serviceflow_rules(struct bcm_phs_table *psServiceFlowRulesTable) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 746 | { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 747 | int i, j; |
Kevin McKinney | 2979460 | 2012-05-26 12:05:12 -0400 | [diff] [blame] | 748 | struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 749 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 750 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "=======>\n"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 751 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 752 | if (psServiceFlowRulesTable) { |
| 753 | for (i = 0; i < MAX_SERVICEFLOWS; i++) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 754 | struct bcm_phs_entry stServiceFlowEntry = psServiceFlowRulesTable->stSFList[i]; |
| 755 | struct bcm_phs_classifier_table *pstClassifierRulesTable = stServiceFlowEntry.pstClassifierTable; |
| 756 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 757 | if (pstClassifierRulesTable) { |
| 758 | for (j = 0; j < MAX_PHSRULE_PER_SF; j++) { |
| 759 | if (pstClassifierRulesTable->stActivePhsRulesList[j].pstPhsRule) { |
| 760 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 761 | if (pstClassifierRulesTable->stActivePhsRulesList[j].pstPhsRule->u8RefCnt) |
| 762 | pstClassifierRulesTable->stActivePhsRulesList[j].pstPhsRule->u8RefCnt--; |
| 763 | |
| 764 | if (0 == pstClassifierRulesTable->stActivePhsRulesList[j].pstPhsRule->u8RefCnt) |
Stephen Hemminger | 082e889 | 2010-11-01 09:35:21 -0400 | [diff] [blame] | 765 | kfree(pstClassifierRulesTable->stActivePhsRulesList[j].pstPhsRule); |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 766 | |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 767 | pstClassifierRulesTable->stActivePhsRulesList[j].pstPhsRule = NULL; |
| 768 | } |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 769 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 770 | if (pstClassifierRulesTable->stOldPhsRulesList[j].pstPhsRule) { |
| 771 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 772 | if (pstClassifierRulesTable->stOldPhsRulesList[j].pstPhsRule->u8RefCnt) |
| 773 | pstClassifierRulesTable->stOldPhsRulesList[j].pstPhsRule->u8RefCnt--; |
| 774 | |
| 775 | if (0 == pstClassifierRulesTable->stOldPhsRulesList[j].pstPhsRule->u8RefCnt) |
Stephen Hemminger | 082e889 | 2010-11-01 09:35:21 -0400 | [diff] [blame] | 776 | kfree(pstClassifierRulesTable->stOldPhsRulesList[j].pstPhsRule); |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 777 | |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 778 | pstClassifierRulesTable->stOldPhsRulesList[j].pstPhsRule = NULL; |
| 779 | } |
| 780 | } |
Stephen Hemminger | 082e889 | 2010-11-01 09:35:21 -0400 | [diff] [blame] | 781 | kfree(pstClassifierRulesTable); |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 782 | stServiceFlowEntry.pstClassifierTable = pstClassifierRulesTable = NULL; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 783 | } |
| 784 | } |
| 785 | } |
| 786 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 787 | kfree(psServiceFlowRulesTable); |
| 788 | psServiceFlowRulesTable = NULL; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 789 | } |
| 790 | |
Lisa Nguyen | 3abd6f1 | 2013-10-28 01:35:59 -0700 | [diff] [blame] | 791 | static bool ValidatePHSRuleComplete(IN struct bcm_phs_rule *psPhsRule) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 792 | { |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 793 | if (psPhsRule) { |
| 794 | if (!psPhsRule->u8PHSI) { |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 795 | /* PHSI is not valid */ |
Lisa Nguyen | f70c8a9 | 2013-10-28 01:36:19 -0700 | [diff] [blame] | 796 | return false; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 797 | } |
| 798 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 799 | if (!psPhsRule->u8PHSS) { |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 800 | /* PHSS Is Undefined */ |
Lisa Nguyen | f70c8a9 | 2013-10-28 01:36:19 -0700 | [diff] [blame] | 801 | return false; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 802 | } |
| 803 | |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 804 | /* Check if PHSF is defines for the PHS Rule */ |
| 805 | if (!psPhsRule->u8PHSFLength) /* If any part of PHSF is valid then Rule contains valid PHSF */ |
Lisa Nguyen | f70c8a9 | 2013-10-28 01:36:19 -0700 | [diff] [blame] | 806 | return false; |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 807 | |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 808 | return TRUE; |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 809 | } else |
Lisa Nguyen | f70c8a9 | 2013-10-28 01:36:19 -0700 | [diff] [blame] | 810 | return false; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 811 | } |
| 812 | |
Kevin McKinney | da4d150 | 2012-12-20 00:31:29 -0500 | [diff] [blame] | 813 | UINT GetServiceFlowEntry(IN struct bcm_phs_table *psServiceFlowTable, |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 814 | IN B_UINT16 uiVcid, |
| 815 | struct bcm_phs_entry **ppstServiceFlowEntry) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 816 | { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 817 | int i; |
| 818 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 819 | for (i = 0; i < MAX_SERVICEFLOWS; i++) { |
| 820 | if (psServiceFlowTable->stSFList[i].bUsed) { |
| 821 | if (psServiceFlowTable->stSFList[i].uiVcid == uiVcid) { |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 822 | *ppstServiceFlowEntry = &psServiceFlowTable->stSFList[i]; |
| 823 | return i; |
| 824 | } |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | *ppstServiceFlowEntry = NULL; |
| 829 | return PHS_INVALID_TABLE_INDEX; |
| 830 | } |
| 831 | |
Shalin Mehta | f2be635 | 2013-09-17 00:42:17 -0700 | [diff] [blame] | 832 | static UINT GetClassifierEntry(IN struct bcm_phs_classifier_table *pstClassifierTable, |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 833 | IN B_UINT32 uiClsid, enum bcm_phs_classifier_context eClsContext, |
| 834 | OUT struct bcm_phs_classifier_entry **ppstClassifierEntry) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 835 | { |
| 836 | int i; |
Kevin McKinney | 2212e93 | 2012-12-20 00:31:32 -0500 | [diff] [blame] | 837 | struct bcm_phs_classifier_entry *psClassifierRules = NULL; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 838 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 839 | for (i = 0; i < MAX_PHSRULE_PER_SF; i++) { |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 840 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 841 | if (eClsContext == eActiveClassifierRuleContext) |
| 842 | psClassifierRules = &pstClassifierTable->stActivePhsRulesList[i]; |
| 843 | else |
| 844 | psClassifierRules = &pstClassifierTable->stOldPhsRulesList[i]; |
| 845 | |
| 846 | if (psClassifierRules->bUsed) { |
| 847 | if (psClassifierRules->uiClassifierRuleId == uiClsid) { |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 848 | *ppstClassifierEntry = psClassifierRules; |
| 849 | return i; |
| 850 | } |
| 851 | } |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | *ppstClassifierEntry = NULL; |
| 855 | return PHS_INVALID_TABLE_INDEX; |
| 856 | } |
| 857 | |
Kevin McKinney | a700dbd | 2012-12-20 00:31:31 -0500 | [diff] [blame] | 858 | static UINT GetPhsRuleEntry(IN struct bcm_phs_classifier_table *pstClassifierTable, |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 859 | IN B_UINT32 uiPHSI, enum bcm_phs_classifier_context eClsContext, |
| 860 | OUT struct bcm_phs_rule **ppstPhsRule) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 861 | { |
| 862 | int i; |
Kevin McKinney | 2212e93 | 2012-12-20 00:31:32 -0500 | [diff] [blame] | 863 | struct bcm_phs_classifier_entry *pstClassifierRule = NULL; |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 864 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 865 | for (i = 0; i < MAX_PHSRULE_PER_SF; i++) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 866 | if (eClsContext == eActiveClassifierRuleContext) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 867 | pstClassifierRule = &pstClassifierTable->stActivePhsRulesList[i]; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 868 | else |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 869 | pstClassifierRule = &pstClassifierTable->stOldPhsRulesList[i]; |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 870 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 871 | if (pstClassifierRule->bUsed) { |
| 872 | if (pstClassifierRule->u8PHSI == uiPHSI) { |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 873 | *ppstPhsRule = pstClassifierRule->pstPhsRule; |
| 874 | return i; |
| 875 | } |
| 876 | } |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | *ppstPhsRule = NULL; |
| 880 | return PHS_INVALID_TABLE_INDEX; |
| 881 | } |
| 882 | |
Shalin Mehta | f2be635 | 2013-09-17 00:42:17 -0700 | [diff] [blame] | 883 | static UINT CreateSFToClassifierRuleMapping(IN B_UINT16 uiVcid, IN B_UINT16 uiClsId, |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 884 | IN struct bcm_phs_table *psServiceFlowTable, |
| 885 | struct bcm_phs_rule *psPhsRule, |
| 886 | B_UINT8 u8AssociatedPHSI) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 887 | { |
Kevin McKinney | a700dbd | 2012-12-20 00:31:31 -0500 | [diff] [blame] | 888 | struct bcm_phs_classifier_table *psaClassifiertable = NULL; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 889 | UINT uiStatus = 0; |
| 890 | int iSfIndex; |
Lisa Nguyen | f70c8a9 | 2013-10-28 01:36:19 -0700 | [diff] [blame] | 891 | bool bFreeEntryFound = false; |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 892 | |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 893 | /* Check for a free entry in SFID table */ |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 894 | for (iSfIndex = 0; iSfIndex < MAX_SERVICEFLOWS; iSfIndex++) { |
| 895 | if (!psServiceFlowTable->stSFList[iSfIndex].bUsed) { |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 896 | bFreeEntryFound = TRUE; |
| 897 | break; |
| 898 | } |
| 899 | } |
| 900 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 901 | if (!bFreeEntryFound) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 902 | return ERR_SFTABLE_FULL; |
| 903 | |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 904 | psaClassifiertable = psServiceFlowTable->stSFList[iSfIndex].pstClassifierTable; |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 905 | uiStatus = CreateClassifierPHSRule(uiClsId, psaClassifiertable, psPhsRule, |
| 906 | eActiveClassifierRuleContext, u8AssociatedPHSI); |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 907 | if (uiStatus == PHS_SUCCESS) { |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 908 | /* Add entry at free index to the SF */ |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 909 | psServiceFlowTable->stSFList[iSfIndex].bUsed = TRUE; |
| 910 | psServiceFlowTable->stSFList[iSfIndex].uiVcid = uiVcid; |
| 911 | } |
| 912 | |
| 913 | return uiStatus; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 914 | } |
| 915 | |
Shalin Mehta | f2be635 | 2013-09-17 00:42:17 -0700 | [diff] [blame] | 916 | static UINT CreateClassiferToPHSRuleMapping(IN B_UINT16 uiVcid, |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 917 | IN B_UINT16 uiClsId, |
| 918 | IN struct bcm_phs_entry *pstServiceFlowEntry, |
| 919 | struct bcm_phs_rule *psPhsRule, |
| 920 | B_UINT8 u8AssociatedPHSI) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 921 | { |
Kevin McKinney | 2212e93 | 2012-12-20 00:31:32 -0500 | [diff] [blame] | 922 | struct bcm_phs_classifier_entry *pstClassifierEntry = NULL; |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 923 | UINT uiStatus = PHS_SUCCESS; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 924 | UINT nClassifierIndex = 0; |
Kevin McKinney | a700dbd | 2012-12-20 00:31:31 -0500 | [diff] [blame] | 925 | struct bcm_phs_classifier_table *psaClassifiertable = NULL; |
Kevin McKinney | 2979460 | 2012-05-26 12:05:12 -0400 | [diff] [blame] | 926 | struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 927 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 928 | psaClassifiertable = pstServiceFlowEntry->pstClassifierTable; |
| 929 | |
| 930 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "==>"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 931 | |
| 932 | /* Check if the supplied Classifier already exists */ |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 933 | nClassifierIndex = GetClassifierEntry( |
| 934 | pstServiceFlowEntry->pstClassifierTable, |
| 935 | uiClsId, |
| 936 | eActiveClassifierRuleContext, |
| 937 | &pstClassifierEntry); |
| 938 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 939 | if (nClassifierIndex == PHS_INVALID_TABLE_INDEX) { |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 940 | /* |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 941 | * The Classifier doesn't exist. So its a new classifier being added. |
| 942 | * Add new entry to associate PHS Rule to the Classifier |
| 943 | */ |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 944 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 945 | uiStatus = CreateClassifierPHSRule(uiClsId, psaClassifiertable, |
| 946 | psPhsRule, |
| 947 | eActiveClassifierRuleContext, |
| 948 | u8AssociatedPHSI); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 949 | return uiStatus; |
| 950 | } |
| 951 | |
| 952 | /* |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 953 | * The Classifier exists.The PHS Rule for this classifier |
| 954 | * is being modified |
| 955 | */ |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 956 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 957 | if (pstClassifierEntry->u8PHSI == psPhsRule->u8PHSI) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 958 | if (pstClassifierEntry->pstPhsRule == NULL) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 959 | return ERR_PHS_INVALID_PHS_RULE; |
| 960 | |
| 961 | /* |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 962 | * This rule already exists if any fields are changed for this PHS |
| 963 | * rule update them. |
| 964 | */ |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 965 | /* If any part of PHSF is valid then we update PHSF */ |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 966 | if (psPhsRule->u8PHSFLength) { |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 967 | /* update PHSF */ |
Stephen Hemminger | 082e889 | 2010-11-01 09:35:21 -0400 | [diff] [blame] | 968 | memcpy(pstClassifierEntry->pstPhsRule->u8PHSF, |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 969 | psPhsRule->u8PHSF, MAX_PHS_LENGTHS); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 970 | } |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 971 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 972 | if (psPhsRule->u8PHSFLength) { |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 973 | /* update PHSFLen */ |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 974 | pstClassifierEntry->pstPhsRule->u8PHSFLength = psPhsRule->u8PHSFLength; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 975 | } |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 976 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 977 | if (psPhsRule->u8PHSMLength) { |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 978 | /* update PHSM */ |
Stephen Hemminger | 082e889 | 2010-11-01 09:35:21 -0400 | [diff] [blame] | 979 | memcpy(pstClassifierEntry->pstPhsRule->u8PHSM, |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 980 | psPhsRule->u8PHSM, MAX_PHS_LENGTHS); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 981 | } |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 982 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 983 | if (psPhsRule->u8PHSMLength) { |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 984 | /* update PHSM Len */ |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 985 | pstClassifierEntry->pstPhsRule->u8PHSMLength = |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 986 | psPhsRule->u8PHSMLength; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 987 | } |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 988 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 989 | if (psPhsRule->u8PHSS) { |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 990 | /* update PHSS */ |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 991 | pstClassifierEntry->pstPhsRule->u8PHSS = psPhsRule->u8PHSS; |
| 992 | } |
| 993 | |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 994 | /* update PHSV */ |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 995 | pstClassifierEntry->pstPhsRule->u8PHSV = psPhsRule->u8PHSV; |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 996 | } else { |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 997 | /* A new rule is being set for this classifier. */ |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 998 | uiStatus = UpdateClassifierPHSRule(uiClsId, pstClassifierEntry, |
| 999 | psaClassifiertable, psPhsRule, u8AssociatedPHSI); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1000 | } |
| 1001 | |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1002 | return uiStatus; |
| 1003 | } |
| 1004 | |
Stephen Hemminger | 9dd47ee | 2010-11-01 12:24:00 -0400 | [diff] [blame] | 1005 | static UINT CreateClassifierPHSRule(IN B_UINT16 uiClsId, |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1006 | struct bcm_phs_classifier_table *psaClassifiertable, |
| 1007 | struct bcm_phs_rule *psPhsRule, |
| 1008 | enum bcm_phs_classifier_context eClsContext, |
| 1009 | B_UINT8 u8AssociatedPHSI) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1010 | { |
| 1011 | UINT iClassifierIndex = 0; |
Lisa Nguyen | f70c8a9 | 2013-10-28 01:36:19 -0700 | [diff] [blame] | 1012 | bool bFreeEntryFound = false; |
Kevin McKinney | 2212e93 | 2012-12-20 00:31:32 -0500 | [diff] [blame] | 1013 | struct bcm_phs_classifier_entry *psClassifierRules = NULL; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1014 | UINT nStatus = PHS_SUCCESS; |
Kevin McKinney | 2979460 | 2012-05-26 12:05:12 -0400 | [diff] [blame] | 1015 | struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1016 | |
| 1017 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "Inside CreateClassifierPHSRule"); |
| 1018 | |
| 1019 | if (psaClassifiertable == NULL) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1020 | return ERR_INVALID_CLASSIFIERTABLE_FOR_SF; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1021 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1022 | if (eClsContext == eOldClassifierRuleContext) { |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 1023 | /* |
| 1024 | * If An Old Entry for this classifier ID already exists in the |
| 1025 | * old rules table replace it. |
| 1026 | */ |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1027 | |
| 1028 | iClassifierIndex = |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1029 | GetClassifierEntry(psaClassifiertable, uiClsId, |
| 1030 | eClsContext, &psClassifierRules); |
| 1031 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1032 | if (iClassifierIndex != PHS_INVALID_TABLE_INDEX) { |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1033 | /* |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 1034 | * The Classifier already exists in the old rules table |
| 1035 | * Lets replace the old classifier with the new one. |
| 1036 | */ |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1037 | bFreeEntryFound = TRUE; |
| 1038 | } |
| 1039 | } |
| 1040 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1041 | if (!bFreeEntryFound) { |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 1042 | /* Continue to search for a free location to add the rule */ |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1043 | for (iClassifierIndex = 0; iClassifierIndex < |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1044 | MAX_PHSRULE_PER_SF; iClassifierIndex++) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1045 | if (eClsContext == eActiveClassifierRuleContext) |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1046 | psClassifierRules = &psaClassifiertable->stActivePhsRulesList[iClassifierIndex]; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1047 | else |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1048 | psClassifierRules = &psaClassifiertable->stOldPhsRulesList[iClassifierIndex]; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1049 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1050 | if (!psClassifierRules->bUsed) { |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1051 | bFreeEntryFound = TRUE; |
| 1052 | break; |
| 1053 | } |
| 1054 | } |
| 1055 | } |
| 1056 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1057 | if (!bFreeEntryFound) { |
| 1058 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1059 | if (eClsContext == eActiveClassifierRuleContext) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1060 | return ERR_CLSASSIFIER_TABLE_FULL; |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1061 | else { |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 1062 | /* Lets replace the oldest rule if we are looking in old Rule table */ |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1063 | if (psaClassifiertable->uiOldestPhsRuleIndex >= MAX_PHSRULE_PER_SF) |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1064 | psaClassifiertable->uiOldestPhsRuleIndex = 0; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1065 | |
| 1066 | iClassifierIndex = psaClassifiertable->uiOldestPhsRuleIndex; |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1067 | psClassifierRules = &psaClassifiertable->stOldPhsRulesList[iClassifierIndex]; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1068 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1069 | (psaClassifiertable->uiOldestPhsRuleIndex)++; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1070 | } |
| 1071 | } |
| 1072 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1073 | if (eClsContext == eOldClassifierRuleContext) { |
| 1074 | |
| 1075 | if (psClassifierRules->pstPhsRule == NULL) { |
| 1076 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1077 | psClassifierRules->pstPhsRule = kmalloc(sizeof(struct bcm_phs_rule), GFP_KERNEL); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1078 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1079 | if (NULL == psClassifierRules->pstPhsRule) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1080 | return ERR_PHSRULE_MEMALLOC_FAIL; |
| 1081 | } |
| 1082 | |
| 1083 | psClassifierRules->bUsed = TRUE; |
| 1084 | psClassifierRules->uiClassifierRuleId = uiClsId; |
| 1085 | psClassifierRules->u8PHSI = psPhsRule->u8PHSI; |
| 1086 | psClassifierRules->bUnclassifiedPHSRule = psPhsRule->bUnclassifiedPHSRule; |
| 1087 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1088 | /* Update The PHS rule */ |
| 1089 | memcpy(psClassifierRules->pstPhsRule, psPhsRule, sizeof(struct bcm_phs_rule)); |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1090 | } else |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1091 | nStatus = UpdateClassifierPHSRule(uiClsId, psClassifierRules, |
| 1092 | psaClassifiertable, psPhsRule, u8AssociatedPHSI); |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1093 | |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1094 | return nStatus; |
| 1095 | } |
| 1096 | |
Stephen Hemminger | 9dd47ee | 2010-11-01 12:24:00 -0400 | [diff] [blame] | 1097 | static UINT UpdateClassifierPHSRule(IN B_UINT16 uiClsId, |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1098 | IN struct bcm_phs_classifier_entry *pstClassifierEntry, |
| 1099 | struct bcm_phs_classifier_table *psaClassifiertable, |
| 1100 | struct bcm_phs_rule *psPhsRule, |
| 1101 | B_UINT8 u8AssociatedPHSI) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1102 | { |
Kevin McKinney | a903d65 | 2012-12-20 00:31:34 -0500 | [diff] [blame] | 1103 | struct bcm_phs_rule *pstAddPhsRule = NULL; |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1104 | UINT nPhsRuleIndex = 0; |
Lisa Nguyen | f70c8a9 | 2013-10-28 01:36:19 -0700 | [diff] [blame] | 1105 | bool bPHSRuleOrphaned = false; |
Kevin McKinney | 2979460 | 2012-05-26 12:05:12 -0400 | [diff] [blame] | 1106 | struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1107 | |
| 1108 | psPhsRule->u8RefCnt = 0; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1109 | |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 1110 | /* Step 1 Deref Any Exisiting PHS Rule in this classifier Entry */ |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1111 | bPHSRuleOrphaned = DerefPhsRule(uiClsId, psaClassifiertable, |
| 1112 | pstClassifierEntry->pstPhsRule); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1113 | |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 1114 | /* Step 2 Search if there is a PHS Rule with u8AssociatedPHSI in Classifier table for this SF */ |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1115 | nPhsRuleIndex = GetPhsRuleEntry(psaClassifiertable, u8AssociatedPHSI, |
| 1116 | eActiveClassifierRuleContext, &pstAddPhsRule); |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1117 | if (PHS_INVALID_TABLE_INDEX == nPhsRuleIndex) { |
| 1118 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1119 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nAdding New PHSRuleEntry For Classifier"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1120 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1121 | if (psPhsRule->u8PHSI == 0) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1122 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nError PHSI is Zero\n"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1123 | return ERR_PHS_INVALID_PHS_RULE; |
| 1124 | } |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1125 | |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 1126 | /* Step 2.a PHS Rule Does Not Exist .Create New PHS Rule for uiClsId */ |
Lisa Nguyen | f70c8a9 | 2013-10-28 01:36:19 -0700 | [diff] [blame] | 1127 | if (false == bPHSRuleOrphaned) { |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1128 | |
Kevin McKinney | a903d65 | 2012-12-20 00:31:34 -0500 | [diff] [blame] | 1129 | pstClassifierEntry->pstPhsRule = kmalloc(sizeof(struct bcm_phs_rule), GFP_KERNEL); |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1130 | if (NULL == pstClassifierEntry->pstPhsRule) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1131 | return ERR_PHSRULE_MEMALLOC_FAIL; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1132 | } |
Kevin McKinney | a903d65 | 2012-12-20 00:31:34 -0500 | [diff] [blame] | 1133 | memcpy(pstClassifierEntry->pstPhsRule, psPhsRule, sizeof(struct bcm_phs_rule)); |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1134 | } else { |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 1135 | /* Step 2.b PHS Rule Exists Tie uiClsId with the existing PHS Rule */ |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1136 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nTying Classifier to Existing PHS Rule"); |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1137 | if (bPHSRuleOrphaned) { |
Stephen Hemminger | 082e889 | 2010-11-01 09:35:21 -0400 | [diff] [blame] | 1138 | kfree(pstClassifierEntry->pstPhsRule); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1139 | pstClassifierEntry->pstPhsRule = NULL; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1140 | } |
| 1141 | pstClassifierEntry->pstPhsRule = pstAddPhsRule; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1142 | } |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1143 | |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1144 | pstClassifierEntry->bUsed = TRUE; |
| 1145 | pstClassifierEntry->u8PHSI = pstClassifierEntry->pstPhsRule->u8PHSI; |
| 1146 | pstClassifierEntry->uiClassifierRuleId = uiClsId; |
| 1147 | pstClassifierEntry->pstPhsRule->u8RefCnt++; |
| 1148 | pstClassifierEntry->bUnclassifiedPHSRule = pstClassifierEntry->pstPhsRule->bUnclassifiedPHSRule; |
| 1149 | |
| 1150 | return PHS_SUCCESS; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1151 | } |
| 1152 | |
Lisa Nguyen | 3abd6f1 | 2013-10-28 01:35:59 -0700 | [diff] [blame] | 1153 | static bool DerefPhsRule(IN B_UINT16 uiClsId, struct bcm_phs_classifier_table *psaClassifiertable, struct bcm_phs_rule *pstPhsRule) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1154 | { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1155 | if (pstPhsRule == NULL) |
Lisa Nguyen | f70c8a9 | 2013-10-28 01:36:19 -0700 | [diff] [blame] | 1156 | return false; |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1157 | |
| 1158 | if (pstPhsRule->u8RefCnt) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1159 | pstPhsRule->u8RefCnt--; |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1160 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1161 | if (0 == pstPhsRule->u8RefCnt) { |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 1162 | /* |
| 1163 | * if(pstPhsRule->u8PHSI) |
| 1164 | * Store the currently active rule into the old rules list |
| 1165 | * CreateClassifierPHSRule(uiClsId,psaClassifiertable,pstPhsRule,eOldClassifierRuleContext,pstPhsRule->u8PHSI); |
| 1166 | */ |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1167 | return TRUE; |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1168 | } else |
Lisa Nguyen | f70c8a9 | 2013-10-28 01:36:19 -0700 | [diff] [blame] | 1169 | return false; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1170 | } |
| 1171 | |
Kevin McKinney | 60dadf9 | 2012-12-20 00:31:28 -0500 | [diff] [blame] | 1172 | void DumpPhsRules(struct bcm_phs_extension *pDeviceExtension) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1173 | { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1174 | int i, j, k, l; |
Kevin McKinney | 2979460 | 2012-05-26 12:05:12 -0400 | [diff] [blame] | 1175 | struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1176 | |
| 1177 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\n Dumping PHS Rules :\n"); |
| 1178 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1179 | for (i = 0; i < MAX_SERVICEFLOWS; i++) { |
| 1180 | |
Kevin McKinney | db134a6 | 2012-12-20 00:31:30 -0500 | [diff] [blame] | 1181 | struct bcm_phs_entry stServFlowEntry = |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1182 | pDeviceExtension->pstServiceFlowPhsRulesTable->stSFList[i]; |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1183 | if (stServFlowEntry.bUsed) { |
| 1184 | |
| 1185 | for (j = 0; j < MAX_PHSRULE_PER_SF; j++) { |
| 1186 | |
| 1187 | for (l = 0; l < 2; l++) { |
Kevin McKinney | 2212e93 | 2012-12-20 00:31:32 -0500 | [diff] [blame] | 1188 | struct bcm_phs_classifier_entry stClsEntry; |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1189 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1190 | if (l == 0) { |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1191 | stClsEntry = stServFlowEntry.pstClassifierTable->stActivePhsRulesList[j]; |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1192 | if (stClsEntry.bUsed) |
| 1193 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n Active PHS Rule :\n"); |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1194 | } else { |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1195 | stClsEntry = stServFlowEntry.pstClassifierTable->stOldPhsRulesList[j]; |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1196 | if (stClsEntry.bUsed) |
| 1197 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n Old PHS Rule :\n"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1198 | } |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1199 | |
| 1200 | if (stClsEntry.bUsed) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1201 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\n VCID : %#X", stServFlowEntry.uiVcid); |
| 1202 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n ClassifierID : %#X", stClsEntry.uiClassifierRuleId); |
| 1203 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSRuleID : %#X", stClsEntry.u8PHSI); |
| 1204 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n****************PHS Rule********************\n"); |
| 1205 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSI : %#X", stClsEntry.pstPhsRule->u8PHSI); |
| 1206 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSFLength : %#X ", stClsEntry.pstPhsRule->u8PHSFLength); |
| 1207 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSF : "); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1208 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1209 | for (k = 0 ; k < stClsEntry.pstPhsRule->u8PHSFLength; k++) |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1210 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "%#X ", stClsEntry.pstPhsRule->u8PHSF[k]); |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1211 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSMLength : %#X", stClsEntry.pstPhsRule->u8PHSMLength); |
| 1212 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSM :"); |
| 1213 | |
| 1214 | for (k = 0; k < stClsEntry.pstPhsRule->u8PHSMLength; k++) |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1215 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "%#X ", stClsEntry.pstPhsRule->u8PHSM[k]); |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1216 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSS : %#X ", stClsEntry.pstPhsRule->u8PHSS); |
| 1217 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSV : %#X", stClsEntry.pstPhsRule->u8PHSV); |
| 1218 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\n********************************************\n"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1219 | } |
| 1220 | } |
| 1221 | } |
| 1222 | } |
| 1223 | } |
| 1224 | } |
| 1225 | |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 1226 | /* |
| 1227 | * Procedure: phs_decompress |
| 1228 | * |
| 1229 | * Description: This routine restores the static fields within the packet. |
| 1230 | * |
| 1231 | * Arguments: |
| 1232 | * in_buf - ptr to incoming packet buffer. |
| 1233 | * out_buf - ptr to output buffer where the suppressed header is copied. |
| 1234 | * decomp_phs_rules - ptr to PHS rule. |
| 1235 | * header_size - ptr to field which holds the phss or phsf_length. |
| 1236 | * |
| 1237 | * Returns: |
| 1238 | * size -The number of bytes of dynamic fields present with in the incoming packet |
| 1239 | * header. |
| 1240 | * 0 -If PHS rule is NULL.If PHSI is 0 indicateing packet as uncompressed. |
| 1241 | */ |
Shalin Mehta | f2be635 | 2013-09-17 00:42:17 -0700 | [diff] [blame] | 1242 | static int phs_decompress(unsigned char *in_buf, |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1243 | unsigned char *out_buf, |
| 1244 | struct bcm_phs_rule *decomp_phs_rules, |
| 1245 | UINT *header_size) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1246 | { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1247 | int phss, size = 0; |
Kevin McKinney | a903d65 | 2012-12-20 00:31:34 -0500 | [diff] [blame] | 1248 | struct bcm_phs_rule *tmp_memb; |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1249 | int bit, i = 0; |
| 1250 | unsigned char *phsf, *phsm; |
| 1251 | int in_buf_len = *header_size - 1; |
Kevin McKinney | 2979460 | 2012-05-26 12:05:12 -0400 | [diff] [blame] | 1252 | struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1253 | |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1254 | in_buf++; |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1255 | |
| 1256 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL, "====>\n"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1257 | *header_size = 0; |
| 1258 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1259 | if ((decomp_phs_rules == NULL)) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1260 | return 0; |
| 1261 | |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1262 | tmp_memb = decomp_phs_rules; |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 1263 | /* |
| 1264 | * BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_RECEIVE,DBG_LVL_ALL,"\nDECOMP:In phs_decompress PHSI 1 %d",phsi)); |
| 1265 | * header_size = tmp_memb->u8PHSFLength; |
| 1266 | */ |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1267 | phss = tmp_memb->u8PHSS; |
| 1268 | phsf = tmp_memb->u8PHSF; |
| 1269 | phsm = tmp_memb->u8PHSM; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1270 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1271 | if (phss > MAX_PHS_LENGTHS) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1272 | phss = MAX_PHS_LENGTHS; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1273 | |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 1274 | /* |
| 1275 | * BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_RECEIVE,DBG_LVL_ALL,"\nDECOMP: |
| 1276 | * In phs_decompress PHSI %d phss %d index %d",phsi,phss,index)); |
| 1277 | */ |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1278 | while ((phss > 0) && (size < in_buf_len)) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1279 | bit = ((*phsm << i) & SUPPRESS); |
| 1280 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1281 | if (bit == SUPPRESS) { |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1282 | *out_buf = *phsf; |
Masanari Iida | 276d30e | 2014-01-11 11:26:27 +0900 | [diff] [blame] | 1283 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL, "\nDECOMP:In phss %d phsf %d output %d", |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1284 | phss, *phsf, *out_buf); |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1285 | } else { |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1286 | *out_buf = *in_buf; |
Masanari Iida | 276d30e | 2014-01-11 11:26:27 +0900 | [diff] [blame] | 1287 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL, "\nDECOMP:In phss %d input %d output %d", |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1288 | phss, *in_buf, *out_buf); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1289 | in_buf++; |
| 1290 | size++; |
| 1291 | } |
| 1292 | out_buf++; |
| 1293 | phsf++; |
| 1294 | phss--; |
| 1295 | i++; |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1296 | *header_size = *header_size + 1; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1297 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1298 | if (i > MAX_NO_BIT) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1299 | i = 0; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1300 | phsm++; |
| 1301 | } |
| 1302 | } |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1303 | |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1304 | return size; |
| 1305 | } |
| 1306 | |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 1307 | /* |
| 1308 | * Procedure: phs_compress |
| 1309 | * |
| 1310 | * Description: This routine suppresses the static fields within the packet.Before |
| 1311 | * that it will verify the fields to be suppressed with the corresponding fields in the |
| 1312 | * phsf. For verification it checks the phsv field of PHS rule. If set and verification |
| 1313 | * succeeds it suppresses the field.If any one static field is found different none of |
| 1314 | * the static fields are suppressed then the packet is sent as uncompressed packet with |
| 1315 | * phsi=0. |
| 1316 | * |
| 1317 | * Arguments: |
| 1318 | * phs_rule - ptr to PHS rule. |
| 1319 | * in_buf - ptr to incoming packet buffer. |
| 1320 | * out_buf - ptr to output buffer where the suppressed header is copied. |
| 1321 | * header_size - ptr to field which holds the phss. |
| 1322 | * |
| 1323 | * Returns: |
| 1324 | * size-The number of bytes copied into the output buffer i.e dynamic fields |
| 1325 | * 0 -If PHS rule is NULL.If PHSV field is not set.If the verification fails. |
| 1326 | */ |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1327 | static int phs_compress(struct bcm_phs_rule *phs_rule, |
| 1328 | unsigned char *in_buf, |
| 1329 | unsigned char *out_buf, |
| 1330 | UINT *header_size, |
| 1331 | UINT *new_header_size) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1332 | { |
| 1333 | unsigned char *old_addr = out_buf; |
Peter Meerwald | b38e274 | 2012-06-13 20:44:35 +0200 | [diff] [blame] | 1334 | int suppress = 0; |
Kevin McKinney | 2979460 | 2012-05-26 12:05:12 -0400 | [diff] [blame] | 1335 | struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1336 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1337 | if (phs_rule == NULL) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1338 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "\nphs_compress(): phs_rule null!"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1339 | *out_buf = ZERO_PHSI; |
| 1340 | return STATUS_PHS_NOCOMPRESSION; |
| 1341 | } |
| 1342 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1343 | if (phs_rule->u8PHSS <= *new_header_size) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1344 | *header_size = phs_rule->u8PHSS; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1345 | else |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1346 | *header_size = *new_header_size; |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1347 | |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 1348 | /* To copy PHSI */ |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1349 | out_buf++; |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1350 | suppress = verify_suppress_phsf(in_buf, out_buf, phs_rule->u8PHSF, |
| 1351 | phs_rule->u8PHSM, phs_rule->u8PHSS, |
| 1352 | phs_rule->u8PHSV, new_header_size); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1353 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1354 | if (suppress == STATUS_PHS_COMPRESSED) { |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1355 | *old_addr = (unsigned char)phs_rule->u8PHSI; |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1356 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "\nCOMP:In phs_compress phsi %d", phs_rule->u8PHSI); |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1357 | } else { |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1358 | *old_addr = ZERO_PHSI; |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1359 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "\nCOMP:In phs_compress PHSV Verification failed"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1360 | } |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1361 | |
Peter Meerwald | b38e274 | 2012-06-13 20:44:35 +0200 | [diff] [blame] | 1362 | return suppress; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1363 | } |
| 1364 | |
Kevin McKinney | 14b3a40 | 2013-02-20 23:25:29 -0500 | [diff] [blame] | 1365 | /* |
| 1366 | * Procedure: verify_suppress_phsf |
| 1367 | * |
| 1368 | * Description: This routine verifies the fields of the packet and if all the |
| 1369 | * static fields are equal it adds the phsi of that PHS rule.If any static |
| 1370 | * field differs it woun't suppress any field. |
| 1371 | * |
| 1372 | * Arguments: |
| 1373 | * rules_set - ptr to classifier_rules. |
| 1374 | * in_buffer - ptr to incoming packet buffer. |
| 1375 | * out_buffer - ptr to output buffer where the suppressed header is copied. |
| 1376 | * phsf - ptr to phsf. |
| 1377 | * phsm - ptr to phsm. |
| 1378 | * phss - variable holding phss. |
| 1379 | * |
| 1380 | * Returns: |
| 1381 | * size-The number of bytes copied into the output buffer i.e dynamic fields. |
| 1382 | * 0 -Packet has failed the verification. |
| 1383 | */ |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1384 | static int verify_suppress_phsf(unsigned char *in_buffer, |
| 1385 | unsigned char *out_buffer, |
| 1386 | unsigned char *phsf, |
| 1387 | unsigned char *phsm, |
| 1388 | unsigned int phss, |
| 1389 | unsigned int phsv, |
| 1390 | UINT *new_header_size) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1391 | { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1392 | unsigned int size = 0; |
| 1393 | int bit, i = 0; |
Kevin McKinney | 2979460 | 2012-05-26 12:05:12 -0400 | [diff] [blame] | 1394 | struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1395 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1396 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "\nCOMP:In verify_phsf PHSM - 0x%X", *phsm); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1397 | |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1398 | if (phss > (*new_header_size)) |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1399 | phss = *new_header_size; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1400 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1401 | while (phss > 0) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1402 | bit = ((*phsm << i) & SUPPRESS); |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1403 | if (bit == SUPPRESS) { |
| 1404 | if (*in_buffer != *phsf) { |
| 1405 | if (phsv == VERIFY) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1406 | BCM_DEBUG_PRINT(Adapter, |
| 1407 | DBG_TYPE_OTHERS, |
| 1408 | PHS_SEND, |
| 1409 | DBG_LVL_ALL, |
| 1410 | "\nCOMP:In verify_phsf failed for field %d buf %d phsf %d", |
| 1411 | phss, |
| 1412 | *in_buffer, |
| 1413 | *phsf); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1414 | return STATUS_PHS_NOCOMPRESSION; |
| 1415 | } |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1416 | } else |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1417 | BCM_DEBUG_PRINT(Adapter, |
| 1418 | DBG_TYPE_OTHERS, |
| 1419 | PHS_SEND, |
| 1420 | DBG_LVL_ALL, |
| 1421 | "\nCOMP:In verify_phsf success for field %d buf %d phsf %d", |
| 1422 | phss, |
| 1423 | *in_buffer, |
| 1424 | *phsf); |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1425 | } else { |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1426 | *out_buffer = *in_buffer; |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1427 | BCM_DEBUG_PRINT(Adapter, |
| 1428 | DBG_TYPE_OTHERS, |
| 1429 | PHS_SEND, |
| 1430 | DBG_LVL_ALL, |
| 1431 | "\nCOMP:In copying_header input %d out %d", |
| 1432 | *in_buffer, |
| 1433 | *out_buffer); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1434 | out_buffer++; |
| 1435 | size++; |
| 1436 | } |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1437 | |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1438 | in_buffer++; |
| 1439 | phsf++; |
| 1440 | phss--; |
| 1441 | i++; |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1442 | |
Kevin McKinney | 6949387 | 2013-02-20 23:25:28 -0500 | [diff] [blame] | 1443 | if (i > MAX_NO_BIT) { |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1444 | i = 0; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1445 | phsm++; |
| 1446 | } |
| 1447 | } |
Kevin McKinney | 6c259f4 | 2013-02-20 23:25:27 -0500 | [diff] [blame] | 1448 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "\nCOMP:In verify_phsf success"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1449 | *new_header_size = size; |
| 1450 | return STATUS_PHS_COMPRESSED; |
| 1451 | } |