You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

efx_common.c 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**************************************************************************
  2. *
  3. * Driver datapath common code for Solarflare network cards
  4. *
  5. * Written by Shradha Shah <sshah@solarflare.com>
  6. *
  7. * Copyright Fen Systems Ltd. 2005
  8. * Copyright Level 5 Networks Inc. 2005
  9. * Copyright 2006-2017 Solarflare Communications Inc.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of the
  14. * License, or any later version.
  15. *
  16. * You can also choose to distribute this program under the terms of
  17. * the Unmodified Binary Distribution Licence (as given in the file
  18. * COPYING.UBDL), provided that you have satisfied its requirements.
  19. *
  20. ***************************************************************************/
  21. #include <stdint.h>
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. #include <unistd.h>
  25. #include <errno.h>
  26. #include <assert.h>
  27. #include <byteswap.h>
  28. #include <ipxe/io.h>
  29. #include <ipxe/pci.h>
  30. #include <ipxe/malloc.h>
  31. #include <ipxe/iobuf.h>
  32. #include <ipxe/netdevice.h>
  33. #include "efx_common.h"
  34. #include "efx_bitfield.h"
  35. #include "mc_driver_pcol.h"
  36. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  37. /*******************************************************************************
  38. *
  39. *
  40. * Low-level hardware access
  41. *
  42. *
  43. ******************************************************************************/
  44. void
  45. efx_writel(struct efx_nic *efx, efx_dword_t *value, unsigned int reg)
  46. {
  47. DBGCIO(efx, "Writing partial register %x with " EFX_DWORD_FMT "\n",
  48. reg, EFX_DWORD_VAL(*value));
  49. _efx_writel(efx, value->u32[0], reg);
  50. }
  51. void
  52. efx_readl(struct efx_nic *efx, efx_dword_t *value, unsigned int reg)
  53. {
  54. value->u32[0] = _efx_readl(efx, reg);
  55. DBGCIO(efx, "Read from register %x, got " EFX_DWORD_FMT "\n",
  56. reg, EFX_DWORD_VAL(*value));
  57. }
  58. /*******************************************************************************
  59. *
  60. *
  61. * Inititialization and Close
  62. *
  63. *
  64. ******************************************************************************/
  65. void efx_probe(struct net_device *netdev, enum efx_revision revision)
  66. {
  67. struct efx_nic *efx = netdev_priv(netdev);
  68. struct pci_device *pci = container_of(netdev->dev,
  69. struct pci_device, dev);
  70. efx->netdev = netdev;
  71. efx->revision = revision;
  72. /* MMIO bar */
  73. efx->mmio_start = pci_bar_start(pci, PCI_BASE_ADDRESS_2);
  74. efx->mmio_len = pci_bar_size(pci, PCI_BASE_ADDRESS_2);
  75. efx->membase = ioremap(efx->mmio_start, efx->mmio_len);
  76. DBGCP(efx, "BAR of %lx bytes at phys %lx mapped at %p\n",
  77. efx->mmio_len, efx->mmio_start, efx->membase);
  78. /* Enable PCI access */
  79. adjust_pci_device(pci);
  80. }
  81. void efx_remove(struct net_device *netdev)
  82. {
  83. struct efx_nic *efx = netdev_priv(netdev);
  84. iounmap(efx->membase);
  85. efx->membase = NULL;
  86. }