Linux Audio

Check our new training course

Loading...
v3.1
 
  1#ifndef _SPARC64_VIO_H
  2#define _SPARC64_VIO_H
  3
  4#include <linux/kernel.h>
  5#include <linux/device.h>
  6#include <linux/mod_devicetable.h>
  7#include <linux/timer.h>
  8#include <linux/spinlock.h>
  9#include <linux/completion.h>
 10#include <linux/list.h>
 11#include <linux/log2.h>
 12
 13#include <asm/ldc.h>
 14#include <asm/mdesc.h>
 15
 16struct vio_msg_tag {
 17	u8			type;
 18#define VIO_TYPE_CTRL		0x01
 19#define VIO_TYPE_DATA		0x02
 20#define VIO_TYPE_ERR		0x04
 21
 22	u8			stype;
 23#define VIO_SUBTYPE_INFO	0x01
 24#define VIO_SUBTYPE_ACK		0x02
 25#define VIO_SUBTYPE_NACK	0x04
 26
 27	u16			stype_env;
 28#define VIO_VER_INFO		0x0001
 29#define VIO_ATTR_INFO		0x0002
 30#define VIO_DRING_REG		0x0003
 31#define VIO_DRING_UNREG		0x0004
 32#define VIO_RDX			0x0005
 33#define VIO_PKT_DATA		0x0040
 34#define VIO_DESC_DATA		0x0041
 35#define VIO_DRING_DATA		0x0042
 36#define VNET_MCAST_INFO		0x0101
 37
 38	u32		sid;
 39};
 40
 41struct vio_rdx {
 42	struct vio_msg_tag	tag;
 43	u64			resv[6];
 44};
 45
 46struct vio_ver_info {
 47	struct vio_msg_tag	tag;
 48	u16			major;
 49	u16			minor;
 50	u8			dev_class;
 51#define VDEV_NETWORK		0x01
 52#define VDEV_NETWORK_SWITCH	0x02
 53#define VDEV_DISK		0x03
 54#define VDEV_DISK_SERVER	0x04
 
 55
 56	u8			resv1[3];
 57	u64			resv2[5];
 58};
 59
 60struct vio_dring_register {
 61	struct vio_msg_tag	tag;
 62	u64			dring_ident;
 63	u32			num_descr;
 64	u32			descr_size;
 65	u16			options;
 66#define VIO_TX_DRING		0x0001
 67#define VIO_RX_DRING		0x0002
 
 68	u16			resv;
 69	u32			num_cookies;
 70	struct ldc_trans_cookie	cookies[0];
 71};
 72
 73struct vio_dring_unregister {
 74	struct vio_msg_tag	tag;
 75	u64			dring_ident;
 76	u64			resv[5];
 77};
 78
 79/* Data transfer modes */
 80#define VIO_PKT_MODE		0x01 /* Packet based transfer	*/
 81#define VIO_DESC_MODE		0x02 /* In-band descriptors	*/
 82#define VIO_DRING_MODE		0x03 /* Descriptor rings	*/
 
 
 83
 84struct vio_dring_data {
 85	struct vio_msg_tag	tag;
 86	u64			seq;
 87	u64			dring_ident;
 88	u32			start_idx;
 89	u32			end_idx;
 90	u8			state;
 91#define VIO_DRING_ACTIVE	0x01
 92#define VIO_DRING_STOPPED	0x02
 93
 94	u8			__pad1;
 95	u16			__pad2;
 96	u32			__pad3;
 97	u64			__par4[2];
 98};
 99
