blob: d3d74e526e17d4cf343687617a2796483dd66a1d [file] [log] [blame]
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001/*******************************************************************************
2 This contains the functions to handle the pci driver.
3
4 Copyright (C) 2011-2012 Vayavya Labs Pvt Ltd
5
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.
9
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
13 more details.
14
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000015 The full GNU General Public License is included in this distribution in
16 the file called "COPYING".
17
18 Author: Rayagond Kokatanur <rayagond@vayavyalabs.com>
19 Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
20*******************************************************************************/
21
22#include <linux/pci.h>
Andy Shevchenko0763d952015-01-27 21:44:48 +020023#include <linux/dmi.h>
24
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000025#include "stmmac.h"
26
Andy Shevchenko0763d952015-01-27 21:44:48 +020027/*
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
31 * with PHY.
32 */
33struct stmmac_pci_dmi_data {
34 const char *name;
Jan Kiszka212c7fd2017-05-02 09:58:00 +020035 const char *asset_tag;
Andy Shevchenko0763d952015-01-27 21:44:48 +020036 unsigned int func;
37 int phy_addr;
38};
39
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +020040struct stmmac_pci_info {
Jan Kiszkac5d52872017-06-22 08:17:57 +020041 int (*setup)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat,
42 const struct stmmac_pci_info *info);
Andy Shevchenko0763d952015-01-27 21:44:48 +020043 struct stmmac_pci_dmi_data *dmi;
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +020044};
45
Jan Kiszkac5d52872017-06-22 08:17:57 +020046static int stmmac_pci_find_phy_addr(struct pci_dev *pdev,
47 const struct stmmac_pci_info *info)
Andy Shevchenko0763d952015-01-27 21:44:48 +020048{
49 const char *name = dmi_get_system_info(DMI_BOARD_NAME);
Jan Kiszka212c7fd2017-05-02 09:58:00 +020050 const char *asset_tag = dmi_get_system_info(DMI_BOARD_ASSET_TAG);
Jan Kiszkac5d52872017-06-22 08:17:57 +020051 unsigned int func = PCI_FUNC(pdev->devfn);
Andy Shevchenko0763d952015-01-27 21:44:48 +020052 struct stmmac_pci_dmi_data *dmi;
53
54 /*
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.
57 */
58 if (!name)
59 return 1;
60
61 for (dmi = info->dmi; dmi->name && *dmi->name; dmi++) {
Jan Kiszka212c7fd2017-05-02 09:58:00 +020062 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))
65 continue;
Andy Shevchenko0763d952015-01-27 21:44:48 +020066 return dmi->phy_addr;
Jan Kiszka212c7fd2017-05-02 09:58:00 +020067 }
Andy Shevchenko0763d952015-01-27 21:44:48 +020068 }
69
70 return -ENODEV;
71}
72
Andy Shevchenko70fe4432017-05-08 17:14:22 +030073static void common_default_data(struct plat_stmmacenet_data *plat)
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000074{
Andy Shevchenkoc4b2b9a2014-11-28 15:40:56 +020075 plat->clk_csr = 2; /* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */
76 plat->has_gmac = 1;
77 plat->force_sf_dma_mode = 1;
Andy Shevchenko1e19e082014-10-31 18:28:03 +020078
Andy Shevchenkoc4b2b9a2014-11-28 15:40:56 +020079 plat->mdio_bus_data->phy_reset = NULL;
80 plat->mdio_bus_data->phy_mask = 0;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000081
Andy Shevchenko1e19e082014-10-31 18:28:03 +020082 /* Set default value for multicast hash bins */
Andy Shevchenkoc4b2b9a2014-11-28 15:40:56 +020083 plat->multicast_filter_bins = HASH_TABLE_SIZE;
Andy Shevchenko1e19e082014-10-31 18:28:03 +020084
85 /* Set default value for unicast filter entries */
Andy Shevchenkoc4b2b9a2014-11-28 15:40:56 +020086 plat->unicast_filter_entries = 1;
Kweh, Hock Leonga2cd64f2017-01-07 17:32:03 +080087
88 /* Set the maxmtu to a default of JUMBO_LEN */
89 plat->maxmtu = JUMBO_LEN;
Joao Pinto26d68512017-03-13 10:07:07 +000090
91 /* Set default number of RX and TX queues to use */
92 plat->tx_queues_to_use = 1;
93 plat->rx_queues_to_use = 1;
Joao Pintoa8f51022017-03-17 16:11:06 +000094
95 /* Disable Priority config by default */
96 plat->tx_queues_cfg[0].use_prio = false;
97 plat->rx_queues_cfg[0].use_prio = false;
Joao Pintoabe80fd2017-03-17 16:11:07 +000098
99 /* Disable RX queues routing by default */
100 plat->rx_queues_cfg[0].pkt_route = 0x0;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000101}
102
Jan Kiszkab6a4c8f02017-06-22 08:17:58 +0200103static int stmmac_default_data(struct pci_dev *pdev,
104 struct plat_stmmacenet_data *plat,
105 const struct stmmac_pci_info *info)
Andy Shevchenko70fe4432017-05-08 17:14:22 +0300106{
107 /* Set common default data first */
108 common_default_data(plat);
109
110 plat->bus_id = 1;
111 plat->phy_addr = 0;
112 plat->interface = PHY_INTERFACE_MODE_GMII;
113
114 plat->dma_cfg->pbl = 32;
115 plat->dma_cfg->pblx8 = true;
116 /* TODO: AXI */
Jan Kiszkab6a4c8f02017-06-22 08:17:58 +0200117
118 return 0;
Andy Shevchenko70fe4432017-05-08 17:14:22 +0300119}
120
Jan Kiszkab6a4c8f02017-06-22 08:17:58 +0200121static const struct stmmac_pci_info stmmac_pci_info = {
122 .setup = stmmac_default_data,
123};
124
Jan Kiszkac5d52872017-06-22 08:17:57 +0200125static int quark_default_data(struct pci_dev *pdev,
126 struct plat_stmmacenet_data *plat,
127 const struct stmmac_pci_info *info)
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +0200128{
Andy Shevchenko0763d952015-01-27 21:44:48 +0200129 int ret;
130
Andy Shevchenko70fe4432017-05-08 17:14:22 +0300131 /* Set common default data first */
132 common_default_data(plat);
133
Andy Shevchenko0763d952015-01-27 21:44:48 +0200134 /*
135 * Refuse to load the driver and register net device if MAC controller
136 * does not connect to any PHY interface.
137 */
Jan Kiszkac5d52872017-06-22 08:17:57 +0200138 ret = stmmac_pci_find_phy_addr(pdev, info);
Andy Shevchenko0763d952015-01-27 21:44:48 +0200139 if (ret < 0)
140 return ret;
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +0200141
142 plat->bus_id = PCI_DEVID(pdev->bus->number, pdev->devfn);
Andy Shevchenko0763d952015-01-27 21:44:48 +0200143 plat->phy_addr = ret;
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +0200144 plat->interface = PHY_INTERFACE_MODE_RMII;
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +0200145
146 plat->dma_cfg->pbl = 16;
Niklas Cassel4022d032016-12-07 15:20:08 +0100147 plat->dma_cfg->pblx8 = true;
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +0200148 plat->dma_cfg->fixed_burst = 1;
Giuseppe Cavallaroafea0362016-02-29 14:27:28 +0100149 /* AXI (TODO) */
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +0200150
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +0200151 return 0;
152}
153
Andy Shevchenko0763d952015-01-27 21:44:48 +0200154static struct stmmac_pci_dmi_data quark_pci_dmi_data[] = {
155 {
156 .name = "Galileo",
157 .func = 6,
158 .phy_addr = 1,
159 },
160 {
161 .name = "GalileoGen2",
162 .func = 6,
163 .phy_addr = 1,
164 },
Jan Kiszka212c7fd2017-05-02 09:58:00 +0200165 {
166 .name = "SIMATIC IOT2000",
167 .asset_tag = "6ES7647-0AA00-0YA2",
168 .func = 6,
169 .phy_addr = 1,
170 },
171 {
172 .name = "SIMATIC IOT2000",
173 .asset_tag = "6ES7647-0AA00-1YA2",
174 .func = 6,
175 .phy_addr = 1,
176 },
177 {
178 .name = "SIMATIC IOT2000",
179 .asset_tag = "6ES7647-0AA00-1YA2",
180 .func = 7,
181 .phy_addr = 1,
182 },
Andy Shevchenko0763d952015-01-27 21:44:48 +0200183 {}
184};
185
Jan Kiszkac5d52872017-06-22 08:17:57 +0200186static const struct stmmac_pci_info quark_pci_info = {
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +0200187 .setup = quark_default_data,
Andy Shevchenko0763d952015-01-27 21:44:48 +0200188 .dmi = quark_pci_dmi_data,
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +0200189};
190
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000191/**
192 * stmmac_pci_probe
193 *
194 * @pdev: pci device pointer
195 * @id: pointer to table of device id/id's.
196 *
197 * Description: This probing function gets called for all PCI devices which
198 * match the ID table and are not "owned" by other driver yet. This function
199 * gets passed a "struct pci_dev *" for each device whose entry in the ID table
200 * matches the device. The probe functions returns zero when the driver choose
201 * to take "ownership" of the device or an error code(-ve no) otherwise.
202 */
Bill Pemberton979857b2012-12-03 09:23:34 -0500203static int stmmac_pci_probe(struct pci_dev *pdev,
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +0000204 const struct pci_device_id *id)
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000205{
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +0200206 struct stmmac_pci_info *info = (struct stmmac_pci_info *)id->driver_data;
Andy Shevchenkoc4b2b9a2014-11-28 15:40:56 +0200207 struct plat_stmmacenet_data *plat;
Joachim Eastwoode56788c2015-05-20 20:03:07 +0200208 struct stmmac_resources res;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000209 int i;
Andy Shevchenko2a3e8e92014-11-05 12:27:28 +0200210 int ret;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000211
Andy Shevchenkoc4b2b9a2014-11-28 15:40:56 +0200212 plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
213 if (!plat)
214 return -ENOMEM;
215
216 plat->mdio_bus_data = devm_kzalloc(&pdev->dev,
217 sizeof(*plat->mdio_bus_data),
218 GFP_KERNEL);
219 if (!plat->mdio_bus_data)
220 return -ENOMEM;
221
222 plat->dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*plat->dma_cfg),
223 GFP_KERNEL);
224 if (!plat->dma_cfg)
225 return -ENOMEM;
226
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000227 /* Enable pci device */
Andy Shevchenko2a3e8e92014-11-05 12:27:28 +0200228 ret = pcim_enable_device(pdev);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000229 if (ret) {
Andy Shevchenko7627fc02014-11-05 12:27:29 +0200230 dev_err(&pdev->dev, "%s: ERROR: failed to enable device\n",
231 __func__);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000232 return ret;
233 }
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000234
235 /* Get the base address of device */
Andy Shevchenko295f9d02014-11-05 12:27:26 +0200236 for (i = 0; i <= PCI_STD_RESOURCE_END; i++) {
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000237 if (pci_resource_len(pdev, i) == 0)
238 continue;
Andy Shevchenko2a3e8e92014-11-05 12:27:28 +0200239 ret = pcim_iomap_regions(pdev, BIT(i), pci_name(pdev));
240 if (ret)
241 return ret;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000242 break;
243 }
Andy Shevchenko2a3e8e92014-11-05 12:27:28 +0200244
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000245 pci_set_master(pdev);
246
Jan Kiszkab6a4c8f02017-06-22 08:17:58 +0200247 ret = info->setup(pdev, plat, info);
248 if (ret)
249 return ret;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000250
Kweh, Hock Leongd2a029b2015-01-27 21:44:49 +0200251 pci_enable_msi(pdev);
252
Joachim Eastwoode56788c2015-05-20 20:03:07 +0200253 memset(&res, 0, sizeof(res));
254 res.addr = pcim_iomap_table(pdev)[i];
255 res.wol_irq = pdev->irq;
256 res.irq = pdev->irq;
257
Joachim Eastwood15ffac72015-05-20 20:03:08 +0200258 return stmmac_dvr_probe(&pdev->dev, plat, &res);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000259}
260
261/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000262 * stmmac_pci_remove
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000263 *
264 * @pdev: platform device pointer
265 * Description: this function calls the main to free the net resources
266 * and releases the PCI resources.
267 */
Bill Pemberton979857b2012-12-03 09:23:34 -0500268static void stmmac_pci_remove(struct pci_dev *pdev)
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000269{
Joachim Eastwoodf4e7bd82016-05-01 22:58:19 +0200270 stmmac_dvr_remove(&pdev->dev);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000271}
272
Joachim Eastwoodf4e7bd82016-05-01 22:58:19 +0200273static SIMPLE_DEV_PM_OPS(stmmac_pm_ops, stmmac_suspend, stmmac_resume);
Andy Shevchenko3be3d812014-11-05 12:27:27 +0200274
Jan Kiszkab6a4c8f02017-06-22 08:17:58 +0200275/* synthetic ID, no official vendor */
276#define PCI_VENDOR_ID_STMMAC 0x700
277
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +0200278#define STMMAC_QUARK_ID 0x0937
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000279#define STMMAC_DEVICE_ID 0x1108
280
Jan Kiszkab6a4c8f02017-06-22 08:17:58 +0200281#define STMMAC_DEVICE(vendor_id, dev_id, info) { \
282 PCI_VDEVICE(vendor_id, dev_id), \
283 .driver_data = (kernel_ulong_t)&info \
284 }
285
Benoit Taine9baa3c32014-08-08 15:56:03 +0200286static const struct pci_device_id stmmac_id_table[] = {
Jan Kiszkab6a4c8f02017-06-22 08:17:58 +0200287 STMMAC_DEVICE(STMMAC, STMMAC_DEVICE_ID, stmmac_pci_info),
288 STMMAC_DEVICE(STMICRO, PCI_DEVICE_ID_STMICRO_MAC, stmmac_pci_info),
289 STMMAC_DEVICE(INTEL, STMMAC_QUARK_ID, quark_pci_info),
Alessandro Rubini5437f4b2012-01-23 23:08:56 +0000290 {}
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000291};
292
293MODULE_DEVICE_TABLE(pci, stmmac_id_table);
294
Andy Shevchenkob2e2f0c2014-11-10 12:38:59 +0200295static struct pci_driver stmmac_pci_driver = {
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000296 .name = STMMAC_RESOURCE_NAME,
297 .id_table = stmmac_id_table,
298 .probe = stmmac_pci_probe,
Bill Pemberton979857b2012-12-03 09:23:34 -0500299 .remove = stmmac_pci_remove,
Andy Shevchenko3be3d812014-11-05 12:27:27 +0200300 .driver = {
301 .pm = &stmmac_pm_ops,
302 },
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000303};
304
Andy Shevchenkob2e2f0c2014-11-10 12:38:59 +0200305module_pci_driver(stmmac_pci_driver);
306
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000307MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet PCI driver");
308MODULE_AUTHOR("Rayagond Kokatanur <rayagond.kokatanur@vayavyalabs.com>");
309MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
310MODULE_LICENSE("GPL");