1 // SPDX-License-Identifier: GPL-2.0-only
2 /*******************************************************************************
3 This contains the functions to handle the pci driver.
5 Copyright (C) 2011-2012 Vayavya Labs Pvt Ltd
8 Author: Rayagond Kokatanur <rayagond@vayavyalabs.com>
9 Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
10 *******************************************************************************/
12 #include <linux/clk-provider.h>
13 #include <linux/pci.h>
14 #include <linux/dmi.h>
18 struct stmmac_pci_info {
19 int (*setup)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat);
22 static void common_default_data(struct plat_stmmacenet_data *plat)
24 plat->clk_csr = 2; /* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */
26 plat->force_sf_dma_mode = 1;
28 plat->mdio_bus_data->needs_reset = true;
30 /* Set default value for multicast hash bins */
31 plat->multicast_filter_bins = HASH_TABLE_SIZE;
33 /* Set default value for unicast filter entries */
34 plat->unicast_filter_entries = 1;
36 /* Set the maxmtu to a default of JUMBO_LEN */
37 plat->maxmtu = JUMBO_LEN;
39 /* Set default number of RX and TX queues to use */
40 plat->tx_queues_to_use = 1;
41 plat->rx_queues_to_use = 1;
43 /* Disable Priority config by default */
44 plat->tx_queues_cfg[0].use_prio = false;
45 plat->rx_queues_cfg[0].use_prio = false;
47 /* Disable RX queues routing by default */
48 plat->rx_queues_cfg[0].pkt_route = 0x0;
51 static int stmmac_default_data(struct pci_dev *pdev,
52 struct plat_stmmacenet_data *plat)
54 /* Set common default data first */
55 common_default_data(plat);
59 plat->phy_interface = PHY_INTERFACE_MODE_GMII;
61 plat->dma_cfg->pbl = 32;
62 plat->dma_cfg->pblx8 = true;
68 static const struct stmmac_pci_info stmmac_pci_info = {
69 .setup = stmmac_default_data,
72 static int snps_gmac5_default_data(struct pci_dev *pdev,
73 struct plat_stmmacenet_data *plat)
79 plat->force_sf_dma_mode = 1;
80 plat->flags |= STMMAC_FLAG_TSO_EN;
83 /* Set default value for multicast hash bins */
84 plat->multicast_filter_bins = HASH_TABLE_SIZE;
86 /* Set default value for unicast filter entries */
87 plat->unicast_filter_entries = 1;
89 /* Set the maxmtu to a default of JUMBO_LEN */
90 plat->maxmtu = JUMBO_LEN;
92 /* Set default number of RX and TX queues to use */
93 plat->tx_queues_to_use = 4;
94 plat->rx_queues_to_use = 4;
96 plat->tx_sched_algorithm = MTL_TX_ALGORITHM_WRR;
97 for (i = 0; i < plat->tx_queues_to_use; i++) {
98 plat->tx_queues_cfg[i].use_prio = false;
99 plat->tx_queues_cfg[i].mode_to_use = MTL_QUEUE_DCB;
100 plat->tx_queues_cfg[i].weight = 25;
102 plat->tx_queues_cfg[i].tbs_en = 1;
105 plat->rx_sched_algorithm = MTL_RX_ALGORITHM_SP;
106 for (i = 0; i < plat->rx_queues_to_use; i++) {
107 plat->rx_queues_cfg[i].use_prio = false;
108 plat->rx_queues_cfg[i].mode_to_use = MTL_QUEUE_DCB;
109 plat->rx_queues_cfg[i].pkt_route = 0x0;
110 plat->rx_queues_cfg[i].chan = i;
115 plat->phy_interface = PHY_INTERFACE_MODE_GMII;
117 plat->dma_cfg->pbl = 32;
118 plat->dma_cfg->pblx8 = true;
120 /* Axi Configuration */
121 plat->axi = devm_kzalloc(&pdev->dev, sizeof(*plat->axi), GFP_KERNEL);
125 plat->axi->axi_wr_osr_lmt = 31;
126 plat->axi->axi_rd_osr_lmt = 31;
128 plat->axi->axi_fb = false;
129 plat->axi->axi_blen[0] = 4;
130 plat->axi->axi_blen[1] = 8;
131 plat->axi->axi_blen[2] = 16;
132 plat->axi->axi_blen[3] = 32;
137 static const struct stmmac_pci_info snps_gmac5_pci_info = {
138 .setup = snps_gmac5_default_data,
144 * @pdev: pci device pointer
145 * @id: pointer to table of device id/id's.
147 * Description: This probing function gets called for all PCI devices which
148 * match the ID table and are not "owned" by other driver yet. This function
149 * gets passed a "struct pci_dev *" for each device whose entry in the ID table
150 * matches the device. The probe functions returns zero when the driver choose
151 * to take "ownership" of the device or an error code(-ve no) otherwise.
153 static int stmmac_pci_probe(struct pci_dev *pdev,
154 const struct pci_device_id *id)
156 struct stmmac_pci_info *info = (struct stmmac_pci_info *)id->driver_data;
157 struct plat_stmmacenet_data *plat;
158 struct stmmac_resources res;
162 plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
166 plat->mdio_bus_data = devm_kzalloc(&pdev->dev,
167 sizeof(*plat->mdio_bus_data),
169 if (!plat->mdio_bus_data)
172 plat->dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*plat->dma_cfg),
177 plat->safety_feat_cfg = devm_kzalloc(&pdev->dev,
178 sizeof(*plat->safety_feat_cfg),
180 if (!plat->safety_feat_cfg)
183 /* Enable pci device */
184 ret = pcim_enable_device(pdev);
186 dev_err(&pdev->dev, "%s: ERROR: failed to enable device\n",
191 /* Get the base address of device */
192 for (i = 0; i < PCI_STD_NUM_BARS; i++) {
193 if (pci_resource_len(pdev, i) == 0)
195 ret = pcim_iomap_regions(pdev, BIT(i), pci_name(pdev));
201 pci_set_master(pdev);
203 ret = info->setup(pdev, plat);
207 memset(&res, 0, sizeof(res));
208 res.addr = pcim_iomap_table(pdev)[i];
209 res.wol_irq = pdev->irq;
212 plat->safety_feat_cfg->tsoee = 1;
213 plat->safety_feat_cfg->mrxpee = 1;
214 plat->safety_feat_cfg->mestee = 1;
215 plat->safety_feat_cfg->mrxee = 1;
216 plat->safety_feat_cfg->mtxee = 1;
217 plat->safety_feat_cfg->epsi = 1;
218 plat->safety_feat_cfg->edpp = 1;
219 plat->safety_feat_cfg->prtyen = 1;
220 plat->safety_feat_cfg->tmouten = 1;
222 return stmmac_dvr_probe(&pdev->dev, plat, &res);
228 * @pdev: platform device pointer
229 * Description: this function calls the main to free the net resources
230 * and releases the PCI resources.
232 static void stmmac_pci_remove(struct pci_dev *pdev)
236 stmmac_dvr_remove(&pdev->dev);
238 for (i = 0; i < PCI_STD_NUM_BARS; i++) {
239 if (pci_resource_len(pdev, i) == 0)
241 pcim_iounmap_regions(pdev, BIT(i));
246 static int __maybe_unused stmmac_pci_suspend(struct device *dev)
248 struct pci_dev *pdev = to_pci_dev(dev);
251 ret = stmmac_suspend(dev);
255 ret = pci_save_state(pdev);
259 pci_disable_device(pdev);
260 pci_wake_from_d3(pdev, true);
264 static int __maybe_unused stmmac_pci_resume(struct device *dev)
266 struct pci_dev *pdev = to_pci_dev(dev);
269 pci_restore_state(pdev);
270 pci_set_power_state(pdev, PCI_D0);
272 ret = pci_enable_device(pdev);
276 pci_set_master(pdev);
278 return stmmac_resume(dev);
281 static SIMPLE_DEV_PM_OPS(stmmac_pm_ops, stmmac_pci_suspend, stmmac_pci_resume);
283 /* synthetic ID, no official vendor */
284 #define PCI_VENDOR_ID_STMMAC 0x0700
286 #define PCI_DEVICE_ID_STMMAC_STMMAC 0x1108
287 #define PCI_DEVICE_ID_SYNOPSYS_GMAC5_ID 0x7102
289 static const struct pci_device_id stmmac_id_table[] = {
290 { PCI_DEVICE_DATA(STMMAC, STMMAC, &stmmac_pci_info) },
291 { PCI_DEVICE_DATA(STMICRO, MAC, &stmmac_pci_info) },
292 { PCI_DEVICE_DATA(SYNOPSYS, GMAC5_ID, &snps_gmac5_pci_info) },
296 MODULE_DEVICE_TABLE(pci, stmmac_id_table);
298 static struct pci_driver stmmac_pci_driver = {
299 .name = STMMAC_RESOURCE_NAME,
300 .id_table = stmmac_id_table,
301 .probe = stmmac_pci_probe,
302 .remove = stmmac_pci_remove,
304 .pm = &stmmac_pm_ops,
308 module_pci_driver(stmmac_pci_driver);
310 MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet PCI driver");
311 MODULE_AUTHOR("Rayagond Kokatanur <rayagond.kokatanur@vayavyalabs.com>");
312 MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
313 MODULE_LICENSE("GPL");