Generally, IP phones that can send tagged voice packets can obtain voice VLAN information from the switch using a protocol such as LLDP (LLDP is used as an example). LLDP needs to be enabled. When the switch receives an LLDPDU from an IP phone, the switch encapsulates voice VLAN information in the LLDPDU and sends it to the IP phone. The IP phone then sends tagged voice packets.
The switch can encapsulate voice VLAN information into LLDPDUs and send them to connected IP phones. However, IP phones of some vendors send Cisco Discovery Protocol (CDP) packets. You can run the voice-vlan legacy enable command to enable CDP-compatible function so that the switch encapsulates voice VLAN information in CDP packets and sends them to connected IP phones.