100struct vio_dring_hdr {
101	u8			state;
102#define VIO_DESC_FREE		0x01
103#define VIO_DESC_READY		0x02
104#define VIO_DESC_ACCEPTED	0x03
105#define VIO_DESC_DONE		0x04
106	u8			ack;
107#define VIO_ACK_ENABLE		0x01
108#define VIO_ACK_DISABLE		0x00
109
110	u16			__pad1;
111	u32			__pad2;
112};
113
114/* VIO disk specific structures and defines */
115struct vio_disk_attr_info {
116	struct vio_msg_tag	tag;
117	u8			xfer_mode;
118	u8			vdisk_type;
119#define VD_DISK_TYPE_SLICE	0x01 /* Slice in block device	*/
120#define VD_DISK_TYPE_DISK	0x02 /* Entire block device	*/
121	u16			resv1;
 
 
 
 
122	u32			vdisk_block_size;
123	u64			operations;
124	u64			vdisk_size;
125	u64			max_xfer_size;
126	u64			resv2[2];
 
 
127};
128
129struct vio_disk_desc {
130	struct vio_dring_hdr	hdr;
131	u64			req_id;
132	u8			operation;
133#define VD_OP_BREAD		0x01 /* Block read			*/
134#define VD_OP_BWRITE		0x02 /* Block write			*/
135#define VD_OP_FLUSH		0x03 /* Flush disk contents		*/
136#define VD_OP_GET_WCE		0x04 /* Get write-cache status		*/
137#define VD_OP_SET_WCE		0x05 /* Enable/disable write-cache	*/
138#define VD_OP_GET_VTOC		0x06 /* Get VTOC			*/
139#define VD_OP_SET_VTOC		0x07 /* Set VTOC			*/
140#define VD_OP_GET_DISKGEOM	0x08 /* Get disk geometry		*/
141#define VD_OP_SET_DISKGEOM	0x09 /* Set disk geometry		*/
142#define VD_OP_SCSICMD		0x0a /* SCSI control command		*/
143#define VD_OP_GET_DEVID		0x0b /* Get device ID			*/
144#define VD_OP_GET_EFI		0x0c /* Get EFI				*/
145#define VD_OP_SET_EFI		0x0d /* Set EFI				*/
146	u8			slice;
147	u16			resv1;
148	u32			status;
149	u64			offset;
150	u64			size;
151	u32			ncookies;
152	u32			resv2;
153	struct ldc_trans_cookie	cookies[0];
154};
155
156#define VIO_DISK_VNAME_LEN	8
157#define VIO_DISK_ALABEL_LEN	128
158#define VIO_DISK_NUM_PART	8
159
160struct vio_disk_vtoc {
161	u8			volume_name[VIO_DISK_VNAME_LEN];
162	u16			sector_size;
163	u16			num_partitions;
164	u8			ascii_label[VIO_DISK_ALABEL_LEN];
165	struct {
166		u16		id;
167		u16		perm_flags;
168		u32		resv;
169		u64		start_block;
170		u64		num_blocks;
171	} partitions[VIO_DISK_NUM_PART];
172};
173
174struct vio_disk_geom {
175	u16			num_cyl; /* Num data cylinders		*/
176	u16			alt_cyl; /* Num alternate cylinders	*/
177	u16			beg_cyl; /* Cyl off of fixed head area	*/
178	u16			num_hd;  /* Num heads			*/
179	u16			num_sec; /* Num sectors			*/
180	u16			ifact;   /* Interleave factor		*/
181	u16			apc;     /* Alts per cylinder (SCSI)	*/
182	u16			rpm;	 /* Revolutions per minute	*/
183	u16			phy_cyl; /* Num physical cylinders	*/
184	u16			wr_skip; /* Num sects to skip, writes	*/
185	u16			rd_skip; /* Num sects to skip, writes	*/
186};
187
188struct vio_disk_devid {
189	u16			resv;
190	u16			type;
191	u32			len;
192	char			id[0];
193};
194
195struct vio_disk_efi {
196	u64			lba;
197	u64			len;
198	char			data[0];
199};
200
201/* VIO net specific structures and defines */
202struct vio_net_attr_info {
203	struct vio_msg_tag	tag;
204	u8			xfer_mode;
205	u8			addr_type;
206#define VNET_ADDR_ETHERMAC	0x01
207	u16			ack_freq;
208	u32			resv1;
 
 
 
 
 
 
209	u64			addr;
210	u64			mtu;
211	u64			resv2[3];
 
 
 
 
212};
213
214#define VNET_NUM_MCAST		7
215
216struct vio_net_mcast_info {
217	struct vio_msg_tag	tag;
218	u8			set;
219	u8			count;
220	u8			mcast_addr[VNET_NUM_MCAST * 6];
221	u32			resv;
222};
223
224struct vio_net_desc {
225	struct vio_dring_hdr	hdr;
226	u32			size;
227	u32			ncookies;
228	struct ldc_trans_cookie	cookies[0];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
229};
230
 
 
 
 
 
