ethernet-util.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * This file is based on code from OCTEON SDK by Cavium Networks.
  3. *
  4. * Copyright (c) 2003-2007 Cavium Networks
  5. *
  6. * This file is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License, Version 2, as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <asm/octeon/cvmx-pip.h>
  11. #include <asm/octeon/cvmx-helper.h>
  12. #include <asm/octeon/cvmx-helper-util.h>
  13. /**
  14. * cvm_oct_get_buffer_ptr - convert packet data address to pointer
  15. * @packet_ptr: Packet data hardware address
  16. *
  17. * Returns Packet buffer pointer
  18. */
  19. static inline void *cvm_oct_get_buffer_ptr(union cvmx_buf_ptr packet_ptr)
  20. {
  21. return cvmx_phys_to_ptr(((packet_ptr.s.addr >> 7) - packet_ptr.s.back)
  22. << 7);
  23. }
  24. /**
  25. * INTERFACE - convert IPD port to logical interface
  26. * @ipd_port: Port to check
  27. *
  28. * Returns Logical interface
  29. */
  30. static inline int INTERFACE(int ipd_port)
  31. {
  32. int interface;
  33. if (ipd_port == CVMX_PIP_NUM_INPUT_PORTS)
  34. return 10;
  35. interface = cvmx_helper_get_interface_num(ipd_port);
  36. if (interface >= 0)
  37. return interface;
  38. panic("Illegal ipd_port %d passed to INTERFACE\n", ipd_port);
  39. }
  40. /**
  41. * INDEX - convert IPD/PKO port number to the port's interface index
  42. * @ipd_port: Port to check
  43. *
  44. * Returns Index into interface port list
  45. */
  46. static inline int INDEX(int ipd_port)
  47. {
  48. return cvmx_helper_get_interface_index_num(ipd_port);
  49. }