xref: /linux/drivers/net/ethernet/marvell/octeontx2/af/mbox.h (revision fe8ecccc10b3adc071de05ca7af728ca1a4ac9aa)
1 /* SPDX-License-Identifier: GPL-2.0
2  * Marvell OcteonTx2 RVU Admin Function driver
3  *
4  * Copyright (C) 2018 Marvell International Ltd.
5  *
6  * This program 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 #ifndef MBOX_H
12 #define MBOX_H
13 
14 #include <linux/etherdevice.h>
15 #include <linux/sizes.h>
16 
17 #include "rvu_struct.h"
18 
19 #define MBOX_SIZE		SZ_64K
20 
21 /* AF/PF: PF initiated, PF/VF VF initiated */
22 #define MBOX_DOWN_RX_START	0
23 #define MBOX_DOWN_RX_SIZE	(46 * SZ_1K)
24 #define MBOX_DOWN_TX_START	(MBOX_DOWN_RX_START + MBOX_DOWN_RX_SIZE)
25 #define MBOX_DOWN_TX_SIZE	(16 * SZ_1K)
26 /* AF/PF: AF initiated, PF/VF PF initiated */
27 #define MBOX_UP_RX_START	(MBOX_DOWN_TX_START + MBOX_DOWN_TX_SIZE)
28 #define MBOX_UP_RX_SIZE		SZ_1K
29 #define MBOX_UP_TX_START	(MBOX_UP_RX_START + MBOX_UP_RX_SIZE)
30 #define MBOX_UP_TX_SIZE		SZ_1K
31 
32 #if MBOX_UP_TX_SIZE + MBOX_UP_TX_START != MBOX_SIZE
33 # error "incorrect mailbox area sizes"
34 #endif
35 
36 #define INTR_MASK(pfvfs) ((pfvfs < 64) ? (BIT_ULL(pfvfs) - 1) : (~0ull))
37 
38 #define MBOX_RSP_TIMEOUT	1000 /* in ms, Time to wait for mbox response */
39 
40 #define MBOX_MSG_ALIGN		16  /* Align mbox msg start to 16bytes */
41 
42 /* Mailbox directions */
43 #define MBOX_DIR_AFPF		0  /* AF replies to PF */
44 #define MBOX_DIR_PFAF		1  /* PF sends messages to AF */
45 #define MBOX_DIR_PFVF		2  /* PF replies to VF */
46 #define MBOX_DIR_VFPF		3  /* VF sends messages to PF */
47 #define MBOX_DIR_AFPF_UP	4  /* AF sends messages to PF */
48 #define MBOX_DIR_PFAF_UP	5  /* PF replies to AF */
49 #define MBOX_DIR_PFVF_UP	6  /* PF sends messages to VF */
50 #define MBOX_DIR_VFPF_UP	7  /* VF replies to PF */
51 
52 struct otx2_mbox_dev {
53 	void	    *mbase;   /* This dev's mbox region */
54 	spinlock_t  mbox_lock;
55 	u16         msg_size; /* Total msg size to be sent */
56 	u16         rsp_size; /* Total rsp size to be sure the reply is ok */
57 	u16         num_msgs; /* No of msgs sent or waiting for response */
58 	u16         msgs_acked; /* No of msgs for which response is received */
59 };
60 
61 struct otx2_mbox {
62 	struct pci_dev *pdev;
63 	void   *hwbase;  /* Mbox region advertised by HW */
64 	void   *reg_base;/* CSR base for this dev */
65 	u64    trigger;  /* Trigger mbox notification */
66 	u16    tr_shift; /* Mbox trigger shift */
67 	u64    rx_start; /* Offset of Rx region in mbox memory */
68 	u64    tx_start; /* Offset of Tx region in mbox memory */
69 	u16    rx_size;  /* Size of Rx region */
70 	u16    tx_size;  /* Size of Tx region */
71 	u16    ndevs;    /* The number of peers */
72 	struct otx2_mbox_dev *dev;
73 };
74 
75 /* Header which preceeds all mbox messages */
76 struct mbox_hdr {
77 	u16  num_msgs;   /* No of msgs embedded */
78 };
79 
80 /* Header which preceeds every msg and is also part of it */
81 struct mbox_msghdr {
82 	u16 pcifunc;     /* Who's sending this msg */
83 	u16 id;          /* Mbox message ID */
84 #define OTX2_MBOX_REQ_SIG (0xdead)
85 #define OTX2_MBOX_RSP_SIG (0xbeef)
86 	u16 sig;         /* Signature, for validating corrupted msgs */
87 #define OTX2_MBOX_VERSION (0x0001)
88 	u16 ver;         /* Version of msg's structure for this ID */
89 	u16 next_msgoff; /* Offset of next msg within mailbox region */
90 	int rc;          /* Msg process'ed response code */
91 };
92 
93 void otx2_mbox_reset(struct otx2_mbox *mbox, int devid);
94 void otx2_mbox_destroy(struct otx2_mbox *mbox);
95 int otx2_mbox_init(struct otx2_mbox *mbox, void __force *hwbase,
96 		   struct pci_dev *pdev, void __force *reg_base,
97 		   int direction, int ndevs);
98 void otx2_mbox_msg_send(struct otx2_mbox *mbox, int devid);
99 int otx2_mbox_wait_for_rsp(struct otx2_mbox *mbox, int devid);
100 int otx2_mbox_busy_poll_for_rsp(struct otx2_mbox *mbox, int devid);
101 struct mbox_msghdr *otx2_mbox_alloc_msg_rsp(struct otx2_mbox *mbox, int devid,
102 					    int size, int size_rsp);
103 struct mbox_msghdr *otx2_mbox_get_rsp(struct otx2_mbox *mbox, int devid,
104 				      struct mbox_msghdr *msg);
105 int otx2_reply_invalid_msg(struct otx2_mbox *mbox, int devid,
106 			   u16 pcifunc, u16 id);
107 bool otx2_mbox_nonempty(struct otx2_mbox *mbox, int devid);
108 const char *otx2_mbox_id2name(u16 id);
109 static inline struct mbox_msghdr *otx2_mbox_alloc_msg(struct otx2_mbox *mbox,
110 						      int devid, int size)
111 {
112 	return otx2_mbox_alloc_msg_rsp(mbox, devid, size, 0);
113 }
114 
115 /* Mailbox message types */
116 #define MBOX_MSG_MASK				0xFFFF
117 #define MBOX_MSG_INVALID			0xFFFE
118 #define MBOX_MSG_MAX				0xFFFF
119 
120 #define MBOX_MESSAGES							\
121 /* Generic mbox IDs (range 0x000 - 0x1FF) */				\
122 M(READY,		0x001, msg_req, ready_msg_rsp)			\
123 M(ATTACH_RESOURCES,	0x002, rsrc_attach, msg_rsp)			\
124 M(DETACH_RESOURCES,	0x003, rsrc_detach, msg_rsp)			\
125 M(MSIX_OFFSET,		0x004, msg_req, msix_offset_rsp)		\
126 /* CGX mbox IDs (range 0x200 - 0x3FF) */				\
127 /* NPA mbox IDs (range 0x400 - 0x5FF) */				\
128 /* SSO/SSOW mbox IDs (range 0x600 - 0x7FF) */				\
129 /* TIM mbox IDs (range 0x800 - 0x9FF) */				\
130 /* CPT mbox IDs (range 0xA00 - 0xBFF) */				\
131 /* NPC mbox IDs (range 0x6000 - 0x7FFF) */				\
132 /* NIX mbox IDs (range 0x8000 - 0xFFFF) */				\
133 
134 enum {
135 #define M(_name, _id, _1, _2) MBOX_MSG_ ## _name = _id,
136 MBOX_MESSAGES
137 #undef M
138 };
139 
140 /* Mailbox message formats */
141 
142 /* Generic request msg used for those mbox messages which
143  * don't send any data in the request.
144  */
145 struct msg_req {
146 	struct mbox_msghdr hdr;
147 };
148 
149 /* Generic rsponse msg used a ack or response for those mbox
150  * messages which doesn't have a specific rsp msg format.
151  */
152 struct msg_rsp {
153 	struct mbox_msghdr hdr;
154 };
155 
156 struct ready_msg_rsp {
157 	struct mbox_msghdr hdr;
158 	u16    sclk_feq;	/* SCLK frequency */
159 };
160 
161 /* Structure for requesting resource provisioning.
162  * 'modify' flag to be used when either requesting more
163  * or to detach partial of a cetain resource type.
164  * Rest of the fields specify how many of what type to
165  * be attached.
166  */
167 struct rsrc_attach {
168 	struct mbox_msghdr hdr;
169 	u8   modify:1;
170 	u8   npalf:1;
171 	u8   nixlf:1;
172 	u16  sso;
173 	u16  ssow;
174 	u16  timlfs;
175 	u16  cptlfs;
176 };
177 
178 /* Structure for relinquishing resources.
179  * 'partial' flag to be used when relinquishing all resources
180  * but only of a certain type. If not set, all resources of all
181  * types provisioned to the RVU function will be detached.
182  */
183 struct rsrc_detach {
184 	struct mbox_msghdr hdr;
185 	u8 partial:1;
186 	u8 npalf:1;
187 	u8 nixlf:1;
188 	u8 sso:1;
189 	u8 ssow:1;
190 	u8 timlfs:1;
191 	u8 cptlfs:1;
192 };
193 
194 #define MSIX_VECTOR_INVALID	0xFFFF
195 #define MAX_RVU_BLKLF_CNT	256
196 
197 struct msix_offset_rsp {
198 	struct mbox_msghdr hdr;
199 	u16  npa_msixoff;
200 	u16  nix_msixoff;
201 	u8   sso;
202 	u8   ssow;
203 	u8   timlfs;
204 	u8   cptlfs;
205 	u16  sso_msixoff[MAX_RVU_BLKLF_CNT];
206 	u16  ssow_msixoff[MAX_RVU_BLKLF_CNT];
207 	u16  timlf_msixoff[MAX_RVU_BLKLF_CNT];
208 	u16  cptlf_msixoff[MAX_RVU_BLKLF_CNT];
209 };
210 
211 #endif /* MBOX_H */
212