231#define VIO_MAX_RING_COOKIES	24
232
233struct vio_dring_state {
234	u64			ident;
235	void			*base;
236	u64			snd_nxt;
237	u64			rcv_nxt;
238	u32			entry_size;
239	u32			num_entries;
240	u32			prod;
241	u32			cons;
242	u32			pending;
243	int			ncookies;
244	struct ldc_trans_cookie	cookies[VIO_MAX_RING_COOKIES];
245};
246
 
 
 
 
 
 
 
 
247static inline void *vio_dring_cur(struct vio_dring_state *dr)
248{
249	return dr->base + (dr->entry_size * dr->prod);
250}
251
252static inline void *vio_dring_entry(struct vio_dring_state *dr,
253				    unsigned int index)
254{
255	return dr->base + (dr->entry_size * index);
256}
257
258static inline u32 vio_dring_avail(struct vio_dring_state *dr,
259				  unsigned int ring_size)
260{
261	return (dr->pending -
262		((dr->prod - dr->cons) & (ring_size - 1)));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
263}
264
265#define VIO_MAX_TYPE_LEN	32
 
266#define VIO_MAX_COMPAT_LEN	64
267
268struct vio_dev {
269	u64			mp;
270	struct device_node	*dp;
271
 
272	char			type[VIO_MAX_TYPE_LEN];
273	char			compat[VIO_MAX_COMPAT_LEN];
274	int			compat_len;
275
276	u64			dev_no;
277
 
278	unsigned long		channel_id;
279
280	unsigned int		tx_irq;
281	unsigned int		rx_irq;
 
 
 
 
 
 
 
 
282
283	struct device		dev;
284};
285
286struct vio_driver {
 
287	struct list_head		node;
288	const struct vio_device_id	*id_table;
289	int (*probe)(struct vio_dev *dev, const struct vio_device_id *id);
290	int (*remove)(struct vio_dev *dev);
291	void (*shutdown)(struct vio_dev *dev);
292	unsigned long			driver_data;
293	struct device_driver		driver;
 
294};
295
296struct vio_version {
297	u16		major;
298	u16		minor;
299};
300
301struct vio_driver_state;
302struct vio_driver_ops {
303	int	(*send_attr)(struct vio_driver_state *vio);
304	int	(*handle_attr)(struct vio_driver_state *vio, void *pkt);
305	void	(*handshake_complete)(struct vio_driver_state *vio);
306};
307
308struct vio_completion {
309	struct completion	com;
310	int			err;
311	int			waiting_for;
312};
313
314struct vio_driver_state {
315	/* Protects VIO handshake and, optionally, driver private state.  */
316	spinlock_t		lock;
317
318	struct ldc_channel	*lp;
319
320	u32			_peer_sid;
321	u32			_local_sid;
322	struct vio_dring_state	drings[2];
323#define VIO_DRIVER_TX_RING	0
324#define VIO_DRIVER_RX_RING	1
325
326	u8			hs_state;
327#define VIO_HS_INVALID		0x00
328#define VIO_HS_GOTVERS		0x01
329#define VIO_HS_GOT_ATTR		0x04
330#define VIO_HS_SENT_DREG	0x08
331#define VIO_HS_SENT_RDX		0x10
332#define VIO_HS_GOT_RDX_ACK	0x20
333#define VIO_HS_GOT_RDX		0x40
334#define VIO_HS_SENT_RDX_ACK	0x80
335#define VIO_HS_COMPLETE		(VIO_HS_GOT_RDX_ACK | VIO_HS_SENT_RDX_ACK)
336
337	u8			dev_class;
338
339	u8			dr_state;
340#define VIO_DR_STATE_TXREG	0x01
341#define VIO_DR_STATE_RXREG	0x02
342#define VIO_DR_STATE_TXREQ	0x10
343#define VIO_DR_STATE_RXREQ	0x20
344
345	u8			debug;
346#define VIO_DEBUG_HS		0x01
347#define VIO_DEBUG_DATA		0x02
348
349	void			*desc_buf;
350	unsigned int		desc_buf_len;
351
352	struct vio_completion	*cmp;
353
354	struct vio_dev		*vdev;
355
356	struct timer_list	timer;
357
358	struct vio_version	ver;
359
360	struct vio_version	*ver_table;
361	int			ver_table_entries;
362
363	char			*name;
364
365	struct vio_driver_ops	*ops;
366};
367
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
368#define viodbg(TYPE, f, a...) \
369do {	if (vio->debug & VIO_DEBUG_##TYPE) \
370		printk(KERN_INFO "vio: ID[%lu] " f, \
371		       vio->vdev->channel_id, ## a); \
372} while (0)
373
374extern int vio_register_driver(struct vio_driver *drv);
375extern void vio_unregister_driver(struct vio_driver *drv);
 
 
 
 
 
 
376
377static inline struct vio_driver *to_vio_driver(struct device_driver *drv)
378{
379	return container_of(drv, struct vio_driver, driver);
380}
381
382static inline struct vio_dev *to_vio_dev(struct device *dev)
383{
384	return container_of(dev, struct vio_dev, dev);
385}
386
387extern int vio_ldc_send(struct vio_driver_state *vio, void *data, int len);
388extern void vio_link_state_change(struct vio_driver_state *vio, int event);
389extern void vio_conn_reset(struct vio_driver_state *vio);
390extern int vio_control_pkt_engine(struct vio_driver_state *vio, void *pkt);
391extern int vio_validate_sid(struct vio_driver_state *vio,
392			    struct vio_msg_tag *tp);
393extern u32 vio_send_sid(struct vio_driver_state *vio);
394extern int vio_ldc_alloc(struct vio_driver_state *vio,
395			 struct ldc_channel_config *base_cfg, void *event_arg);
396extern void vio_ldc_free(struct vio_driver_state *vio);
397extern int vio_driver_init(struct vio_driver_state *vio, struct vio_dev *vdev,
398			   u8 dev_class, struct vio_version *ver_table,
399			   int ver_table_size, struct vio_driver_ops *ops,
400			   char *name);
401
402extern void vio_port_up(struct vio_driver_state *vio);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
403
404#endif /* _SPARC64_VIO_H */
v6.8
  1/* SPDX-License-Identifier: GPL-2.0 */
  2#ifndef _SPARC64_VIO_H
  3#define _SPARC64_VIO_H
  4
  5#include <linux/kernel.h>
  6#include <linux/device.h>
  7#include <linux/mod_devicetable.h>
  8#include <linux/timer.h>
  9#include <linux/spinlock.h>
 10#include <linux/completion.h>
 11#include <linux/list.h>
 12#include <linux/log2.h>
 13
 14#include <asm/ldc.h>
 15#include <asm/mdesc.h>
 16
 17struct vio_msg_tag {
 18	u8			type;
 19#define VIO_TYPE_CTRL		0x01
 20#define VIO_TYPE_DATA		0x02
 21#define VIO_TYPE_ERR		0x04
 22
 23	u8			stype;
 24#define VIO_SUBTYPE_INFO	0x01
 25#define VIO_SUBTYPE_ACK		0x02
 26#define VIO_SUBTYPE_NACK	0x04
 27
 28	u16			stype_env;
 29#define VIO_VER_INFO		0x0001
 30#define VIO_ATTR_INFO		0x0002
 31#define VIO_DRING_REG		0x0003
 32#define VIO_DRING_UNREG		0x0004
 33#define VIO_RDX			0x0005
 34#define VIO_PKT_DATA		0x0040
 35#define VIO_DESC_DATA		0x0041
 36#define VIO_DRING_DATA		0x0042
 37#define VNET_MCAST_INFO		0x0101
 38
 39	u32		sid;
 40};
 41
 42struct vio_rdx {
 43	struct vio_msg_tag	tag;
 44	u64			resv[6];
 45};
 46
 47struct vio_ver_info {
 48	struct vio_msg_tag	tag;
 49	u16			major;
 50	u16			minor;
 51	u8			dev_class;
 52#define VDEV_NETWORK		0x01
 53#define VDEV_NETWORK_SWITCH	0x02
 54#define VDEV_DISK		0x03
 55#define VDEV_DISK_SERVER	0x04
 56#define VDEV_CONSOLE_CON	0x05
 57
 58	u8			resv1[3];
 59	u64			resv2[5];
 60};
 61
 62struct vio_dring_register {
 63	struct vio_msg_tag	tag;
 64	u64			dring_ident;
 65	u32			num_descr;
 66	u32			descr_size;
 67	u16			options;
 68#define VIO_TX_DRING		0x0001
 69#define VIO_RX_DRING		0x0002
 70#define VIO_RX_DRING_DATA	0x0004
 71	u16			resv;
 72	u32			num_cookies;
 73	struct ldc_trans_cookie	cookies[];
 74};
 75
 76struct vio_dring_unregister {
 77	struct vio_msg_tag	tag;
 78	u64			dring_ident;
 79	u64			resv[5];
 80};
 81
 82/* Data transfer modes */
 83#define VIO_PKT_MODE		0x01 /* Packet based transfer	*/
 84#define VIO_DESC_MODE		0x02 /* In-band descriptors	*/
 85#define VIO_DRING_MODE		0x03 /* Descriptor rings	*/
 86/* in vers >= 1.2, VIO_DRING_MODE is 0x04 and transfer mode is a bitmask */
 87#define VIO_NEW_DRING_MODE	0x04
 88
 89struct vio_dring_data {
 90	struct vio_msg_tag	tag;
 91	u64			seq;
 92	u64			dring_ident;
 93	u32			start_idx;
 94	u32			end_idx;
 95	u8			state;
 96#define VIO_DRING_ACTIVE	0x01
 97#define VIO_DRING_STOPPED	0x02
 98
 99	u8			__pad1;
100	u16			__pad2;
101	u32			__pad3;
102	u64			__par4[2];
103};
104
105struct vio_dring_hdr {
106	u8			state;
107#define VIO_DESC_FREE		0x01
108#define VIO_DESC_READY		0x02
109#define VIO_DESC_ACCEPTED	0x03
110#define VIO_DESC_DONE		0x04
111	u8			ack;
112#define VIO_ACK_ENABLE		0x01
113#define VIO_ACK_DISABLE		0x00
114
115	u16			__pad1;
116	u32			__pad2;
117};
118
119/* VIO disk specific structures and defines */
120struct vio_disk_attr_info {
121	struct vio_msg_tag	tag;
122	u8			xfer_mode;
123	u8			vdisk_type;
124#define VD_DISK_TYPE_SLICE	0x01 /* Slice in block device	*/
125#define VD_DISK_TYPE_DISK	0x02 /* Entire block device	*/
126	u8			vdisk_mtype;		/* v1.1 */
127#define VD_MEDIA_TYPE_FIXED	0x01 /* Fixed device */
128#define VD_MEDIA_TYPE_CD	0x02 /* CD Device    */
129#define VD_MEDIA_TYPE_DVD	0x03 /* DVD Device   */
130	u8			resv1;
131	u32			vdisk_block_size;
132	u64			operations;
133	u64			vdisk_size;		/* v1.1 */
134	u64			max_xfer_size;
135	u32			phys_block_size;	/* v1.2 */
136	u32			resv2;
137	u64			resv3[1];
138};
139
140struct vio_disk_desc {
141	struct vio_dring_hdr	hdr;
142	u64			req_id;
143	u8			operation;
144#define VD_OP_BREAD		0x01 /* Block read			*/
145#define VD_OP_BWRITE		0x02 /* Block write			*/
146#define VD_OP_FLUSH		0x03 /* Flush disk contents		*/
147#define VD_OP_GET_WCE		0x04 /* Get write-cache status		*/
148#define VD_OP_SET_WCE		0x05 /* Enable/disable write-cache	*/
149#define VD_OP_GET_VTOC		0x06 /* Get VTOC			*/
150#define VD_OP_SET_VTOC		0x07 /* Set VTOC			*/
151#define VD_OP_GET_DISKGEOM	0x08 /* Get disk geometry		*/
152#define VD_OP_SET_DISKGEOM	0x09 /* Set disk geometry		*/
153#define VD_OP_SCSICMD		0x0a /* SCSI control command		*/
154#define VD_OP_GET_DEVID		0x0b /* Get device ID			*/
155#define VD_OP_GET_EFI		0x0c /* Get EFI				*/
156#define VD_OP_SET_EFI		0x0d /* Set EFI				*/
157	u8			slice;
158	u16			resv1;
159	u32			status;
160	u64			offset;
161	u64			size;
162	u32			ncookies;
163	u32			resv2;
164	struct ldc_trans_cookie	cookies[];
165};
166
167#define VIO_DISK_VNAME_LEN	8
168#define VIO_DISK_ALABEL_LEN	128
169#define VIO_DISK_NUM_PART	8
170
171struct vio_disk_vtoc {
172	u8			volume_name[VIO_DISK_VNAME_LEN];
173	u16			sector_size;
174	u16			num_partitions;
175	u8			ascii_label[VIO_DISK_ALABEL_LEN];
176	struct {
177		u16		id;
178		u16		perm_flags;
179		u32		resv;
180		u64		start_block;
181		u64		num_blocks;
182	} partitions[VIO_DISK_NUM_PART];
183};
184
185struct vio_disk_geom {
186	u16			num_cyl; /* Num data cylinders		*/
187	u16			alt_cyl; /* Num alternate cylinders	*/
188	u16			beg_cyl; /* Cyl off of fixed head area	*/
189	u16			num_hd;  /* Num heads			*/
190	u16			num_sec; /* Num sectors			*/
191	u16			ifact;   /* Interleave factor		*/
192	u16			apc;     /* Alts per cylinder (SCSI)	*/
193	u16			rpm;	 /* Revolutions per minute	*/
194	u16			phy_cyl; /* Num physical cylinders	*/
195	u16			wr_skip; /* Num sects to skip, writes	*/
196	u16			rd_skip; /* Num sects to skip, writes	*/
197};
198
199struct vio_disk_devid {
200	u16			resv;
201	u16			type;
202	u32			len;
203	char			id[];
204};
205
206struct vio_disk_efi {
207	u64			lba;
208	u64			len;
209	char			data[];
210};
211
212/* VIO net specific structures and defines */
213struct vio_net_attr_info {
214	struct vio_msg_tag	tag;
215	u8			xfer_mode;
216	u8			addr_type;
217#define VNET_ADDR_ETHERMAC	0x01
218	u16			ack_freq;
219	u8			plnk_updt;
220#define PHYSLINK_UPDATE_NONE		0x00
221#define PHYSLINK_UPDATE_STATE		0x01
222#define PHYSLINK_UPDATE_STATE_ACK	0x02
223#define PHYSLINK_UPDATE_STATE_NACK	0x03
224	u8			options;
225	u16			resv1;
226	u64			addr;
227	u64			mtu;
228	u16			cflags;
229#define VNET_LSO_IPV4_CAPAB		0x0001
230	u16			ipv4_lso_maxlen;
231	u32			resv2;
232	u64			resv3[2];
233};
234
235#define VNET_NUM_MCAST		7
236
237struct vio_net_mcast_info {
238	struct vio_msg_tag	tag;
239	u8			set;
240	u8			count;
241	u8			mcast_addr[VNET_NUM_MCAST * 6];
242	u32			resv;
243};
244
245struct vio_net_desc {
246	struct vio_dring_hdr	hdr;
247	u32			size;
248	u32			ncookies;
249	struct ldc_trans_cookie	cookies[];
250};
251
252struct vio_net_dext {
253	u8		flags;
254#define VNET_PKT_HASH			0x01
255#define	VNET_PKT_HCK_IPV4_HDRCKSUM	0x02
256#define	VNET_PKT_HCK_FULLCKSUM		0x04
257#define	VNET_PKT_IPV4_LSO		0x08
258#define	VNET_PKT_HCK_IPV4_HDRCKSUM_OK	0x10
259#define	VNET_PKT_HCK_FULLCKSUM_OK	0x20
260
261	u8		vnet_hashval;
262	u16		ipv4_lso_mss;
263	u32		resv3;
264};
265
266static inline struct vio_net_dext *vio_net_ext(struct vio_net_desc *desc)
267{
268	return (struct vio_net_dext *)&desc->cookies[2];
269}
270
271#define VIO_MAX_RING_COOKIES	24
272
273struct vio_dring_state {
274	u64			ident;
275	void			*base;
276	u64			snd_nxt;
277	u64			rcv_nxt;
278	u32			entry_size;
279	u32			num_entries;
280	u32			prod;
281	u32			cons;
282	u32			pending;
283	int			ncookies;
284	struct ldc_trans_cookie	cookies[VIO_MAX_RING_COOKIES];
285};
286
287#define VIO_TAG_SIZE		(sizeof(struct vio_msg_tag))
288#define VIO_VCC_MTU_SIZE	(LDC_PACKET_SIZE - VIO_TAG_SIZE)
289
290struct vio_vcc {
291	struct vio_msg_tag	tag;
292	char			data[VIO_VCC_MTU_SIZE];
293};
294
295static inline void *vio_dring_cur(struct vio_dring_state *dr)
296{
297	return dr->base + (dr->entry_size * dr->prod);
298}
299
300static inline void *vio_dring_entry(struct vio_dring_state *dr,
301				    unsigned int index)
302{
303	return dr->base + (dr->entry_size * index);
304}
305
306static inline u32 vio_dring_avail(struct vio_dring_state *dr,
307				  unsigned int ring_size)
308{
309	return (dr->pending -
310		((dr->prod - dr->cons) & (ring_size - 1)) - 1);
311}
312
313static inline u32 vio_dring_next(struct vio_dring_state *dr, u32 index)
314{
315	if (++index == dr->num_entries)
316		index = 0;
317	return index;
318}
319
320static inline u32 vio_dring_prev(struct vio_dring_state *dr, u32 index)
321{
322	if (index == 0)
323		return dr->num_entries - 1;
324	else
325		return index - 1;
326}
327
328#define VIO_MAX_TYPE_LEN	32
329#define VIO_MAX_NAME_LEN	32
330#define VIO_MAX_COMPAT_LEN	64
331
332struct vio_dev {
333	u64			mp;
334	struct device_node	*dp;
335
336	char			node_name[VIO_MAX_NAME_LEN];
337	char			type[VIO_MAX_TYPE_LEN];
338	char			compat[VIO_MAX_COMPAT_LEN];
339	int			compat_len;
340
341	u64			dev_no;
342
343	unsigned long		port_id;
344	unsigned long		channel_id;
345
346	unsigned int		tx_irq;
347	unsigned int		rx_irq;
348	u64			rx_ino;
349	u64			tx_ino;
350
351	/* Handle to the root of "channel-devices" sub-tree in MDESC */
352	u64			cdev_handle;
353
354	/* MD specific data used to identify the vdev in MD */
355	union md_node_info	md_node_info;
356
357	struct device		dev;
358};
359
360struct vio_driver {
361	const char			*name;
362	struct list_head		node;
363	const struct vio_device_id	*id_table;
364	int (*probe)(struct vio_dev *dev, const struct vio_device_id *id);
365	void (*remove)(struct vio_dev *dev);
366	void (*shutdown)(struct vio_dev *dev);
367	unsigned long			driver_data;
368	struct device_driver		driver;
369	bool				no_irq;
370};
371
372struct vio_version {
373	u16		major;
374	u16		minor;
375};
376
377struct vio_driver_state;
378struct vio_driver_ops {
379	int	(*send_attr)(struct vio_driver_state *vio);
380	int	(*handle_attr)(struct vio_driver_state *vio, void *pkt);
381	void	(*handshake_complete)(struct vio_driver_state *vio);
382};
383
384struct vio_completion {
385	struct completion	com;
386	int			err;
387	int			waiting_for;
388};
389
390struct vio_driver_state {
391	/* Protects VIO handshake and, optionally, driver private state.  */
392	spinlock_t		lock;
393
394	struct ldc_channel	*lp;
395
396	u32			_peer_sid;
397	u32			_local_sid;
398	struct vio_dring_state	drings[2];
399#define VIO_DRIVER_TX_RING	0
400#define VIO_DRIVER_RX_RING	1
401
402	u8			hs_state;
403#define VIO_HS_INVALID		0x00
404#define VIO_HS_GOTVERS		0x01
405#define VIO_HS_GOT_ATTR		0x04
406#define VIO_HS_SENT_DREG	0x08
407#define VIO_HS_SENT_RDX		0x10
408#define VIO_HS_GOT_RDX_ACK	0x20
409#define VIO_HS_GOT_RDX		0x40
410#define VIO_HS_SENT_RDX_ACK	0x80
411#define VIO_HS_COMPLETE		(VIO_HS_GOT_RDX_ACK | VIO_HS_SENT_RDX_ACK)
412
413	u8			dev_class;
414
415	u8			dr_state;
416#define VIO_DR_STATE_TXREG	0x01
417#define VIO_DR_STATE_RXREG	0x02
418#define VIO_DR_STATE_TXREQ	0x10
419#define VIO_DR_STATE_RXREQ	0x20
420
421	u8			debug;
422#define VIO_DEBUG_HS		0x01
423#define VIO_DEBUG_DATA		0x02
424
425	void			*desc_buf;
426	unsigned int		desc_buf_len;
427
428	struct vio_completion	*cmp;
429
430	struct vio_dev		*vdev;
431
432	struct timer_list	timer;
433
434	struct vio_version	ver;
435
436	struct vio_version	*ver_table;
437	int			ver_table_entries;
438
439	char			*name;
440
441	struct vio_driver_ops	*ops;
442};
443
444static inline bool vio_version_before(struct vio_driver_state *vio,
445				      u16 major, u16 minor)
446{
447	u32 have = (u32)vio->ver.major << 16 | vio->ver.minor;
448	u32 want = (u32)major << 16 | minor;
449
450	return have < want;
451}
452
453static inline bool vio_version_after(struct vio_driver_state *vio,
454				      u16 major, u16 minor)
455{
456	u32 have = (u32)vio->ver.major << 16 | vio->ver.minor;
457	u32 want = (u32)major << 16 | minor;
458
459	return have > want;
460}
461
462static inline bool vio_version_after_eq(struct vio_driver_state *vio,
463					u16 major, u16 minor)
464{
465	u32 have = (u32)vio->ver.major << 16 | vio->ver.minor;
466	u32 want = (u32)major << 16 | minor;
467
468	return have >= want;
469}
470
471#define viodbg(TYPE, f, a...) \
472do {	if (vio->debug & VIO_DEBUG_##TYPE) \
473		printk(KERN_INFO "vio: ID[%lu] " f, \
474		       vio->vdev->channel_id, ## a); \
475} while (0)
476
477int __vio_register_driver(struct vio_driver *drv, struct module *owner,
478				 const char *mod_name);
479/*
480 * vio_register_driver must be a macro so that KBUILD_MODNAME can be expanded
481 */
482#define vio_register_driver(driver)		\
483	__vio_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
484void vio_unregister_driver(struct vio_driver *drv);
485
486static inline struct vio_driver *to_vio_driver(struct device_driver *drv)
487{
488	return container_of(drv, struct vio_driver, driver);
489}
490
491#define to_vio_dev(__dev)	container_of_const(__dev, struct vio_dev, dev)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
492
493int vio_ldc_send(struct vio_driver_state *vio, void *data, int len);
494void vio_link_state_change(struct vio_driver_state *vio, int event);
495void vio_conn_reset(struct vio_driver_state *vio);
496int vio_control_pkt_engine(struct vio_driver_state *vio, void *pkt);
497int vio_validate_sid(struct vio_driver_state *vio,
498		     struct vio_msg_tag *tp);
499u32 vio_send_sid(struct vio_driver_state *vio);
500int vio_ldc_alloc(struct vio_driver_state *vio,
501		  struct ldc_channel_config *base_cfg, void *event_arg);
502void vio_ldc_free(struct vio_driver_state *vio);
503int vio_driver_init(struct vio_driver_state *vio, struct vio_dev *vdev,
504		    u8 dev_class, struct vio_version *ver_table,
505		    int ver_table_size, struct vio_driver_ops *ops,
506		    char *name);
507
508void vio_port_up(struct vio_driver_state *vio);
509int vio_set_intr(unsigned long dev_ino, int state);
510u64 vio_vdev_node(struct mdesc_handle *hp, struct vio_dev *vdev);
511
512#endif /* _SPARC64_VIO_H */