That comes from "kaffir," from the Arabic "kafir," meaning "unbeliever," or "heathen." In common use it meant "anyone who isn't us." They applied the term to the people of Ethiopia who weren't Islamic, Jewish, or Christian. Portuguese traders picked up the term, and applied it to black people they met around the Cape of Good Hope. The Dutch, and later the English, applied it to black persons in South Africa. During the 19th century you even found military units with names like the Natal Native Kaffirs in South Africa (period around the Zulu Wars). But, as times changed, and during the period of apartheid, the word was used as a term of abuse by whites against blacks, and today, in South Africa, the word has approximately the same meaning and offensiveness as "n*****" does in the USA.