21 #include <linux/etherdevice.h> |
21 #include <linux/etherdevice.h> |
22 #include <linux/module.h> |
22 #include <linux/module.h> |
23 #include <linux/netdevice.h> |
23 #include <linux/netdevice.h> |
24 #include <linux/platform_device.h> |
24 #include <linux/platform_device.h> |
25 #include <linux/version.h> |
25 #include <linux/version.h> |
26 |
|
27 #include "module.h" |
26 #include "module.h" |
28 |
27 |
29 MODULE_DESCRIPTION(DRV_DESCRIPTION); |
28 MODULE_DESCRIPTION(DRV_DESCRIPTION); |
30 MODULE_AUTHOR("Patrick Bruenn <p.bruenn@beckhoff.com>"); |
29 MODULE_AUTHOR("Patrick Bruenn <p.bruenn@beckhoff.com>"); |
31 MODULE_LICENSE("GPL"); |
30 MODULE_LICENSE("GPL"); |
271 ccatdev->pdev = pdev; |
270 ccatdev->pdev = pdev; |
272 pci_set_drvdata(pdev, ccatdev); |
271 pci_set_drvdata(pdev, ccatdev); |
273 |
272 |
274 status = pci_enable_device_mem(pdev); |
273 status = pci_enable_device_mem(pdev); |
275 if (status) { |
274 if (status) { |
276 pr_info("enable %s failed: %d\n", pdev->dev.kobj.name, status); |
275 pr_err("enable %s failed: %d\n", pdev->dev.kobj.name, status); |
277 goto cleanup_pci_device; |
276 return status; |
278 } |
277 } |
279 |
278 |
280 status = pci_read_config_byte(pdev, PCI_REVISION_ID, &revision); |
279 status = pci_read_config_byte(pdev, PCI_REVISION_ID, &rev); |
281 if (status) { |
280 if (status) { |
282 pr_warn("read CCAT pci revision failed with %d\n", status); |
281 pr_err("read CCAT pci revision failed with %d\n", status); |
283 goto cleanup_pci_device; |
282 goto disable_device; |
284 } |
283 } |
285 |
284 |
286 if ((status = pci_request_regions(pdev, KBUILD_MODNAME))) { |
285 status = pci_request_regions(pdev, KBUILD_MODNAME); |
287 pr_info("allocate mem_regions failed.\n"); |
286 if (status) { |
288 goto cleanup_pci_device; |
287 pr_err("allocate mem_regions failed.\n"); |
289 } |
288 goto disable_device; |
290 |
289 } |
291 /* CCAT is unable to access memory above 4 GB */ |
290 |
292 if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32))) { |
291 status = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
293 pr_debug("32 bit DMA supported, pci rev: %u\n", revision); |
292 if (status) { |
|
293 status = |
|
294 dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
|
295 if (status) { |
|
296 pr_err("No suitable DMA available, pci rev: %u\n", rev); |
|
297 goto release_regions; |
|
298 } |
|
299 pr_debug("32 bit DMA supported, pci rev: %u\n", rev); |
294 } else { |
300 } else { |
295 pr_warn("No suitable DMA available, pci rev: %u\n", revision); |
301 pr_debug("64 bit DMA supported, pci rev: %u\n", rev); |
296 } |
302 } |
297 |
303 |
298 if (!(ccatdev->bar_0 = pci_iomap(pdev, 0, 0))) { |
304 ccatdev->bar_0 = pci_iomap(pdev, 0, 0); |
299 pr_warn("initialization of bar0 failed.\n"); |
305 if (!ccatdev->bar_0) { |
|
306 pr_err("initialization of bar0 failed.\n"); |
300 status = -EIO; |
307 status = -EIO; |
301 goto cleanup_pci_device; |
308 goto release_regions; |
302 } |
309 } |
303 |
310 |
304 if (!(ccatdev->bar_2 = pci_iomap(pdev, 2, 0))) { |
311 ccatdev->bar_2 = pci_iomap(pdev, 2, 0); |
|
312 if (!ccatdev->bar_2) { |
305 pr_warn("initialization of optional bar2 failed.\n"); |
313 pr_warn("initialization of optional bar2 failed.\n"); |
306 } |
314 } |
307 |
315 |
308 pci_set_master(pdev); |
316 pci_set_master(pdev); |
309 if (ccat_functions_init(ccatdev)) { |
317 if (ccat_functions_init(ccatdev)) { |
310 pr_warn("some functions couldn't be initialized\n"); |
318 pr_warn("some functions couldn't be initialized\n"); |
311 } |
319 } |
312 return 0; |
320 return 0; |
313 cleanup_pci_device: |
321 |
|
322 release_regions: |
|
323 pci_release_regions(pdev); |
|
324 disable_device: |
314 pci_disable_device(pdev); |
325 pci_disable_device(pdev); |
315 return status; |
326 return status; |
316 } |
327 } |
317 |
328 |
318 static void ccat_pci_remove(struct pci_dev *pdev) |
329 static void ccat_pci_remove(struct pci_dev *pdev) |