xref: /linux-6.15/include/linux/ism.h (revision 89e7d2ba)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  *  Internal Shared Memory
4  *
5  *  Definitions for the ISM module
6  *
7  *  Copyright IBM Corp. 2022
8  */
9 #ifndef _ISM_H
10 #define _ISM_H
11 
12 #include <linux/workqueue.h>
13 
14 struct ism_dmb {
15 	u64 dmb_tok;
16 	u64 rgid;
17 	u32 dmb_len;
18 	u32 sba_idx;
19 	u32 vlan_valid;
20 	u32 vlan_id;
21 	void *cpu_addr;
22 	dma_addr_t dma_addr;
23 };
24 
25 /* Unless we gain unexpected popularity, this limit should hold for a while */
26 #define MAX_CLIENTS		8
27 #define ISM_NR_DMBS		1920
28 
29 struct ism_dev {
30 	spinlock_t lock; /* protects the ism device */
31 	struct list_head list;
32 	struct pci_dev *pdev;
33 	struct smcd_dev *smcd;
34 
35 	struct ism_sba *sba;
36 	dma_addr_t sba_dma_addr;
37 	DECLARE_BITMAP(sba_bitmap, ISM_NR_DMBS);
38 	u8 *sba_client_arr;	/* entries are indices into 'clients' array */
39 	void *priv[MAX_CLIENTS];
40 
41 	struct ism_eq *ieq;
42 	dma_addr_t ieq_dma_addr;
43 
44 	struct device dev;
45 	u64 local_gid;
46 	int ieq_idx;
47 
48 	atomic_t free_clients_cnt;
49 	atomic_t add_dev_cnt;
50 	wait_queue_head_t waitq;
51 };
52 
53 struct ism_event {
54 	u32 type;
55 	u32 code;
56 	u64 tok;
57 	u64 time;
58 	u64 info;
59 };
60 
61 struct ism_client {
62 	const char *name;
63 	void (*add)(struct ism_dev *dev);
64 	void (*remove)(struct ism_dev *dev);
65 	void (*handle_event)(struct ism_dev *dev, struct ism_event *event);
66 	/* Parameter dmbemask contains a bit vector with updated DMBEs, if sent
67 	 * via ism_move_data(). Callback function must handle all active bits
68 	 * indicated by dmbemask.
69 	 */
70 	void (*handle_irq)(struct ism_dev *dev, unsigned int bit, u16 dmbemask);
71 	/* Private area - don't touch! */
72 	struct work_struct remove_work;
73 	struct work_struct add_work;
74 	struct ism_dev *tgt_ism;
75 	u8 id;
76 };
77 
78 int ism_register_client(struct ism_client *client);
79 int  ism_unregister_client(struct ism_client *client);
80 static inline void *ism_get_priv(struct ism_dev *dev,
81 				 struct ism_client *client) {
82 	return dev->priv[client->id];
83 }
84 
85 static inline void ism_set_priv(struct ism_dev *dev, struct ism_client *client,
86 				void *priv) {
87 	dev->priv[client->id] = priv;
88 }
89 
90 #endif	/* _ISM_H */
91