blob: 0efe42659a372c8b98dcba8082a5005017c0c559 [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
Andy Shevchenko70fe4432017-05-08 17:14:22 +0300103static void stmmac_default_data(struct plat_stmmacenet_data *plat)
104{
105 /* Set common default data first */
106 common_default_data(plat);
107
108 plat->bus_id = 1;
109 plat->phy_addr = 0;
110 plat->interface = PHY_INTERFACE_MODE_GMII;
111
112 plat->dma_cfg->pbl = 32;
113 plat->dma_cfg->pblx8 = true;
114 /* TODO: AXI */
115}
116
Jan Kiszkac5d52872017-06-22 08:17:57 +0200117static int quark_default_data(struct pci_dev *pdev,
118 struct plat_stmmacenet_data *plat,
119 const struct stmmac_pci_info *info)
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +0200120{
Andy Shevchenko0763d952015-01-27 21:44:48 +0200121 int ret;
122
Andy Shevchenko70fe4432017-05-08 17:14:22 +0300123 /* Set common default data first */
124 common_default_data(plat);
125
Andy Shevchenko0763d952015-01-27 21:44:48 +0200126 /*
127 * Refuse to load the driver and register net device if MAC controller
128 * does not connect to any PHY interface.
129 */
Jan Kiszkac5d52872017-06-22 08:17:57 +0200130 ret = stmmac_pci_find_phy_addr(pdev, info);
Andy Shevchenko0763d952015-01-27 21:44:48 +0200131 if (ret < 0)
132 return ret;
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +0200133
134 plat->bus_id = PCI_DEVID(pdev->bus->number, pdev->devfn);
Andy Shevchenko0763d952015-01-27 21:44:48 +0200135 plat->phy_addr = ret;
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +0200136 plat->interface = PHY_INTERFACE_MODE_RMII;
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +0200137
138 plat->dma_cfg->pbl = 16;
Niklas Cassel4022d032016-12-07 15:20:08 +0100139 plat->dma_cfg->pblx8 = true;
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +0200140 plat->dma_cfg->fixed_burst = 1;
Giuseppe Cavallaroafea0362016-02-29 14:27:28 +0100141 /* AXI (TODO) */
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +0200142
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +0200143 return 0;
144}
145
Andy Shevchenko0763d952015-01-27 21:44:48 +0200146static struct stmmac_pci_dmi_data quark_pci_dmi_data[] = {
147 {
148 .name = "Galileo",
149 .func = 6,
150 .phy_addr = 1,
151 },
152 {
153 .name = "GalileoGen2",
154 .func = 6,
155 .phy_addr = 1,
156 },
Jan Kiszka212c7fd2017-05-02 09:58:00 +0200157 {
158 .name = "SIMATIC IOT2000",
159 .asset_tag = "6ES7647-0AA00-0YA2",
160 .func = 6,
161 .phy_addr = 1,
162 },
163 {
164 .name = "SIMATIC IOT2000",
165 .asset_tag = "6ES7647-0AA00-1YA2",
166 .func = 6,
167 .phy_addr = 1,
168 },
169 {
170 .name = "SIMATIC IOT2000",
171 .asset_tag = "6ES7647-0AA00-1YA2",
172 .func = 7,
173 .phy_addr = 1,
174 },
Andy Shevchenko0763d952015-01-27 21:44:48 +0200175 {}
176};
177
Jan Kiszkac5d52872017-06-22 08:17:57 +0200178static const struct stmmac_pci_info quark_pci_info = {
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +0200179 .setup = quark_default_data,
Andy Shevchenko0763d952015-01-27 21:44:48 +0200180 .dmi = quark_pci_dmi_data,
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +0200181};
182
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000183/**
184 * stmmac_pci_probe
185 *
186 * @pdev: pci device pointer
187 * @id: pointer to table of device id/id's.
188 *
189 * Description: This probing function gets called for all PCI devices which
190 * match the ID table and are not "owned" by other driver yet. This function
191 * gets passed a "struct pci_dev *" for each device whose entry in the ID table
192 * matches the device. The probe functions returns zero when the driver choose
193 * to take "ownership" of the device or an error code(-ve no) otherwise.
194 */
Bill Pemberton979857b2012-12-03 09:23:34 -0500195static int stmmac_pci_probe(struct pci_dev *pdev,
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +0000196 const struct pci_device_id *id)
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000197{
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +0200198 struct stmmac_pci_info *info = (struct stmmac_pci_info *)id->driver_data;
Andy Shevchenkoc4b2b9a2014-11-28 15:40:56 +0200199 struct plat_stmmacenet_data *plat;
Joachim Eastwoode56788c2015-05-20 20:03:07 +0200200 struct stmmac_resources res;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000201 int i;
Andy Shevchenko2a3e8e92014-11-05 12:27:28 +0200202 int ret;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000203
Andy Shevchenkoc4b2b9a2014-11-28 15:40:56 +0200204 plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
205 if (!plat)
206 return -ENOMEM;
207
208 plat->mdio_bus_data = devm_kzalloc(&pdev->dev,
209 sizeof(*plat->mdio_bus_data),
210 GFP_KERNEL);
211 if (!plat->mdio_bus_data)
212 return -ENOMEM;
213
214 plat->dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*plat->dma_cfg),
215 GFP_KERNEL);
216 if (!plat->dma_cfg)
217 return -ENOMEM;
218
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000219 /* Enable pci device */
Andy Shevchenko2a3e8e92014-11-05 12:27:28 +0200220 ret = pcim_enable_device(pdev);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000221 if (ret) {
Andy Shevchenko7627fc02014-11-05 12:27:29 +0200222 dev_err(&pdev->dev, "%s: ERROR: failed to enable device\n",
223 __func__);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000224 return ret;
225 }
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000226
227 /* Get the base address of device */
Andy Shevchenko295f9d02014-11-05 12:27:26 +0200228 for (i = 0; i <= PCI_STD_RESOURCE_END; i++) {
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000229 if (pci_resource_len(pdev, i) == 0)
230 continue;
Andy Shevchenko2a3e8e92014-11-05 12:27:28 +0200231 ret = pcim_iomap_regions(pdev, BIT(i), pci_name(pdev));
232 if (ret)
233 return ret;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000234 break;
235 }
Andy Shevchenko2a3e8e92014-11-05 12:27:28 +0200236
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000237 pci_set_master(pdev);
238
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +0200239 if (info) {
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +0200240 if (info->setup) {
Jan Kiszkac5d52872017-06-22 08:17:57 +0200241 ret = info->setup(pdev, plat, info);
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +0200242 if (ret)
243 return ret;
244 }
245 } else
246 stmmac_default_data(plat);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000247
Kweh, Hock Leongd2a029b2015-01-27 21:44:49 +0200248 pci_enable_msi(pdev);
249
Joachim Eastwoode56788c2015-05-20 20:03:07 +0200250 memset(&res, 0, sizeof(res));
251 res.addr = pcim_iomap_table(pdev)[i];
252 res.wol_irq = pdev->irq;
253 res.irq = pdev->irq;
254
Joachim Eastwood15ffac72015-05-20 20:03:08 +0200255 return stmmac_dvr_probe(&pdev->dev, plat, &res);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000256}
257
258/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000259 * stmmac_pci_remove
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000260 *
261 * @pdev: platform device pointer
262 * Description: this function calls the main to free the net resources
263 * and releases the PCI resources.
264 */
Bill Pemberton979857b2012-12-03 09:23:34 -0500265static void stmmac_pci_remove(struct pci_dev *pdev)
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000266{
Joachim Eastwoodf4e7bd82016-05-01 22:58:19 +0200267 stmmac_dvr_remove(&pdev->dev);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000268}
269
Joachim Eastwoodf4e7bd82016-05-01 22:58:19 +0200270static SIMPLE_DEV_PM_OPS(stmmac_pm_ops, stmmac_suspend, stmmac_resume);
Andy Shevchenko3be3d812014-11-05 12:27:27 +0200271
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000272#define STMMAC_VENDOR_ID 0x700
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +0200273#define STMMAC_QUARK_ID 0x0937
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000274#define STMMAC_DEVICE_ID 0x1108
275
Benoit Taine9baa3c32014-08-08 15:56:03 +0200276static const struct pci_device_id stmmac_id_table[] = {
Alessandro Rubini5437f4b2012-01-23 23:08:56 +0000277 {PCI_DEVICE(STMMAC_VENDOR_ID, STMMAC_DEVICE_ID)},
278 {PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_MAC)},
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +0200279 {PCI_VDEVICE(INTEL, STMMAC_QUARK_ID), (kernel_ulong_t)&quark_pci_info},
Alessandro Rubini5437f4b2012-01-23 23:08:56 +0000280 {}
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000281};
282
283MODULE_DEVICE_TABLE(pci, stmmac_id_table);
284
Andy Shevchenkob2e2f0c2014-11-10 12:38:59 +0200285static struct pci_driver stmmac_pci_driver = {
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000286 .name = STMMAC_RESOURCE_NAME,
287 .id_table = stmmac_id_table,
288 .probe = stmmac_pci_probe,
Bill Pemberton979857b2012-12-03 09:23:34 -0500289 .remove = stmmac_pci_remove,
Andy Shevchenko3be3d812014-11-05 12:27:27 +0200290 .driver = {
291 .pm = &stmmac_pm_ops,
292 },
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000293};
294
Andy Shevchenkob2e2f0c2014-11-10 12:38:59 +0200295module_pci_driver(stmmac_pci_driver);
296
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000297MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet PCI driver");
298MODULE_AUTHOR("Rayagond Kokatanur <rayagond.kokatanur@vayavyalabs.com>");
299MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
300MODULE_LICENSE("GPL");