I have read a lot of information online but I am still not sure when do we exactly configure FEC and what are the advantages/disadvantages of configuring it. Does DAC transceivers always need FEC to be configured or optics always need them or both? How do you decide when to configure them when not to?
FEC is mandatory for some -R PHYs and optional for others. IEEE 802.3 Clause 74.1 sums it up quite nicely - FEC is used to reduce the bit error rate (BER) below 10-12 where needed. FEC is optional for ten-lane 100GBASE-R PHYs.
Clause 91 defines an alternative, transcoding (reed-solomon) RS-FEC. RS-FEC is mandatory for four-lane and two-lane 100GBASE-R variants. The ~25 GBd symbol rate, especially in combination with PAM4 line code (for -R2), would raise the BER far above the usual limit. For 100GBASE-SR2 and -CR2, RS-FEC guarantees a BER below 9.2×10-13 with a PMA BER of just 2.4×10-4 or better.
Normally, a switch should know when FEC is mandatory or when it can be optionally configured.
Both FEC variants significantly decrease the BER but increase latency (~50-100 ns), depending on the exact hardware.