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