2 * Copyright (C) 2013 Realtek Semiconductor Corp.
5 * Unless you and Realtek execute a separate written software license
6 * agreement governing use of this software, this software is licensed
7 * to you under the terms of the GNU General Public License version 2,
8 * available at https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
11 * $Date: 2017-03-08 15:13:58 +0800 (週三, 08 三月 2017) $
13 * Purpose : RTK switch high-level API for RTL8367/RTL8367C
14 * Feature : Here is a list of all functions and variables in Trunk module.
18 #include <rtk_switch.h>
19 #include <rtk_error.h>
23 #include <rtl8367c_asicdrv.h>
24 #include <rtl8367c_asicdrv_trunking.h>
29 * Set trunking group available port mask
31 * trk_gid - trunk group id
32 * pTrunk_member_portmask - Logic trunking member port mask
37 * RT_ERR_FAILED - Failed
38 * RT_ERR_SMI - SMI access error
39 * RT_ERR_LA_TRUNK_ID - Invalid trunking group
40 * RT_ERR_PORT_MASK - Invalid portmask.
42 * The API can set port trunking group port mask. Each port trunking group has max 4 ports.
43 * If enabled port mask has less than 2 ports available setting, then this trunking group function is disabled.
45 rtk_api_ret_t
rtk_trunk_port_set(rtk_trunk_group_t trk_gid
, rtk_portmask_t
*pTrunk_member_portmask
)
49 rtk_uint32 regValue
, type
, tmp
;
52 if((retVal
= rtl8367c_setAsicReg(0x13C2, 0x0249)) != RT_ERR_OK
)
55 if((retVal
= rtl8367c_getAsicReg(0x1300, ®Value
)) != RT_ERR_OK
)
58 if((retVal
= rtl8367c_setAsicReg(0x13C2, 0x0000)) != RT_ERR_OK
)
80 /* Check initialization state */
83 /* Check Trunk Group Valid */
84 RTK_CHK_TRUNK_GROUP_VALID(trk_gid
);
86 if(NULL
== pTrunk_member_portmask
)
87 return RT_ERR_NULL_POINTER
;
89 RTK_CHK_PORTMASK_VALID(pTrunk_member_portmask
);
91 if((retVal
= rtk_switch_portmask_L2P_get(pTrunk_member_portmask
, &pmsk
)) != RT_ERR_OK
)
94 if((type
== 0) || (type
== 1))
96 if ((pmsk
| RTL8367C_PORT_TRUNK_GROUP_MASK_MASK(trk_gid
)) != (rtk_uint32
)RTL8367C_PORT_TRUNK_GROUP_MASK_MASK(trk_gid
))
97 return RT_ERR_PORT_MASK
;
99 pmsk
= (pmsk
& RTL8367C_PORT_TRUNK_GROUP_MASK_MASK(trk_gid
)) >> RTL8367C_PORT_TRUNK_GROUP_MASK_OFFSET(trk_gid
);
115 if ((retVal
= rtl8367c_setAsicTrunkingGroup(trk_gid
, pmsk
)) != RT_ERR_OK
)
124 * Get trunking group available port mask
126 * trk_gid - trunk group id
128 * pTrunk_member_portmask - Logic trunking member port mask
131 * RT_ERR_FAILED - Failed
132 * RT_ERR_SMI - SMI access error
133 * RT_ERR_LA_TRUNK_ID - Invalid trunking group
135 * The API can get 2 port trunking group.
137 rtk_api_ret_t
rtk_trunk_port_get(rtk_trunk_group_t trk_gid
, rtk_portmask_t
*pTrunk_member_portmask
)
139 rtk_api_ret_t retVal
;
142 /* Check initialization state */
143 RTK_CHK_INIT_STATE();
145 /* Check Trunk Group Valid */
146 RTK_CHK_TRUNK_GROUP_VALID(trk_gid
);
148 if ((retVal
= rtl8367c_getAsicTrunkingGroup(trk_gid
, &pmsk
)) != RT_ERR_OK
)
151 pmsk
= pmsk
<< RTL8367C_PORT_TRUNK_GROUP_MASK_OFFSET(trk_gid
);
153 if((retVal
= rtk_switch_portmask_P2L_get(pmsk
, pTrunk_member_portmask
)) != RT_ERR_OK
)
160 * rtk_trunk_distributionAlgorithm_set
162 * Set port trunking hash select sources
164 * trk_gid - trunk group id
165 * algo_bitmask - Bitmask of the distribution algorithm
170 * RT_ERR_FAILED - Failed
171 * RT_ERR_SMI - SMI access error
172 * RT_ERR_LA_TRUNK_ID - Invalid trunking group
173 * RT_ERR_LA_HASHMASK - Hash algorithm selection error.
174 * RT_ERR_PORT_MASK - Invalid portmask.
176 * The API can set port trunking hash algorithm sources.
177 * 7 bits mask for link aggregation group0 hash parameter selection {DIP, SIP, DMAC, SMAC, SPA}
183 * - 0b0100000: TCP/UDP Source Port
184 * - 0b1000000: TCP/UDP Destination Port
186 * - 0b0000011: SMAC & SPA
187 * - Note that it could be an arbitrary combination or independent set
189 rtk_api_ret_t
rtk_trunk_distributionAlgorithm_set(rtk_trunk_group_t trk_gid
, rtk_uint32 algo_bitmask
)
191 rtk_api_ret_t retVal
;
193 /* Check initialization state */
194 RTK_CHK_INIT_STATE();
196 if (trk_gid
!= RTK_WHOLE_SYSTEM
)
197 return RT_ERR_LA_TRUNK_ID
;
199 if (algo_bitmask
>= 128)
200 return RT_ERR_LA_HASHMASK
;
202 if ((retVal
= rtl8367c_setAsicTrunkingHashSelect(algo_bitmask
)) != RT_ERR_OK
)
209 * rtk_trunk_distributionAlgorithm_get
211 * Get port trunking hash select sources
213 * trk_gid - trunk group id
215 * pAlgo_bitmask - Bitmask of the distribution algorithm
218 * RT_ERR_FAILED - Failed
219 * RT_ERR_SMI - SMI access error
220 * RT_ERR_LA_TRUNK_ID - Invalid trunking group
222 * The API can get port trunking hash algorithm sources.
224 rtk_api_ret_t
rtk_trunk_distributionAlgorithm_get(rtk_trunk_group_t trk_gid
, rtk_uint32
*pAlgo_bitmask
)
226 rtk_api_ret_t retVal
;
228 /* Check initialization state */
229 RTK_CHK_INIT_STATE();
231 if (trk_gid
!= RTK_WHOLE_SYSTEM
)
232 return RT_ERR_LA_TRUNK_ID
;
234 if(NULL
== pAlgo_bitmask
)
235 return RT_ERR_NULL_POINTER
;
237 if ((retVal
= rtl8367c_getAsicTrunkingHashSelect((rtk_uint32
*)pAlgo_bitmask
)) != RT_ERR_OK
)
244 * rtk_trunk_trafficSeparate_set
246 * Set the traffic separation setting of a trunk group from the specified device.
248 * trk_gid - trunk group id
249 * separateType - traffic separation setting
255 * RT_ERR_UNIT_ID - invalid unit id
256 * RT_ERR_LA_TRUNK_ID - invalid trunk ID
257 * RT_ERR_LA_HASHMASK - invalid hash mask
259 * SEPARATE_NONE: disable traffic separation
260 * SEPARATE_FLOOD: trunk MSB link up port is dedicated to TX flooding (L2 lookup miss) traffic
262 rtk_api_ret_t
rtk_trunk_trafficSeparate_set(rtk_trunk_group_t trk_gid
, rtk_trunk_separateType_t separateType
)
264 rtk_api_ret_t retVal
;
267 /* Check initialization state */
268 RTK_CHK_INIT_STATE();
270 if (trk_gid
!= RTK_WHOLE_SYSTEM
)
271 return RT_ERR_LA_TRUNK_ID
;
273 if(separateType
>= SEPARATE_END
)
276 enabled
= (separateType
== SEPARATE_FLOOD
) ? ENABLED
: DISABLED
;
277 if ((retVal
= rtl8367c_setAsicTrunkingFlood(enabled
)) != RT_ERR_OK
)
284 * rtk_trunk_trafficSeparate_get
286 * Get the traffic separation setting of a trunk group from the specified device.
288 * trk_gid - trunk group id
290 * pSeparateType - pointer separated traffic type
294 * RT_ERR_UNIT_ID - invalid unit id
295 * RT_ERR_LA_TRUNK_ID - invalid trunk ID
296 * RT_ERR_NULL_POINTER - input parameter may be null pointer
298 * SEPARATE_NONE: disable traffic separation
299 * SEPARATE_FLOOD: trunk MSB link up port is dedicated to TX flooding (L2 lookup miss) traffic
301 rtk_api_ret_t
rtk_trunk_trafficSeparate_get(rtk_trunk_group_t trk_gid
, rtk_trunk_separateType_t
*pSeparateType
)
303 rtk_api_ret_t retVal
;
306 /* Check initialization state */
307 RTK_CHK_INIT_STATE();
309 if (trk_gid
!= RTK_WHOLE_SYSTEM
)
310 return RT_ERR_LA_TRUNK_ID
;
312 if(NULL
== pSeparateType
)
313 return RT_ERR_NULL_POINTER
;
315 if ((retVal
= rtl8367c_getAsicTrunkingFlood(&enabled
)) != RT_ERR_OK
)
318 *pSeparateType
= (enabled
== ENABLED
) ? SEPARATE_FLOOD
: SEPARATE_NONE
;
325 * Set the trunk mode to the specified device.
333 * RT_ERR_INPUT - invalid input parameter
335 * The enum of the trunk mode as following
336 * - TRUNK_MODE_NORMAL
339 rtk_api_ret_t
rtk_trunk_mode_set(rtk_trunk_mode_t mode
)
341 rtk_api_ret_t retVal
;
343 /* Check initialization state */
344 RTK_CHK_INIT_STATE();
346 if(mode
>= TRUNK_MODE_END
)
349 if ((retVal
= rtl8367c_setAsicTrunkingMode((rtk_uint32
)mode
)) != RT_ERR_OK
)
358 * Get the trunk mode from the specified device.
362 * pMode - pointer buffer of trunk mode
366 * RT_ERR_NULL_POINTER - input parameter may be null pointer
368 * The enum of the trunk mode as following
369 * - TRUNK_MODE_NORMAL
372 rtk_api_ret_t
rtk_trunk_mode_get(rtk_trunk_mode_t
*pMode
)
374 rtk_api_ret_t retVal
;
376 /* Check initialization state */
377 RTK_CHK_INIT_STATE();
380 return RT_ERR_NULL_POINTER
;
382 if ((retVal
= rtl8367c_getAsicTrunkingMode((rtk_uint32
*)pMode
)) != RT_ERR_OK
)
389 * rtk_trunk_trafficPause_set
391 * Set the traffic pause setting of a trunk group.
393 * trk_gid - trunk group id
394 * enable - traffic pause state
400 * RT_ERR_LA_TRUNK_ID - invalid trunk ID
404 rtk_api_ret_t
rtk_trunk_trafficPause_set(rtk_trunk_group_t trk_gid
, rtk_enable_t enable
)
406 rtk_api_ret_t retVal
;
408 /* Check initialization state */
409 RTK_CHK_INIT_STATE();
411 /* Check Trunk Group Valid */
412 RTK_CHK_TRUNK_GROUP_VALID(trk_gid
);
414 if(enable
>= RTK_ENABLE_END
)
417 if ((retVal
= rtl8367c_setAsicTrunkingFc((rtk_uint32
)trk_gid
, (rtk_uint32
)enable
)) != RT_ERR_OK
)
424 * rtk_trunk_trafficPause_get
426 * Get the traffic pause setting of a trunk group.
428 * trk_gid - trunk group id
430 * pEnable - pointer of traffic pause state.
434 * RT_ERR_LA_TRUNK_ID - invalid trunk ID
435 * RT_ERR_NULL_POINTER - input parameter may be null pointer
439 rtk_api_ret_t
rtk_trunk_trafficPause_get(rtk_trunk_group_t trk_gid
, rtk_enable_t
*pEnable
)
441 rtk_api_ret_t retVal
;
443 /* Check initialization state */
444 RTK_CHK_INIT_STATE();
446 /* Check Trunk Group Valid */
447 RTK_CHK_TRUNK_GROUP_VALID(trk_gid
);
450 return RT_ERR_NULL_POINTER
;
452 if ((retVal
= rtl8367c_getAsicTrunkingFc((rtk_uint32
)trk_gid
, (rtk_uint32
*)pEnable
)) != RT_ERR_OK
)
459 * rtk_trunk_hashMappingTable_set
461 * Set hash value to port array in the trunk group id from the specified device.
463 * trk_gid - trunk group id
464 * pHash2Port_array - ports associate with the hash value
470 * RT_ERR_UNIT_ID - invalid unit id
471 * RT_ERR_LA_TRUNK_ID - invalid trunk ID
472 * RT_ERR_NULL_POINTER - input parameter may be null pointer
473 * RT_ERR_LA_TRUNK_NOT_EXIST - the trunk doesn't exist
474 * RT_ERR_LA_NOT_MEMBER_PORT - the port is not a member port of the trunk
475 * RT_ERR_LA_CPUPORT - CPU port can not be aggregated port
477 * Trunk group 0 & 1 shares the same hash mapping table.
478 * Trunk group 2 uses a independent table.
480 rtk_api_ret_t
rtk_trunk_hashMappingTable_set(rtk_trunk_group_t trk_gid
, rtk_trunk_hashVal2Port_t
*pHash2Port_array
)
482 rtk_api_ret_t retVal
;
483 rtk_uint32 hashValue
;
485 /* Check initialization state */
486 RTK_CHK_INIT_STATE();
488 /* Check Trunk Group Valid */
489 RTK_CHK_TRUNK_GROUP_VALID(trk_gid
);
491 if(NULL
== pHash2Port_array
)
492 return RT_ERR_NULL_POINTER
;
494 if(trk_gid
<= TRUNK_GROUP1
)
496 for(hashValue
= 0; hashValue
< RTK_MAX_NUM_OF_TRUNK_HASH_VAL
; hashValue
++)
498 if ((retVal
= rtl8367c_setAsicTrunkingHashTable(hashValue
, pHash2Port_array
->value
[hashValue
])) != RT_ERR_OK
)
504 for(hashValue
= 0; hashValue
< RTK_MAX_NUM_OF_TRUNK_HASH_VAL
; hashValue
++)
506 if ((retVal
= rtl8367c_setAsicTrunkingHashTable1(hashValue
, pHash2Port_array
->value
[hashValue
])) != RT_ERR_OK
)
515 * rtk_trunk_hashMappingTable_get
517 * Get hash value to port array in the trunk group id from the specified device.
519 * trk_gid - trunk group id
521 * pHash2Port_array - pointer buffer of ports associate with the hash value
525 * RT_ERR_UNIT_ID - invalid unit id
526 * RT_ERR_LA_TRUNK_ID - invalid trunk ID
527 * RT_ERR_NULL_POINTER - input parameter may be null pointer
529 * Trunk group 0 & 1 shares the same hash mapping table.
530 * Trunk group 2 uses a independent table.
532 rtk_api_ret_t
rtk_trunk_hashMappingTable_get(rtk_trunk_group_t trk_gid
, rtk_trunk_hashVal2Port_t
*pHash2Port_array
)
534 rtk_api_ret_t retVal
;
535 rtk_uint32 hashValue
;
538 /* Check initialization state */
539 RTK_CHK_INIT_STATE();
541 /* Check Trunk Group Valid */
542 RTK_CHK_TRUNK_GROUP_VALID(trk_gid
);
544 if(NULL
== pHash2Port_array
)
545 return RT_ERR_NULL_POINTER
;
547 if(trk_gid
<= TRUNK_GROUP1
)
549 for(hashValue
= 0; hashValue
< RTK_MAX_NUM_OF_TRUNK_HASH_VAL
; hashValue
++)
551 if ((retVal
= rtl8367c_getAsicTrunkingHashTable(hashValue
, &hashPort
)) != RT_ERR_OK
)
554 pHash2Port_array
->value
[hashValue
] = hashPort
;
559 for(hashValue
= 0; hashValue
< RTK_MAX_NUM_OF_TRUNK_HASH_VAL
; hashValue
++)
561 if ((retVal
= rtl8367c_getAsicTrunkingHashTable1(hashValue
, &hashPort
)) != RT_ERR_OK
)
564 pHash2Port_array
->value
[hashValue
] = hashPort
;
572 * rtk_trunk_portQueueEmpty_get
574 * Get the port mask which all queues are empty.
578 * pEmpty_portmask - pointer empty port mask
582 * RT_ERR_NULL_POINTER - input parameter may be null pointer
586 rtk_api_ret_t
rtk_trunk_portQueueEmpty_get(rtk_portmask_t
*pEmpty_portmask
)
588 rtk_api_ret_t retVal
;
591 /* Check initialization state */
592 RTK_CHK_INIT_STATE();
594 if(NULL
== pEmpty_portmask
)
595 return RT_ERR_NULL_POINTER
;
597 if ((retVal
= rtl8367c_getAsicQeueuEmptyStatus(&pmask
)) != RT_ERR_OK
)
600 if ((retVal
= rtk_switch_portmask_P2L_get(pmask
, pEmpty_portmask
)) != RT_ERR_OK
)