blob: 45f024bc5e33f777d2a320633dff9eb55dfac64d [file] [log] [blame]
Aaro Koskinen67620982015-04-04 22:51:21 +03001/*
2 * This file is based on code from OCTEON SDK by Cavium Networks.
David Daney80ff0fd2009-05-05 17:35:21 -07003 *
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 Koskinen67620982015-04-04 22:51:21 +03009 */
David Daney80ff0fd2009-05-05 17:35:21 -070010
Janne Huttunen1d39a5e2015-08-13 16:21:46 +030011#include <asm/octeon/cvmx-pip.h>
12#include <asm/octeon/cvmx-helper.h>
13#include <asm/octeon/cvmx-helper-util.h>
14
David Daney80ff0fd2009-05-05 17:35:21 -070015/**
David Daneyec977c52010-02-16 17:25:32 -080016 * cvm_oct_get_buffer_ptr - convert packet data address to pointer
David Daney80ff0fd2009-05-05 17:35:21 -070017 * @packet_ptr: Packet data hardware address
David Daneyec977c52010-02-16 17:25:32 -080018 *
David Daney80ff0fd2009-05-05 17:35:21 -070019 * Returns Packet buffer pointer
20 */
21static 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. Mattock215c47c2012-03-26 21:34:18 -070028 * INTERFACE - convert IPD port to logical interface
David Daney80ff0fd2009-05-05 17:35:21 -070029 * @ipd_port: Port to check
30 *
31 * Returns Logical interface
32 */
33static inline int INTERFACE(int ipd_port)
34{
Janne Huttunen1d39a5e2015-08-13 16:21:46 +030035 int interface = cvmx_helper_get_interface_num(ipd_port);
36
37 if (interface >= 0)
38 return interface;
39 else if (ipd_port == CVMX_PIP_NUM_INPUT_PORTS)
40 return 10;
Dilek Uzulmezaa66d882014-09-27 14:58:31 +030041 panic("Illegal ipd_port %d passed to INTERFACE\n", ipd_port);
David Daney80ff0fd2009-05-05 17:35:21 -070042}
43
44/**
David Daneyec977c52010-02-16 17:25:32 -080045 * INDEX - convert IPD/PKO port number to the port's interface index
David Daney80ff0fd2009-05-05 17:35:21 -070046 * @ipd_port: Port to check
47 *
48 * Returns Index into interface port list
49 */
50static inline int INDEX(int ipd_port)
51{
Janne Huttunen1d39a5e2015-08-13 16:21:46 +030052 return cvmx_helper_get_interface_index_num(ipd_port);
David Daney80ff0fd2009-05-05 17:35:21 -070053}