Aaro Koskinen | 6762098 | 2015-04-04 22:51:21 +0300 | [diff] [blame] | 1 | /* |
| 2 | * This file is based on code from OCTEON SDK by Cavium Networks. |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 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. |
Aaro Koskinen | 6762098 | 2015-04-04 22:51:21 +0300 | [diff] [blame] | 9 | */ |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 10 | |
Janne Huttunen | 1d39a5e | 2015-08-13 16:21:46 +0300 | [diff] [blame] | 11 | #include <asm/octeon/cvmx-pip.h> |
| 12 | #include <asm/octeon/cvmx-helper.h> |
| 13 | #include <asm/octeon/cvmx-helper-util.h> |
| 14 | |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 15 | /** |
David Daney | ec977c5 | 2010-02-16 17:25:32 -0800 | [diff] [blame] | 16 | * cvm_oct_get_buffer_ptr - convert packet data address to pointer |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 17 | * @packet_ptr: Packet data hardware address |
David Daney | ec977c5 | 2010-02-16 17:25:32 -0800 | [diff] [blame] | 18 | * |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 19 | * Returns Packet buffer pointer |
| 20 | */ |
| 21 | static inline void *cvm_oct_get_buffer_ptr(union cvmx_buf_ptr packet_ptr) |
| 22 | { |
| 23 | return cvmx_phys_to_ptr(((packet_ptr.s.addr >> 7) - packet_ptr.s.back) |
| 24 | << 7); |
| 25 | } |
| 26 | |
| 27 | /** |
Justin P. Mattock | 215c47c | 2012-03-26 21:34:18 -0700 | [diff] [blame] | 28 | * INTERFACE - convert IPD port to logical interface |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 29 | * @ipd_port: Port to check |
| 30 | * |
| 31 | * Returns Logical interface |
| 32 | */ |
| 33 | static inline int INTERFACE(int ipd_port) |
| 34 | { |
Aaro Koskinen | 9eca499 | 2016-06-29 15:20:45 +0300 | [diff] [blame] | 35 | int interface; |
Janne Huttunen | 1d39a5e | 2015-08-13 16:21:46 +0300 | [diff] [blame] | 36 | |
Aaro Koskinen | 9eca499 | 2016-06-29 15:20:45 +0300 | [diff] [blame] | 37 | if (ipd_port == CVMX_PIP_NUM_INPUT_PORTS) |
| 38 | return 10; |
| 39 | interface = cvmx_helper_get_interface_num(ipd_port); |
Janne Huttunen | 1d39a5e | 2015-08-13 16:21:46 +0300 | [diff] [blame] | 40 | if (interface >= 0) |
| 41 | return interface; |
Craig Kewley | 355e6e4 | 2017-05-01 21:22:35 +0100 | [diff] [blame] | 42 | panic("Illegal ipd_port %d passed to %s\n", ipd_port, __func__); |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | /** |
David Daney | ec977c5 | 2010-02-16 17:25:32 -0800 | [diff] [blame] | 46 | * INDEX - convert IPD/PKO port number to the port's interface index |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 47 | * @ipd_port: Port to check |
| 48 | * |
| 49 | * Returns Index into interface port list |
| 50 | */ |
| 51 | static inline int INDEX(int ipd_port) |
| 52 | { |
Janne Huttunen | 1d39a5e | 2015-08-13 16:21:46 +0300 | [diff] [blame] | 53 | return cvmx_helper_get_interface_index_num(ipd_port); |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 54 | } |