blob: 6b135a8ab07bfdca9d8c2aa066d104a92bbb68e6 [file] [log] [blame]
Sam Ravnborga00736e2008-06-19 20:26:19 +02001#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
David L Stevens163a4e72014-09-29 19:47:59 -040068#define VIO_RX_DRING_DATA 0x0004
Sam Ravnborga00736e2008-06-19 20:26:19 +020069 u16 resv;
70 u32 num_cookies;
71 struct ldc_trans_cookie cookies[0];
72};
73
74struct vio_dring_unregister {
75 struct vio_msg_tag tag;
76 u64 dring_ident;
77 u64 resv[5];
78};
79
80/* Data transfer modes */
81#define VIO_PKT_MODE 0x01 /* Packet based transfer */
82#define VIO_DESC_MODE 0x02 /* In-band descriptors */
83#define VIO_DRING_MODE 0x03 /* Descriptor rings */
David L Stevens163a4e72014-09-29 19:47:59 -040084/* in vers >= 1.2, VIO_DRING_MODE is 0x04 and transfer mode is a bitmask */
85#define VIO_NEW_DRING_MODE 0x04
Sam Ravnborga00736e2008-06-19 20:26:19 +020086
87struct vio_dring_data {
88 struct vio_msg_tag tag;
89 u64 seq;
90 u64 dring_ident;
91 u32 start_idx;
92 u32 end_idx;
93 u8 state;
94#define VIO_DRING_ACTIVE 0x01
95#define VIO_DRING_STOPPED 0x02
96
97 u8 __pad1;
98 u16 __pad2;
99 u32 __pad3;
100 u64 __par4[2];
101};
102
103struct vio_dring_hdr {
104 u8 state;
105#define VIO_DESC_FREE 0x01
106#define VIO_DESC_READY 0x02
107#define VIO_DESC_ACCEPTED 0x03
108#define VIO_DESC_DONE 0x04
109 u8 ack;
110#define VIO_ACK_ENABLE 0x01
111#define VIO_ACK_DISABLE 0x00
112
113 u16 __pad1;
114 u32 __pad2;
115};
116
117/* VIO disk specific structures and defines */
118struct vio_disk_attr_info {
119 struct vio_msg_tag tag;
120 u8 xfer_mode;
121 u8 vdisk_type;
122#define VD_DISK_TYPE_SLICE 0x01 /* Slice in block device */
123#define VD_DISK_TYPE_DISK 0x02 /* Entire block device */
124 u16 resv1;
125 u32 vdisk_block_size;
126 u64 operations;
127 u64 vdisk_size;
128 u64 max_xfer_size;
129 u64 resv2[2];
130};
131
132struct vio_disk_desc {
133 struct vio_dring_hdr hdr;
134 u64 req_id;
135 u8 operation;
136#define VD_OP_BREAD 0x01 /* Block read */
137#define VD_OP_BWRITE 0x02 /* Block write */
138#define VD_OP_FLUSH 0x03 /* Flush disk contents */
139#define VD_OP_GET_WCE 0x04 /* Get write-cache status */
140#define VD_OP_SET_WCE 0x05 /* Enable/disable write-cache */
141#define VD_OP_GET_VTOC 0x06 /* Get VTOC */
142#define VD_OP_SET_VTOC 0x07 /* Set VTOC */
143#define VD_OP_GET_DISKGEOM 0x08 /* Get disk geometry */
144#define VD_OP_SET_DISKGEOM 0x09 /* Set disk geometry */
145#define VD_OP_SCSICMD 0x0a /* SCSI control command */
146#define VD_OP_GET_DEVID 0x0b /* Get device ID */
147#define VD_OP_GET_EFI 0x0c /* Get EFI */
148#define VD_OP_SET_EFI 0x0d /* Set EFI */
149 u8 slice;
150 u16 resv1;
151 u32 status;
152 u64 offset;
153 u64 size;
154 u32 ncookies;
155 u32 resv2;
156 struct ldc_trans_cookie cookies[0];
157};
158
159#define VIO_DISK_VNAME_LEN 8
160#define VIO_DISK_ALABEL_LEN 128
161#define VIO_DISK_NUM_PART 8
162
163struct vio_disk_vtoc {
164 u8 volume_name[VIO_DISK_VNAME_LEN];
165 u16 sector_size;
166 u16 num_partitions;
167 u8 ascii_label[VIO_DISK_ALABEL_LEN];
168 struct {
169 u16 id;
170 u16 perm_flags;
171 u32 resv;
172 u64 start_block;
173 u64 num_blocks;
174 } partitions[VIO_DISK_NUM_PART];
175};
176
177struct vio_disk_geom {
178 u16 num_cyl; /* Num data cylinders */
179 u16 alt_cyl; /* Num alternate cylinders */
180 u16 beg_cyl; /* Cyl off of fixed head area */
181 u16 num_hd; /* Num heads */
182 u16 num_sec; /* Num sectors */
183 u16 ifact; /* Interleave factor */
184 u16 apc; /* Alts per cylinder (SCSI) */
185 u16 rpm; /* Revolutions per minute */
186 u16 phy_cyl; /* Num physical cylinders */
187 u16 wr_skip; /* Num sects to skip, writes */
188 u16 rd_skip; /* Num sects to skip, writes */
189};
190
191struct vio_disk_devid {
192 u16 resv;
193 u16 type;
194 u32 len;
195 char id[0];
196};
197
198struct vio_disk_efi {
199 u64 lba;
200 u64 len;
201 char data[0];
202};
203
204/* VIO net specific structures and defines */
205struct vio_net_attr_info {
206 struct vio_msg_tag tag;
207 u8 xfer_mode;
208 u8 addr_type;
209#define VNET_ADDR_ETHERMAC 0x01
210 u16 ack_freq;
David L Stevens163a4e72014-09-29 19:47:59 -0400211 u8 plnk_updt;
212#define PHYSLINK_UPDATE_NONE 0x00
213#define PHYSLINK_UPDATE_STATE 0x01
214#define PHYSLINK_UPDATE_STATE_ACK 0x02
215#define PHYSLINK_UPDATE_STATE_NACK 0x03
216 u8 options;
217 u16 resv1;
Sam Ravnborga00736e2008-06-19 20:26:19 +0200218 u64 addr;
219 u64 mtu;
David L Stevens163a4e72014-09-29 19:47:59 -0400220 u16 cflags;
221#define VNET_LSO_IPV4_CAPAB 0x0001
222 u16 ipv4_lso_maxlen;
223 u32 resv2;
224 u64 resv3[2];
Sam Ravnborga00736e2008-06-19 20:26:19 +0200225};
226
227#define VNET_NUM_MCAST 7
228
229struct vio_net_mcast_info {
230 struct vio_msg_tag tag;
231 u8 set;
232 u8 count;
233 u8 mcast_addr[VNET_NUM_MCAST * 6];
234 u32 resv;
235};
236
237struct vio_net_desc {
238 struct vio_dring_hdr hdr;
239 u32 size;
240 u32 ncookies;
241 struct ldc_trans_cookie cookies[0];
242};
243
244#define VIO_MAX_RING_COOKIES 24
245
246struct vio_dring_state {
247 u64 ident;
248 void *base;
249 u64 snd_nxt;
250 u64 rcv_nxt;
251 u32 entry_size;
252 u32 num_entries;
253 u32 prod;
254 u32 cons;
255 u32 pending;
256 int ncookies;
257 struct ldc_trans_cookie cookies[VIO_MAX_RING_COOKIES];
258};
259
260static inline void *vio_dring_cur(struct vio_dring_state *dr)
261{
262 return dr->base + (dr->entry_size * dr->prod);
263}
264
265static inline void *vio_dring_entry(struct vio_dring_state *dr,
266 unsigned int index)
267{
268 return dr->base + (dr->entry_size * index);
269}
270
271static inline u32 vio_dring_avail(struct vio_dring_state *dr,
272 unsigned int ring_size)
273{
Sam Ravnborga00736e2008-06-19 20:26:19 +0200274 return (dr->pending -
275 ((dr->prod - dr->cons) & (ring_size - 1)));
276}
277
278#define VIO_MAX_TYPE_LEN 32
279#define VIO_MAX_COMPAT_LEN 64
280
281struct vio_dev {
282 u64 mp;
283 struct device_node *dp;
284
285 char type[VIO_MAX_TYPE_LEN];
286 char compat[VIO_MAX_COMPAT_LEN];
287 int compat_len;
288
289 u64 dev_no;
290
291 unsigned long channel_id;
292
293 unsigned int tx_irq;
294 unsigned int rx_irq;
295
296 struct device dev;
297};
298
299struct vio_driver {
Benjamin Herrenschmidtcb52d892012-03-26 19:06:30 +0000300 const char *name;
Sam Ravnborga00736e2008-06-19 20:26:19 +0200301 struct list_head node;
302 const struct vio_device_id *id_table;
303 int (*probe)(struct vio_dev *dev, const struct vio_device_id *id);
304 int (*remove)(struct vio_dev *dev);
305 void (*shutdown)(struct vio_dev *dev);
306 unsigned long driver_data;
307 struct device_driver driver;
308};
309
310struct vio_version {
311 u16 major;
312 u16 minor;
313};
314
315struct vio_driver_state;
316struct vio_driver_ops {
317 int (*send_attr)(struct vio_driver_state *vio);
318 int (*handle_attr)(struct vio_driver_state *vio, void *pkt);
319 void (*handshake_complete)(struct vio_driver_state *vio);
320};
321
322struct vio_completion {
323 struct completion com;
324 int err;
325 int waiting_for;
326};
327
328struct vio_driver_state {
329 /* Protects VIO handshake and, optionally, driver private state. */
330 spinlock_t lock;
331
332 struct ldc_channel *lp;
333
334 u32 _peer_sid;
335 u32 _local_sid;
336 struct vio_dring_state drings[2];
337#define VIO_DRIVER_TX_RING 0
338#define VIO_DRIVER_RX_RING 1
339
340 u8 hs_state;
341#define VIO_HS_INVALID 0x00
342#define VIO_HS_GOTVERS 0x01
343#define VIO_HS_GOT_ATTR 0x04
344#define VIO_HS_SENT_DREG 0x08
345#define VIO_HS_SENT_RDX 0x10
346#define VIO_HS_GOT_RDX_ACK 0x20
347#define VIO_HS_GOT_RDX 0x40
348#define VIO_HS_SENT_RDX_ACK 0x80
349#define VIO_HS_COMPLETE (VIO_HS_GOT_RDX_ACK | VIO_HS_SENT_RDX_ACK)
350
351 u8 dev_class;
352
353 u8 dr_state;
354#define VIO_DR_STATE_TXREG 0x01
355#define VIO_DR_STATE_RXREG 0x02
356#define VIO_DR_STATE_TXREQ 0x10
357#define VIO_DR_STATE_RXREQ 0x20
358
359 u8 debug;
360#define VIO_DEBUG_HS 0x01
361#define VIO_DEBUG_DATA 0x02
362
363 void *desc_buf;
364 unsigned int desc_buf_len;
365
366 struct vio_completion *cmp;
367
368 struct vio_dev *vdev;
369
370 struct timer_list timer;
371
372 struct vio_version ver;
373
374 struct vio_version *ver_table;
375 int ver_table_entries;
376
377 char *name;
378
379 struct vio_driver_ops *ops;
380};
381
David L Stevens163a4e72014-09-29 19:47:59 -0400382static inline bool vio_version_before(struct vio_driver_state *vio,
383 u16 major, u16 minor)
384{
385 u32 have = (u32)vio->ver.major << 16 | vio->ver.minor;
386 u32 want = (u32)major << 16 | minor;
387
388 return have < want;
389}
390
391static inline bool vio_version_after(struct vio_driver_state *vio,
392 u16 major, u16 minor)
393{
394 u32 have = (u32)vio->ver.major << 16 | vio->ver.minor;
395 u32 want = (u32)major << 16 | minor;
396
397 return have > want;
398}
399
400static inline bool vio_version_after_eq(struct vio_driver_state *vio,
401 u16 major, u16 minor)
402{
403 u32 have = (u32)vio->ver.major << 16 | vio->ver.minor;
404 u32 want = (u32)major << 16 | minor;
405
406 return have >= want;
407}
408
Sam Ravnborga00736e2008-06-19 20:26:19 +0200409#define viodbg(TYPE, f, a...) \
410do { if (vio->debug & VIO_DEBUG_##TYPE) \
411 printk(KERN_INFO "vio: ID[%lu] " f, \
412 vio->vdev->channel_id, ## a); \
413} while (0)
414
Sam Ravnborgf05a6862014-05-16 23:25:50 +0200415int __vio_register_driver(struct vio_driver *drv, struct module *owner,
Benjamin Herrenschmidtcb52d892012-03-26 19:06:30 +0000416 const char *mod_name);
417/*
418 * vio_register_driver must be a macro so that KBUILD_MODNAME can be expanded
419 */
420#define vio_register_driver(driver) \
421 __vio_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
Sam Ravnborgf05a6862014-05-16 23:25:50 +0200422void vio_unregister_driver(struct vio_driver *drv);
Sam Ravnborga00736e2008-06-19 20:26:19 +0200423
424static inline struct vio_driver *to_vio_driver(struct device_driver *drv)
425{
426 return container_of(drv, struct vio_driver, driver);
427}
428
429static inline struct vio_dev *to_vio_dev(struct device *dev)
430{
431 return container_of(dev, struct vio_dev, dev);
432}
433
Sam Ravnborgf05a6862014-05-16 23:25:50 +0200434int vio_ldc_send(struct vio_driver_state *vio, void *data, int len);
435void vio_link_state_change(struct vio_driver_state *vio, int event);
436void vio_conn_reset(struct vio_driver_state *vio);
437int vio_control_pkt_engine(struct vio_driver_state *vio, void *pkt);
438int vio_validate_sid(struct vio_driver_state *vio,
439 struct vio_msg_tag *tp);
440u32 vio_send_sid(struct vio_driver_state *vio);
441int vio_ldc_alloc(struct vio_driver_state *vio,
442 struct ldc_channel_config *base_cfg, void *event_arg);
443void vio_ldc_free(struct vio_driver_state *vio);
444int vio_driver_init(struct vio_driver_state *vio, struct vio_dev *vdev,
445 u8 dev_class, struct vio_version *ver_table,
446 int ver_table_size, struct vio_driver_ops *ops,
447 char *name);
Sam Ravnborga00736e2008-06-19 20:26:19 +0200448
Sam Ravnborgf05a6862014-05-16 23:25:50 +0200449void vio_port_up(struct vio_driver_state *vio);
Sam Ravnborga00736e2008-06-19 20:26:19 +0200450
451#endif /* _SPARC64_VIO_H */