18c978d05SRaghu Vatsavayi /**********************************************************************
28c978d05SRaghu Vatsavayi  * Author: Cavium, Inc.
38c978d05SRaghu Vatsavayi  *
48c978d05SRaghu Vatsavayi  * Contact: support@cavium.com
58c978d05SRaghu Vatsavayi  *          Please include "LiquidIO" in the subject.
68c978d05SRaghu Vatsavayi  *
78c978d05SRaghu Vatsavayi  * Copyright (c) 2003-2016 Cavium, Inc.
88c978d05SRaghu Vatsavayi  *
98c978d05SRaghu Vatsavayi  * This file is free software; you can redistribute it and/or modify
108c978d05SRaghu Vatsavayi  * it under the terms of the GNU General Public License, Version 2, as
118c978d05SRaghu Vatsavayi  * published by the Free Software Foundation.
128c978d05SRaghu Vatsavayi  *
138c978d05SRaghu Vatsavayi  * This file is distributed in the hope that it will be useful, but
148c978d05SRaghu Vatsavayi  * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
158c978d05SRaghu Vatsavayi  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
168c978d05SRaghu Vatsavayi  * NONINFRINGEMENT.  See the GNU General Public License for more details.
178c978d05SRaghu Vatsavayi  ***********************************************************************/
188c978d05SRaghu Vatsavayi #ifndef __MAILBOX_H__
198c978d05SRaghu Vatsavayi #define __MAILBOX_H__
208c978d05SRaghu Vatsavayi 
218c978d05SRaghu Vatsavayi /* Macros for Mail Box Communication */
228c978d05SRaghu Vatsavayi 
238c978d05SRaghu Vatsavayi #define OCTEON_MBOX_DATA_MAX	32
248c978d05SRaghu Vatsavayi 
258c978d05SRaghu Vatsavayi #define OCTEON_VF_ACTIVE		0x1
268c978d05SRaghu Vatsavayi #define OCTEON_VF_FLR_REQUEST		0x2
278c978d05SRaghu Vatsavayi #define OCTEON_PF_CHANGED_VF_MACADDR	0x4
288c978d05SRaghu Vatsavayi 
298c978d05SRaghu Vatsavayi /*Macro for Read acknowldgement*/
308c978d05SRaghu Vatsavayi #define OCTEON_PFVFACK			0xffffffffffffffff
318c978d05SRaghu Vatsavayi #define OCTEON_PFVFSIG			0x1122334455667788
328c978d05SRaghu Vatsavayi #define OCTEON_PFVFERR			0xDEADDEADDEADDEAD
338c978d05SRaghu Vatsavayi 
348c978d05SRaghu Vatsavayi #define LIO_MBOX_WRITE_WAIT_CNT         1000
35a8ac1a55SPrasad Kanneganti #define LIO_MBOX_WRITE_WAIT_TIME        msecs_to_jiffies(1)
368c978d05SRaghu Vatsavayi 
378c978d05SRaghu Vatsavayi enum octeon_mbox_cmd_status {
388c978d05SRaghu Vatsavayi 	OCTEON_MBOX_STATUS_SUCCESS = 0,
398c978d05SRaghu Vatsavayi 	OCTEON_MBOX_STATUS_FAILED = 1,
408c978d05SRaghu Vatsavayi 	OCTEON_MBOX_STATUS_BUSY = 2
418c978d05SRaghu Vatsavayi };
428c978d05SRaghu Vatsavayi 
438c978d05SRaghu Vatsavayi enum octeon_mbox_message_type {
448c978d05SRaghu Vatsavayi 	OCTEON_MBOX_REQUEST = 0,
458c978d05SRaghu Vatsavayi 	OCTEON_MBOX_RESPONSE = 1
468c978d05SRaghu Vatsavayi };
478c978d05SRaghu Vatsavayi 
488c978d05SRaghu Vatsavayi union octeon_mbox_message {
498c978d05SRaghu Vatsavayi 	u64 u64;
508c978d05SRaghu Vatsavayi 	struct {
518c978d05SRaghu Vatsavayi 		u16 type : 1;
528c978d05SRaghu Vatsavayi 		u16 resp_needed : 1;
538c978d05SRaghu Vatsavayi 		u16 cmd : 6;
548c978d05SRaghu Vatsavayi 		u16 len : 8;
558c978d05SRaghu Vatsavayi 		u8 params[6];
568c978d05SRaghu Vatsavayi 	} s;
578c978d05SRaghu Vatsavayi };
588c978d05SRaghu Vatsavayi 
598c978d05SRaghu Vatsavayi typedef void (*octeon_mbox_callback_t)(void *, void *, void *);
608c978d05SRaghu Vatsavayi 
618c978d05SRaghu Vatsavayi struct octeon_mbox_cmd {
628c978d05SRaghu Vatsavayi 	union octeon_mbox_message msg;
638c978d05SRaghu Vatsavayi 	u64 data[OCTEON_MBOX_DATA_MAX];
648c978d05SRaghu Vatsavayi 	u32 q_no;
658c978d05SRaghu Vatsavayi 	u32 recv_len;
668c978d05SRaghu Vatsavayi 	u32 recv_status;
678c978d05SRaghu Vatsavayi 	octeon_mbox_callback_t fn;
688c978d05SRaghu Vatsavayi 	void *fn_arg;
698c978d05SRaghu Vatsavayi };
708c978d05SRaghu Vatsavayi 
718c978d05SRaghu Vatsavayi enum octeon_mbox_state {
728c978d05SRaghu Vatsavayi 	OCTEON_MBOX_STATE_IDLE = 1,
738c978d05SRaghu Vatsavayi 	OCTEON_MBOX_STATE_REQUEST_RECEIVING = 2,
748c978d05SRaghu Vatsavayi 	OCTEON_MBOX_STATE_REQUEST_RECEIVED = 4,
758c978d05SRaghu Vatsavayi 	OCTEON_MBOX_STATE_RESPONSE_PENDING = 8,
768c978d05SRaghu Vatsavayi 	OCTEON_MBOX_STATE_RESPONSE_RECEIVING = 16,
778c978d05SRaghu Vatsavayi 	OCTEON_MBOX_STATE_RESPONSE_RECEIVED = 16,
788c978d05SRaghu Vatsavayi 	OCTEON_MBOX_STATE_ERROR = 32
798c978d05SRaghu Vatsavayi };
808c978d05SRaghu Vatsavayi 
818c978d05SRaghu Vatsavayi struct octeon_mbox {
828c978d05SRaghu Vatsavayi 	/** A spinlock to protect access to this q_mbox. */
838c978d05SRaghu Vatsavayi 	spinlock_t lock;
848c978d05SRaghu Vatsavayi 
858c978d05SRaghu Vatsavayi 	struct octeon_device *oct_dev;
868c978d05SRaghu Vatsavayi 
878c978d05SRaghu Vatsavayi 	u32 q_no;
888c978d05SRaghu Vatsavayi 
898c978d05SRaghu Vatsavayi 	enum octeon_mbox_state state;
908c978d05SRaghu Vatsavayi 
918c978d05SRaghu Vatsavayi 	struct cavium_wk mbox_poll_wk;
928c978d05SRaghu Vatsavayi 
938c978d05SRaghu Vatsavayi 	/** SLI_MAC_PF_MBOX_INT for PF, SLI_PKT_MBOX_INT for VF. */
948c978d05SRaghu Vatsavayi 	void *mbox_int_reg;
958c978d05SRaghu Vatsavayi 
968c978d05SRaghu Vatsavayi 	/** SLI_PKT_PF_VF_MBOX_SIG(0) for PF, SLI_PKT_PF_VF_MBOX_SIG(1) for VF.
978c978d05SRaghu Vatsavayi 	 */
988c978d05SRaghu Vatsavayi 	void *mbox_write_reg;
998c978d05SRaghu Vatsavayi 
1008c978d05SRaghu Vatsavayi 	/** SLI_PKT_PF_VF_MBOX_SIG(1) for PF, SLI_PKT_PF_VF_MBOX_SIG(0) for VF.
1018c978d05SRaghu Vatsavayi 	 */
1028c978d05SRaghu Vatsavayi 	void *mbox_read_reg;
1038c978d05SRaghu Vatsavayi 
1048c978d05SRaghu Vatsavayi 	struct octeon_mbox_cmd mbox_req;
1058c978d05SRaghu Vatsavayi 
1068c978d05SRaghu Vatsavayi 	struct octeon_mbox_cmd mbox_resp;
1078c978d05SRaghu Vatsavayi 
1088c978d05SRaghu Vatsavayi };
1098c978d05SRaghu Vatsavayi 
1108c978d05SRaghu Vatsavayi int octeon_mbox_read(struct octeon_mbox *mbox);
1118c978d05SRaghu Vatsavayi int octeon_mbox_write(struct octeon_device *oct,
1128c978d05SRaghu Vatsavayi 		      struct octeon_mbox_cmd *mbox_cmd);
1138c978d05SRaghu Vatsavayi int octeon_mbox_process_message(struct octeon_mbox *mbox);
1148c978d05SRaghu Vatsavayi 
1158c978d05SRaghu Vatsavayi #endif
116