Raghu Vatsavayi | 8c978d0 | 2016-11-14 15:54:41 -0800 | [diff] [blame] | 1 | /********************************************************************** |
| 2 | * Author: Cavium, Inc. |
| 3 | * |
| 4 | * Contact: support@cavium.com |
| 5 | * Please include "LiquidIO" in the subject. |
| 6 | * |
| 7 | * Copyright (c) 2003-2016 Cavium, Inc. |
| 8 | * |
| 9 | * This file is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License, Version 2, as |
| 11 | * published by the Free Software Foundation. |
| 12 | * |
| 13 | * This file is distributed in the hope that it will be useful, but |
| 14 | * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty |
| 15 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or |
| 16 | * NONINFRINGEMENT. See the GNU General Public License for more details. |
| 17 | ***********************************************************************/ |
| 18 | #ifndef __MAILBOX_H__ |
| 19 | #define __MAILBOX_H__ |
| 20 | |
| 21 | /* Macros for Mail Box Communication */ |
| 22 | |
Prasad Kanneganti | d5c7d9b | 2017-05-25 10:42:14 -0700 | [diff] [blame] | 23 | #define OCTEON_MBOX_DATA_MAX 32 |
Raghu Vatsavayi | 8c978d0 | 2016-11-14 15:54:41 -0800 | [diff] [blame] | 24 | |
| 25 | #define OCTEON_VF_ACTIVE 0x1 |
| 26 | #define OCTEON_VF_FLR_REQUEST 0x2 |
| 27 | #define OCTEON_PF_CHANGED_VF_MACADDR 0x4 |
| 28 | |
| 29 | /*Macro for Read acknowldgement*/ |
Prasad Kanneganti | d5c7d9b | 2017-05-25 10:42:14 -0700 | [diff] [blame] | 30 | #define OCTEON_PFVFACK 0xffffffffffffffffULL |
| 31 | #define OCTEON_PFVFSIG 0x1122334455667788ULL |
| 32 | #define OCTEON_PFVFERR 0xDEADDEADDEADDEADULL |
Raghu Vatsavayi | 8c978d0 | 2016-11-14 15:54:41 -0800 | [diff] [blame] | 33 | |
Prasad Kanneganti | a8ac1a5 | 2017-01-11 17:40:27 -0800 | [diff] [blame] | 34 | #define LIO_MBOX_WRITE_WAIT_CNT 1000 |
| 35 | #define LIO_MBOX_WRITE_WAIT_TIME msecs_to_jiffies(1) |
Raghu Vatsavayi | 8c978d0 | 2016-11-14 15:54:41 -0800 | [diff] [blame] | 36 | |
| 37 | enum octeon_mbox_cmd_status { |
| 38 | OCTEON_MBOX_STATUS_SUCCESS = 0, |
| 39 | OCTEON_MBOX_STATUS_FAILED = 1, |
| 40 | OCTEON_MBOX_STATUS_BUSY = 2 |
| 41 | }; |
| 42 | |
| 43 | enum octeon_mbox_message_type { |
| 44 | OCTEON_MBOX_REQUEST = 0, |
| 45 | OCTEON_MBOX_RESPONSE = 1 |
| 46 | }; |
| 47 | |
| 48 | union octeon_mbox_message { |
| 49 | u64 u64; |
| 50 | struct { |
| 51 | u16 type : 1; |
| 52 | u16 resp_needed : 1; |
| 53 | u16 cmd : 6; |
| 54 | u16 len : 8; |
| 55 | u8 params[6]; |
| 56 | } s; |
| 57 | }; |
| 58 | |
| 59 | typedef void (*octeon_mbox_callback_t)(void *, void *, void *); |
| 60 | |
| 61 | struct octeon_mbox_cmd { |
| 62 | union octeon_mbox_message msg; |
| 63 | u64 data[OCTEON_MBOX_DATA_MAX]; |
| 64 | u32 q_no; |
| 65 | u32 recv_len; |
| 66 | u32 recv_status; |
| 67 | octeon_mbox_callback_t fn; |
| 68 | void *fn_arg; |
| 69 | }; |
| 70 | |
| 71 | enum octeon_mbox_state { |
| 72 | OCTEON_MBOX_STATE_IDLE = 1, |
| 73 | OCTEON_MBOX_STATE_REQUEST_RECEIVING = 2, |
| 74 | OCTEON_MBOX_STATE_REQUEST_RECEIVED = 4, |
| 75 | OCTEON_MBOX_STATE_RESPONSE_PENDING = 8, |
| 76 | OCTEON_MBOX_STATE_RESPONSE_RECEIVING = 16, |
Prasad Kanneganti | d5c7d9b | 2017-05-25 10:42:14 -0700 | [diff] [blame] | 77 | OCTEON_MBOX_STATE_RESPONSE_RECEIVED = 32, |
| 78 | OCTEON_MBOX_STATE_ERROR = 64 |
Raghu Vatsavayi | 8c978d0 | 2016-11-14 15:54:41 -0800 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | struct octeon_mbox { |
| 82 | /** A spinlock to protect access to this q_mbox. */ |
| 83 | spinlock_t lock; |
| 84 | |
| 85 | struct octeon_device *oct_dev; |
| 86 | |
| 87 | u32 q_no; |
| 88 | |
| 89 | enum octeon_mbox_state state; |
| 90 | |
| 91 | struct cavium_wk mbox_poll_wk; |
| 92 | |
| 93 | /** SLI_MAC_PF_MBOX_INT for PF, SLI_PKT_MBOX_INT for VF. */ |
| 94 | void *mbox_int_reg; |
| 95 | |
| 96 | /** SLI_PKT_PF_VF_MBOX_SIG(0) for PF, SLI_PKT_PF_VF_MBOX_SIG(1) for VF. |
| 97 | */ |
| 98 | void *mbox_write_reg; |
| 99 | |
| 100 | /** SLI_PKT_PF_VF_MBOX_SIG(1) for PF, SLI_PKT_PF_VF_MBOX_SIG(0) for VF. |
| 101 | */ |
| 102 | void *mbox_read_reg; |
| 103 | |
| 104 | struct octeon_mbox_cmd mbox_req; |
| 105 | |
| 106 | struct octeon_mbox_cmd mbox_resp; |
| 107 | |
| 108 | }; |
| 109 | |
| 110 | int octeon_mbox_read(struct octeon_mbox *mbox); |
| 111 | int octeon_mbox_write(struct octeon_device *oct, |
| 112 | struct octeon_mbox_cmd *mbox_cmd); |
| 113 | int octeon_mbox_process_message(struct octeon_mbox *mbox); |
| 114 | |
| 115 | #endif |