Since you sold all of the shares in 2017, your cost basis will be the total amount of reinvested dividends plus the cost of the original stock.
The entire transaction can be reported as a long-term capital gain; any stock purchased less than a year before the sale would almost certainly have amounted to an immaterial part of the sale and/or resulted in an immaterial gain for a number of reasons.