]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c
stmmac: pci: TX and RX queue priority configuration
[karo-tx-linux.git] / drivers / net / ethernet / stmicro / stmmac / stmmac_pci.c
1 /*******************************************************************************
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
15   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>
23 #include <linux/dmi.h>
24
25 #include "stmmac.h"
26
27 /*
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  */
33 struct stmmac_pci_dmi_data {
34         const char *name;
35         const char *asset_tag;
36         unsigned int func;
37         int phy_addr;
38 };
39
40 struct stmmac_pci_info {
41         struct pci_dev *pdev;
42         int (*setup)(struct plat_stmmacenet_data *plat,
43                      struct stmmac_pci_info *info);
44         struct stmmac_pci_dmi_data *dmi;
45 };
46
47 static int stmmac_pci_find_phy_addr(struct stmmac_pci_info *info)
48 {
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;
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++) {
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))
65                                 continue;
66                         return dmi->phy_addr;
67                 }
68         }
69
70         return -ENODEV;
71 }
72
73 static void stmmac_default_data(struct plat_stmmacenet_data *plat)
74 {
75         plat->bus_id = 1;
76         plat->phy_addr = 0;
77         plat->interface = PHY_INTERFACE_MODE_GMII;
78         plat->clk_csr = 2;      /* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */
79         plat->has_gmac = 1;
80         plat->force_sf_dma_mode = 1;
81
82         plat->mdio_bus_data->phy_reset = NULL;
83         plat->mdio_bus_data->phy_mask = 0;
84
85         plat->dma_cfg->pbl = 32;
86         plat->dma_cfg->pblx8 = true;
87         /* TODO: AXI */
88
89         /* Set default value for multicast hash bins */
90         plat->multicast_filter_bins = HASH_TABLE_SIZE;
91
92         /* Set default value for unicast filter entries */
93         plat->unicast_filter_entries = 1;
94
95         /* Set the maxmtu to a default of JUMBO_LEN */
96         plat->maxmtu = JUMBO_LEN;
97
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;
101
102         /* Disable Priority config by default */
103         plat->tx_queues_cfg[0].use_prio = false;
104         plat->rx_queues_cfg[0].use_prio = false;
105
106         /* Disable RX queues routing by default */
107         plat->rx_queues_cfg[0].pkt_route = 0x0;
108 }
109
110 static int quark_default_data(struct plat_stmmacenet_data *plat,
111                               struct stmmac_pci_info *info)
112 {
113         struct pci_dev *pdev = info->pdev;
114         int ret;
115
116         /*
117          * Refuse to load the driver and register net device if MAC controller
118          * does not connect to any PHY interface.
119          */
120         ret = stmmac_pci_find_phy_addr(info);
121         if (ret < 0)
122                 return ret;
123
124         plat->bus_id = PCI_DEVID(pdev->bus->number, pdev->devfn);
125         plat->phy_addr = ret;
126         plat->interface = PHY_INTERFACE_MODE_RMII;
127         plat->clk_csr = 2;
128         plat->has_gmac = 1;
129         plat->force_sf_dma_mode = 1;
130
131         plat->mdio_bus_data->phy_reset = NULL;
132         plat->mdio_bus_data->phy_mask = 0;
133
134         plat->dma_cfg->pbl = 16;
135         plat->dma_cfg->pblx8 = true;
136         plat->dma_cfg->fixed_burst = 1;
137         /* AXI (TODO) */
138
139         /* Set default value for multicast hash bins */
140         plat->multicast_filter_bins = HASH_TABLE_SIZE;
141
142         /* Set default value for unicast filter entries */
143         plat->unicast_filter_entries = 1;
144
145         /* Set the maxmtu to a default of JUMBO_LEN */
146         plat->maxmtu = JUMBO_LEN;
147
148         /* Set default number of RX and TX queues to use */
149         plat->tx_queues_to_use = 1;
150         plat->rx_queues_to_use = 1;
151
152         /* Disable Priority config by default */
153         plat->tx_queues_cfg[0].use_prio = false;
154         plat->rx_queues_cfg[0].use_prio = false;
155
156         return 0;
157 }
158
159 static struct stmmac_pci_dmi_data quark_pci_dmi_data[] = {
160         {
161                 .name = "Galileo",
162                 .func = 6,
163                 .phy_addr = 1,
164         },
165         {
166                 .name = "GalileoGen2",
167                 .func = 6,
168                 .phy_addr = 1,
169         },
170         {
171                 .name = "SIMATIC IOT2000",
172                 .asset_tag = "6ES7647-0AA00-0YA2",
173                 .func = 6,
174                 .phy_addr = 1,
175         },
176         {
177                 .name = "SIMATIC IOT2000",
178                 .asset_tag = "6ES7647-0AA00-1YA2",
179                 .func = 6,
180                 .phy_addr = 1,
181         },
182         {
183                 .name = "SIMATIC IOT2000",
184                 .asset_tag = "6ES7647-0AA00-1YA2",
185                 .func = 7,
186                 .phy_addr = 1,
187         },
188         {}
189 };
190
191 static struct stmmac_pci_info quark_pci_info = {
192         .setup = quark_default_data,
193         .dmi = quark_pci_dmi_data,
194 };
195
196 /**
197  * stmmac_pci_probe
198  *
199  * @pdev: pci device pointer
200  * @id: pointer to table of device id/id's.
201  *
202  * Description: This probing function gets called for all PCI devices which
203  * match the ID table and are not "owned" by other driver yet. This function
204  * gets passed a "struct pci_dev *" for each device whose entry in the ID table
205  * matches the device. The probe functions returns zero when the driver choose
206  * to take "ownership" of the device or an error code(-ve no) otherwise.
207  */
208 static int stmmac_pci_probe(struct pci_dev *pdev,
209                             const struct pci_device_id *id)
210 {
211         struct stmmac_pci_info *info = (struct stmmac_pci_info *)id->driver_data;
212         struct plat_stmmacenet_data *plat;
213         struct stmmac_resources res;
214         int i;
215         int ret;
216
217         plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
218         if (!plat)
219                 return -ENOMEM;
220
221         plat->mdio_bus_data = devm_kzalloc(&pdev->dev,
222                                            sizeof(*plat->mdio_bus_data),
223                                            GFP_KERNEL);
224         if (!plat->mdio_bus_data)
225                 return -ENOMEM;
226
227         plat->dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*plat->dma_cfg),
228                                      GFP_KERNEL);
229         if (!plat->dma_cfg)
230                 return -ENOMEM;
231
232         /* Enable pci device */
233         ret = pcim_enable_device(pdev);
234         if (ret) {
235                 dev_err(&pdev->dev, "%s: ERROR: failed to enable device\n",
236                         __func__);
237                 return ret;
238         }
239
240         /* Get the base address of device */
241         for (i = 0; i <= PCI_STD_RESOURCE_END; i++) {
242                 if (pci_resource_len(pdev, i) == 0)
243                         continue;
244                 ret = pcim_iomap_regions(pdev, BIT(i), pci_name(pdev));
245                 if (ret)
246                         return ret;
247                 break;
248         }
249
250         pci_set_master(pdev);
251
252         if (info) {
253                 info->pdev = pdev;
254                 if (info->setup) {
255                         ret = info->setup(plat, info);
256                         if (ret)
257                                 return ret;
258                 }
259         } else
260                 stmmac_default_data(plat);
261
262         pci_enable_msi(pdev);
263
264         memset(&res, 0, sizeof(res));
265         res.addr = pcim_iomap_table(pdev)[i];
266         res.wol_irq = pdev->irq;
267         res.irq = pdev->irq;
268
269         return stmmac_dvr_probe(&pdev->dev, plat, &res);
270 }
271
272 /**
273  * stmmac_pci_remove
274  *
275  * @pdev: platform device pointer
276  * Description: this function calls the main to free the net resources
277  * and releases the PCI resources.
278  */
279 static void stmmac_pci_remove(struct pci_dev *pdev)
280 {
281         stmmac_dvr_remove(&pdev->dev);
282 }
283
284 static SIMPLE_DEV_PM_OPS(stmmac_pm_ops, stmmac_suspend, stmmac_resume);
285
286 #define STMMAC_VENDOR_ID 0x700
287 #define STMMAC_QUARK_ID  0x0937
288 #define STMMAC_DEVICE_ID 0x1108
289
290 static const struct pci_device_id stmmac_id_table[] = {
291         {PCI_DEVICE(STMMAC_VENDOR_ID, STMMAC_DEVICE_ID)},
292         {PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_MAC)},
293         {PCI_VDEVICE(INTEL, STMMAC_QUARK_ID), (kernel_ulong_t)&quark_pci_info},
294         {}
295 };
296
297 MODULE_DEVICE_TABLE(pci, stmmac_id_table);
298
299 static struct pci_driver stmmac_pci_driver = {
300         .name = STMMAC_RESOURCE_NAME,
301         .id_table = stmmac_id_table,
302         .probe = stmmac_pci_probe,
303         .remove = stmmac_pci_remove,
304         .driver         = {
305                 .pm     = &stmmac_pm_ops,
306         },
307 };
308
309 module_pci_driver(stmmac_pci_driver);
310
311 MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet PCI driver");
312 MODULE_AUTHOR("Rayagond Kokatanur <rayagond.kokatanur@vayavyalabs.com>");
313 MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
314 MODULE_LICENSE("GPL");