1 /*******************************************************************************
2 This contains the functions to handle the pci driver.
4 Copyright (C) 2011-2012 Vayavya Labs Pvt Ltd
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 The full GNU General Public License is included in this distribution in
16 the file called "COPYING".
18 Author: Rayagond Kokatanur <rayagond@vayavyalabs.com>
19 Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
20 *******************************************************************************/
22 #include <linux/pci.h>
23 #include <linux/dmi.h>
28 * This struct is used to associate PCI Function of MAC controller on a board,
29 * discovered via DMI, with the address of PHY connected to the MAC. The
30 * negative value of the address means that MAC controller is not connected
33 struct stmmac_pci_dmi_data {
35 const char *asset_tag;
40 struct stmmac_pci_info {
42 int (*setup)(struct plat_stmmacenet_data *plat,
43 struct stmmac_pci_info *info);
44 struct stmmac_pci_dmi_data *dmi;
47 static int stmmac_pci_find_phy_addr(struct stmmac_pci_info *info)
49 const char *name = dmi_get_system_info(DMI_BOARD_NAME);
50 const char *asset_tag = dmi_get_system_info(DMI_BOARD_ASSET_TAG);
51 unsigned int func = PCI_FUNC(info->pdev->devfn);
52 struct stmmac_pci_dmi_data *dmi;
55 * Galileo boards with old firmware don't support DMI. We always return
56 * 1 here, so at least first found MAC controller would be probed.
61 for (dmi = info->dmi; dmi->name && *dmi->name; dmi++) {
62 if (!strcmp(dmi->name, name) && dmi->func == func) {
63 /* If asset tag is provided, match on it as well. */
64 if (dmi->asset_tag && strcmp(dmi->asset_tag, asset_tag))
73 static void stmmac_default_data(struct plat_stmmacenet_data *plat)
77 plat->interface = PHY_INTERFACE_MODE_GMII;
78 plat->clk_csr = 2; /* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */
80 plat->force_sf_dma_mode = 1;
82 plat->mdio_bus_data->phy_reset = NULL;
83 plat->mdio_bus_data->phy_mask = 0;
85 plat->dma_cfg->pbl = 32;
86 plat->dma_cfg->pblx8 = true;
89 /* Set default value for multicast hash bins */
90 plat->multicast_filter_bins = HASH_TABLE_SIZE;
92 /* Set default value for unicast filter entries */
93 plat->unicast_filter_entries = 1;
95 /* Set the maxmtu to a default of JUMBO_LEN */
96 plat->maxmtu = JUMBO_LEN;
98 /* Set default number of RX and TX queues to use */
99 plat->tx_queues_to_use = 1;
100 plat->rx_queues_to_use = 1;
102 /* Disable Priority config by default */
103 plat->tx_queues_cfg[0].use_prio = false;
104 plat->rx_queues_cfg[0].use_prio = false;
106 /* Disable RX queues routing by default */
107 plat->rx_queues_cfg[0].pkt_route = 0x0;
110 static int quark_default_data(struct plat_stmmacenet_data *plat,
111 struct stmmac_pci_info *info)
113 struct pci_dev *pdev = info->pdev;
117 * Refuse to load the driver and register net device if MAC controller
118 * does not connect to any PHY interface.
120 ret = stmmac_pci_find_phy_addr(info);
124 plat->bus_id = PCI_DEVID(pdev->bus->number, pdev->devfn);
125 plat->phy_addr = ret;
126 plat->interface = PHY_INTERFACE_MODE_RMII;
129 plat->force_sf_dma_mode = 1;
131 plat->mdio_bus_data->phy_reset = NULL;
132 plat->mdio_bus_data->phy_mask = 0;
134 plat->dma_cfg->pbl = 16;
135 plat->dma_cfg->pblx8 = true;
136 plat->dma_cfg->fixed_burst = 1;
139 /* Set default value for multicast hash bins */
140 plat->multicast_filter_bins = HASH_TABLE_SIZE;
142 /* Set default value for unicast filter entries */
143 plat->unicast_filter_entries = 1;
145 /* Set the maxmtu to a default of JUMBO_LEN */
146 plat->maxmtu = JUMBO_LEN;
151 static struct stmmac_pci_dmi_data quark_pci_dmi_data[] = {
158 .name = "GalileoGen2",
163 .name = "SIMATIC IOT2000",
164 .asset_tag = "6ES7647-0AA00-0YA2",
169 .name = "SIMATIC IOT2000",
170 .asset_tag = "6ES7647-0AA00-1YA2",
175 .name = "SIMATIC IOT2000",
176 .asset_tag = "6ES7647-0AA00-1YA2",
183 static struct stmmac_pci_info quark_pci_info = {
184 .setup = quark_default_data,
185 .dmi = quark_pci_dmi_data,
191 * @pdev: pci device pointer
192 * @id: pointer to table of device id/id's.
194 * Description: This probing function gets called for all PCI devices which
195 * match the ID table and are not "owned" by other driver yet. This function
196 * gets passed a "struct pci_dev *" for each device whose entry in the ID table
197 * matches the device. The probe functions returns zero when the driver choose
198 * to take "ownership" of the device or an error code(-ve no) otherwise.
200 static int stmmac_pci_probe(struct pci_dev *pdev,
201 const struct pci_device_id *id)
203 struct stmmac_pci_info *info = (struct stmmac_pci_info *)id->driver_data;
204 struct plat_stmmacenet_data *plat;
205 struct stmmac_resources res;
209 plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
213 plat->mdio_bus_data = devm_kzalloc(&pdev->dev,
214 sizeof(*plat->mdio_bus_data),
216 if (!plat->mdio_bus_data)
219 plat->dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*plat->dma_cfg),
224 /* Enable pci device */
225 ret = pcim_enable_device(pdev);
227 dev_err(&pdev->dev, "%s: ERROR: failed to enable device\n",
232 /* Get the base address of device */
233 for (i = 0; i <= PCI_STD_RESOURCE_END; i++) {
234 if (pci_resource_len(pdev, i) == 0)
236 ret = pcim_iomap_regions(pdev, BIT(i), pci_name(pdev));
242 pci_set_master(pdev);
247 ret = info->setup(plat, info);
252 stmmac_default_data(plat);
254 pci_enable_msi(pdev);
256 memset(&res, 0, sizeof(res));
257 res.addr = pcim_iomap_table(pdev)[i];
258 res.wol_irq = pdev->irq;
261 return stmmac_dvr_probe(&pdev->dev, plat, &res);
267 * @pdev: platform device pointer
268 * Description: this function calls the main to free the net resources
269 * and releases the PCI resources.
271 static void stmmac_pci_remove(struct pci_dev *pdev)
273 stmmac_dvr_remove(&pdev->dev);
276 static SIMPLE_DEV_PM_OPS(stmmac_pm_ops, stmmac_suspend, stmmac_resume);
278 #define STMMAC_VENDOR_ID 0x700
279 #define STMMAC_QUARK_ID 0x0937
280 #define STMMAC_DEVICE_ID 0x1108
282 static const struct pci_device_id stmmac_id_table[] = {
283 {PCI_DEVICE(STMMAC_VENDOR_ID, STMMAC_DEVICE_ID)},
284 {PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_MAC)},
285 {PCI_VDEVICE(INTEL, STMMAC_QUARK_ID), (kernel_ulong_t)&quark_pci_info},
289 MODULE_DEVICE_TABLE(pci, stmmac_id_table);
291 static struct pci_driver stmmac_pci_driver = {
292 .name = STMMAC_RESOURCE_NAME,
293 .id_table = stmmac_id_table,
294 .probe = stmmac_pci_probe,
295 .remove = stmmac_pci_remove,
297 .pm = &stmmac_pm_ops,
301 module_pci_driver(stmmac_pci_driver);
303 MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet PCI driver");
304 MODULE_AUTHOR("Rayagond Kokatanur <rayagond.kokatanur@vayavyalabs.com>");
305 MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
306 MODULE_LICENSE("GPL");