-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathpager_if.h
More file actions
208 lines (179 loc) · 5.75 KB
/
pager_if.h
File metadata and controls
208 lines (179 loc) · 5.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#ifndef _MORSE_PAGER_IF_H_
#define _MORSE_PAGER_IF_H_
/*
* Copyright 2017-2022 Morse Micro
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
*/
#include <linux/skbuff.h>
#include <linux/workqueue.h>
#include "skbq.h"
/* This is a common interface for pagers. It includes common code between the
* hardware and software implementations for handling interrupts between
* the chip and host.
*/
#define MORSE_PAGER_FLAGS_DIR_TO_HOST BIT(0)
#define MORSE_PAGER_FLAGS_DIR_TO_CHIP BIT(1)
#define MORSE_PAGER_FLAGS_FREE BIT(2)
#define MORSE_PAGER_FLAGS_POPULATED BIT(3)
#define MORSE_PAGER_INT_STS(mors) MORSE_REG_INT1_STS(mors)
#define MORSE_PAGER_INT_EN(mors) MORSE_REG_INT1_EN(mors)
#define MORSE_PAGER_INT_SET(mors) MORSE_REG_INT1_SET(mors)
#define MORSE_PAGER_INT_CLR(mors) MORSE_REG_INT1_CLR(mors)
#define MORSE_PAGER_TRGR_STS(mors) MORSE_REG_TRGR1_STS(mors)
#define MORSE_PAGER_TRGR_EN(mors) MORSE_REG_TRGR1_EN(mors)
#define MORSE_PAGER_TRGR_SET(mors) MORSE_REG_TRGR1_SET(mors)
#define MORSE_PAGER_TRGR_CLR(mors) MORSE_REG_TRGR1_CLR(mors)
#define MORSE_PAGER_IRQ_MASK(ID) (1 << (ID))
#define MORSE_PAGER_BYPASS_TX_STATUS_IRQ_NUM (15)
#define MORSE_PAGER_IRQ_BYPASS_TX_STATUS_AVAILABLE BIT(MORSE_PAGER_BYPASS_TX_STATUS_IRQ_NUM)
#define MORSE_PAGER_BYPASS_TX_STATUS_FIFO_DEPTH (4)
#define MORSE_PAGER_BYPASS_CMD_RESP_IRQ_NUM (29)
#define MORSE_PAGER_IRQ_BYPASS_CMD_RESP_AVAILABLE BIT(MORSE_PAGER_BYPASS_CMD_RESP_IRQ_NUM)
#define MORSE_PAGER_BYPASS_CMD_RESP_FIFO_DEPTH (2)
struct morse;
struct morse_pageset;
struct morse_page;
struct morse_pager {
struct morse *mors;
struct work_struct work;
struct morse_skbq mq;
/* Parent pageset, filled in morse_pageset_init */
struct morse_pageset *parent;
u8 id; /* ID of pager */
u8 flags; /* Indicate direction of pager */
int num_pages; /* Maximum number of pages in this pager */
int page_size_bytes;
/* Pager implementation specific data and function pointers */
const struct morse_pager_ops *ops;
void *aux_data;
};
struct morse_pager_ops {
/**
* Puts a page into the given pager
*
* @pager: Pointer to pager instance to insert page into
* @page: Page to insert
*
* @return: Error code
*/
int (*put)(struct morse_pager *pager, struct morse_page *page);
/**
* Pops a page from the given pager
*
* @pager: Pointer to pager instance to take page from
* @page: Pointer to where to place popped page
*
* @return: Error code
* Note: If page is not available -EAGAIN is returned
*/
int (*pop)(struct morse_pager *pager, struct morse_page *page);
/**
* Notify the pager that there are pages available.
*
* @pager: Pointer to pager instance to notify
*
* @return: Error code
*/
int (*notify)(const struct morse_pager *pager);
/**
* Writes bytes from an SKB into a page's memory.
*
* Will raise an error if the number of bytes is
* greater than the page size.
*
* @pager: Pointer to pager instance to take page from
* @page: Pointer to page to write into
* @offset: Offset in bytes of data in page to write to (must be +ve)
* @buff: Buffer to fetch data from
* @num_bytes: Number of bytes to write
*
* @return: Error code
*/
int (*write_page)(struct morse_pager *pager, struct morse_page *page,
int offset, const char *buff, int num_bytes);
/**
* Reads bytes from a page's memory into an SKB.
*
* Will raise an error if the number of bytes to read is
* greater than the page size.
*
* @pager: Pointer to pager instance
* @page: Pointer to page to fetch data from
* @offset: Offset in bytes of data in page to read from (must be +ve)
* @buff: Buffer to write into
* @num_bytes: Number of bytes to read
*
* @return: Error code
*/
int (*read_page)(struct morse_pager *pager, struct morse_page *page,
int offset, char *buff, int num_bytes);
};
/**
* Initialise the morse pager instance.
* Does not perform any initialisation of the underlying pager implementation,
* it is expected you call the implementation specific init on *pager first.
*
* @mors: Morse chip instance
* @pager: Pointer to pager struct to initialise
* @page_size: Page size in bytes
* @flags: Pager flags (MORSE_PAGER_FLAGS_xxx)
* @id: Unique identifier for the pager
*
* @return: Error code
*/
int morse_pager_init(struct morse *mors, struct morse_pager *pager, int page_size, u8 flags, u8 id);
/**
* Prints info about the pager instance to a file.
*
* @mors: Morse chip instance
* @pager: Pointer to pager struct to print
* @file: Pointer to file to print to
*/
void morse_pager_show(struct morse *mors, struct morse_pager *pager, struct seq_file *file);
/**
* Cleans up memory used by pager instance.
*
* @pager: Pointer to pager struct to delete.
*/
void morse_pager_finish(struct morse_pager *pager);
/**
* Enables an interrupt for the given pager
*
* @pager: Pointer to pager interrupt to enable
* @enable: Enable (true) or disable (false) pager interrupt
*
* @return: Error code
*/
int morse_pager_irq_enable(const struct morse_pager *pager, bool enable);
/**
* morse_pager_tx_status_irq_enable() - Enables/disables interrupt for tx
* statuses to bypass the pager
*
* @mors Mors object.
* @enable Set to true for enable.
*
* Returns: 0 on success, else error code
*/
int morse_pager_tx_status_irq_enable(struct morse *mors, bool enable);
/**
* morse_pager_cmd_resp_irq_enable() - Enables/disables interrupt for cmd
* responses to bypass the pager
*
* @mors Mors object.
* @enable Set to true for enable.
*
* Returns: 0 on success, else error code
*/
int morse_pager_cmd_resp_irq_enable(struct morse *mors, bool enable);
/**
* Default IRQ handler for the pager
*
* @mors: Morse chip instance
* @status: Interrupt status register value
*
* @return: Error code
*/
int morse_pager_irq_handler(struct morse *mors, u32 status);
#endif /* !_MORSE_PAGER_IF_H_ */