1ba789a7741bd2514c098ea4ffa8b828c11f6c07
[linux-drm-fsl-dcu.git] / drivers / staging / octeon / ethernet-util.h
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
11 /**
12  * cvm_oct_get_buffer_ptr - convert packet data address to pointer
13  * @packet_ptr: Packet data hardware address
14  *
15  * Returns Packet buffer pointer
16  */
17 static inline void *cvm_oct_get_buffer_ptr(union cvmx_buf_ptr packet_ptr)
18 {
19         return cvmx_phys_to_ptr(((packet_ptr.s.addr >> 7) - packet_ptr.s.back)
20                                 << 7);
21 }
22
23 /**
24  * INTERFACE - convert IPD port to logical interface
25  * @ipd_port: Port to check
26  *
27  * Returns Logical interface
28  */
29 static inline int INTERFACE(int ipd_port)
30 {
31         if (ipd_port < 32)      /* Interface 0 or 1 for RGMII,GMII,SPI, etc */
32                 return ipd_port >> 4;
33         else if (ipd_port < 36) /* Interface 2 for NPI */
34                 return 2;
35         else if (ipd_port < 40) /* Interface 3 for loopback */
36                 return 3;
37         else if (ipd_port == 40)        /* Non existent interface for POW0 */
38                 return 4;
39         panic("Illegal ipd_port %d passed to INTERFACE\n", ipd_port);
40 }
41
42 /**
43  * INDEX - convert IPD/PKO port number to the port's interface index
44  * @ipd_port: Port to check
45  *
46  * Returns Index into interface port list
47  */
48 static inline int INDEX(int ipd_port)
49 {
50         if (ipd_port < 32)
51                 return ipd_port & 15;
52         return ipd_port & 3;
53 }