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 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. unsigned int reg = PCI_BASE_ADDRESS_0;
  71. uint32_t bar_low;
  72. efx->netdev = netdev;
  73. efx->revision = revision;
  74. /* Find the memory bar to use */
  75. pci_read_config_dword(pci, reg, &bar_low);
  76. if ((bar_low & PCI_BASE_ADDRESS_IO_MASK) == PCI_BASE_ADDRESS_SPACE_IO)
  77. reg = PCI_BASE_ADDRESS_2;
  78. efx->mmio_start = pci_bar_start(pci, reg);
  79. efx->mmio_len = pci_bar_size(pci, reg);
  80. efx->membase = ioremap(efx->mmio_start, efx->mmio_len);
  81. DBGCP(efx, "BAR of %lx bytes at phys %lx mapped at %p\n",
  82. efx->mmio_len, efx->mmio_start, efx->membase);
  83. /* Enable PCI access */
  84. adjust_pci_device(pci);
  85. }
  86. void efx_remove(struct net_device *netdev)
  87. {
  88. struct efx_nic *efx = netdev_priv(netdev);
  89. iounmap(efx->membase);
  90. efx->membase = NULL;
  91. }