stmmac_pci.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /*******************************************************************************
  2. This contains the functions to handle the pci driver.
  3. Copyright (C) 2011-2012 Vayavya Labs Pvt Ltd
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Author: Rayagond Kokatanur <rayagond@vayavyalabs.com>
  17. Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
  18. *******************************************************************************/
  19. #include <linux/pci.h>
  20. #include <linux/dmi.h>
  21. #include "stmmac.h"
  22. /*
  23. * This struct is used to associate PCI Function of MAC controller on a board,
  24. * discovered via DMI, with the address of PHY connected to the MAC. The
  25. * negative value of the address means that MAC controller is not connected
  26. * with PHY.
  27. */
  28. struct stmmac_pci_dmi_data {
  29. const char *name;
  30. unsigned int func;
  31. int phy_addr;
  32. };
  33. struct stmmac_pci_info {
  34. struct pci_dev *pdev;
  35. int (*setup)(struct plat_stmmacenet_data *plat,
  36. struct stmmac_pci_info *info);
  37. struct stmmac_pci_dmi_data *dmi;
  38. };
  39. static int stmmac_pci_find_phy_addr(struct stmmac_pci_info *info)
  40. {
  41. const char *name = dmi_get_system_info(DMI_BOARD_NAME);
  42. unsigned int func = PCI_FUNC(info->pdev->devfn);
  43. struct stmmac_pci_dmi_data *dmi;
  44. /*
  45. * Galileo boards with old firmware don't support DMI. We always return
  46. * 1 here, so at least first found MAC controller would be probed.
  47. */
  48. if (!name)
  49. return 1;
  50. for (dmi = info->dmi; dmi->name && *dmi->name; dmi++) {
  51. if (!strcmp(dmi->name, name) && dmi->func == func)
  52. return dmi->phy_addr;
  53. }
  54. return -ENODEV;
  55. }
  56. static void stmmac_default_data(struct plat_stmmacenet_data *plat)
  57. {
  58. plat->bus_id = 1;
  59. plat->phy_addr = 0;
  60. plat->interface = PHY_INTERFACE_MODE_GMII;
  61. plat->clk_csr = 2; /* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */
  62. plat->has_gmac = 1;
  63. plat->force_sf_dma_mode = 1;
  64. plat->mdio_bus_data->phy_reset = NULL;
  65. plat->mdio_bus_data->phy_mask = 0;
  66. plat->dma_cfg->pbl = 32;
  67. plat->dma_cfg->burst_len = DMA_AXI_BLEN_256;
  68. /* Set default value for multicast hash bins */
  69. plat->multicast_filter_bins = HASH_TABLE_SIZE;
  70. /* Set default value for unicast filter entries */
  71. plat->unicast_filter_entries = 1;
  72. }
  73. static int quark_default_data(struct plat_stmmacenet_data *plat,
  74. struct stmmac_pci_info *info)
  75. {
  76. struct pci_dev *pdev = info->pdev;
  77. int ret;
  78. /*
  79. * Refuse to load the driver and register net device if MAC controller
  80. * does not connect to any PHY interface.
  81. */
  82. ret = stmmac_pci_find_phy_addr(info);
  83. if (ret < 0)
  84. return ret;
  85. plat->bus_id = PCI_DEVID(pdev->bus->number, pdev->devfn);
  86. plat->phy_addr = ret;
  87. plat->interface = PHY_INTERFACE_MODE_RMII;
  88. plat->clk_csr = 2;
  89. plat->has_gmac = 1;
  90. plat->force_sf_dma_mode = 1;
  91. plat->mdio_bus_data->phy_reset = NULL;
  92. plat->mdio_bus_data->phy_mask = 0;
  93. plat->dma_cfg->pbl = 16;
  94. plat->dma_cfg->burst_len = DMA_AXI_BLEN_256;
  95. plat->dma_cfg->fixed_burst = 1;
  96. /* Set default value for multicast hash bins */
  97. plat->multicast_filter_bins = HASH_TABLE_SIZE;
  98. /* Set default value for unicast filter entries */
  99. plat->unicast_filter_entries = 1;
  100. return 0;
  101. }
  102. static struct stmmac_pci_dmi_data quark_pci_dmi_data[] = {
  103. {
  104. .name = "Galileo",
  105. .func = 6,
  106. .phy_addr = 1,
  107. },
  108. {
  109. .name = "GalileoGen2",
  110. .func = 6,
  111. .phy_addr = 1,
  112. },
  113. {}
  114. };
  115. static struct stmmac_pci_info quark_pci_info = {
  116. .setup = quark_default_data,
  117. .dmi = quark_pci_dmi_data,
  118. };
  119. /**
  120. * stmmac_pci_probe
  121. *
  122. * @pdev: pci device pointer
  123. * @id: pointer to table of device id/id's.
  124. *
  125. * Description: This probing function gets called for all PCI devices which
  126. * match the ID table and are not "owned" by other driver yet. This function
  127. * gets passed a "struct pci_dev *" for each device whose entry in the ID table
  128. * matches the device. The probe functions returns zero when the driver choose
  129. * to take "ownership" of the device or an error code(-ve no) otherwise.
  130. */
  131. static int stmmac_pci_probe(struct pci_dev *pdev,
  132. const struct pci_device_id *id)
  133. {
  134. struct stmmac_pci_info *info = (struct stmmac_pci_info *)id->driver_data;
  135. struct plat_stmmacenet_data *plat;
  136. struct stmmac_resources res;
  137. int i;
  138. int ret;
  139. plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
  140. if (!plat)
  141. return -ENOMEM;
  142. plat->mdio_bus_data = devm_kzalloc(&pdev->dev,
  143. sizeof(*plat->mdio_bus_data),
  144. GFP_KERNEL);
  145. if (!plat->mdio_bus_data)
  146. return -ENOMEM;
  147. plat->dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*plat->dma_cfg),
  148. GFP_KERNEL);
  149. if (!plat->dma_cfg)
  150. return -ENOMEM;
  151. /* Enable pci device */
  152. ret = pcim_enable_device(pdev);
  153. if (ret) {
  154. dev_err(&pdev->dev, "%s: ERROR: failed to enable device\n",
  155. __func__);
  156. return ret;
  157. }
  158. /* Get the base address of device */
  159. for (i = 0; i <= PCI_STD_RESOURCE_END; i++) {
  160. if (pci_resource_len(pdev, i) == 0)
  161. continue;
  162. ret = pcim_iomap_regions(pdev, BIT(i), pci_name(pdev));
  163. if (ret)
  164. return ret;
  165. break;
  166. }
  167. pci_set_master(pdev);
  168. if (info) {
  169. info->pdev = pdev;
  170. if (info->setup) {
  171. ret = info->setup(plat, info);
  172. if (ret)
  173. return ret;
  174. }
  175. } else
  176. stmmac_default_data(plat);
  177. pci_enable_msi(pdev);
  178. memset(&res, 0, sizeof(res));
  179. res.addr = pcim_iomap_table(pdev)[i];
  180. res.wol_irq = pdev->irq;
  181. res.irq = pdev->irq;
  182. return stmmac_dvr_probe(&pdev->dev, plat, &res);
  183. }
  184. /**
  185. * stmmac_pci_remove
  186. *
  187. * @pdev: platform device pointer
  188. * Description: this function calls the main to free the net resources
  189. * and releases the PCI resources.
  190. */
  191. static void stmmac_pci_remove(struct pci_dev *pdev)
  192. {
  193. struct net_device *ndev = pci_get_drvdata(pdev);
  194. stmmac_dvr_remove(ndev);
  195. }
  196. #ifdef CONFIG_PM_SLEEP
  197. static int stmmac_pci_suspend(struct device *dev)
  198. {
  199. struct pci_dev *pdev = to_pci_dev(dev);
  200. struct net_device *ndev = pci_get_drvdata(pdev);
  201. return stmmac_suspend(ndev);
  202. }
  203. static int stmmac_pci_resume(struct device *dev)
  204. {
  205. struct pci_dev *pdev = to_pci_dev(dev);
  206. struct net_device *ndev = pci_get_drvdata(pdev);
  207. return stmmac_resume(ndev);
  208. }
  209. #endif
  210. static SIMPLE_DEV_PM_OPS(stmmac_pm_ops, stmmac_pci_suspend, stmmac_pci_resume);
  211. #define STMMAC_VENDOR_ID 0x700
  212. #define STMMAC_QUARK_ID 0x0937
  213. #define STMMAC_DEVICE_ID 0x1108
  214. static const struct pci_device_id stmmac_id_table[] = {
  215. {PCI_DEVICE(STMMAC_VENDOR_ID, STMMAC_DEVICE_ID)},
  216. {PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_MAC)},
  217. {PCI_VDEVICE(INTEL, STMMAC_QUARK_ID), (kernel_ulong_t)&quark_pci_info},
  218. {}
  219. };
  220. MODULE_DEVICE_TABLE(pci, stmmac_id_table);
  221. static struct pci_driver stmmac_pci_driver = {
  222. .name = STMMAC_RESOURCE_NAME,
  223. .id_table = stmmac_id_table,
  224. .probe = stmmac_pci_probe,
  225. .remove = stmmac_pci_remove,
  226. .driver = {
  227. .pm = &stmmac_pm_ops,
  228. },
  229. };
  230. module_pci_driver(stmmac_pci_driver);
  231. MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet PCI driver");
  232. MODULE_AUTHOR("Rayagond Kokatanur <rayagond.kokatanur@vayavyalabs.com>");
  233. MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
  234. MODULE_LICENSE("GPL");