Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vio.h
Go to the documentation of this file.
1 #ifndef _SPARC64_VIO_H
2 #define _SPARC64_VIO_H
3 
4 #include <linux/kernel.h>
5 #include <linux/device.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 
16 struct vio_msg_tag {
18 #define VIO_TYPE_CTRL 0x01
19 #define VIO_TYPE_DATA 0x02
20 #define VIO_TYPE_ERR 0x04
21 
23 #define VIO_SUBTYPE_INFO 0x01
24 #define VIO_SUBTYPE_ACK 0x02
25 #define VIO_SUBTYPE_NACK 0x04
26 
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 
39 };
40 
41 struct vio_rdx {
42  struct vio_msg_tag tag;
43  u64 resv[6];
44 };
45 
46 struct vio_ver_info {
47  struct vio_msg_tag tag;
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 
61  struct vio_msg_tag tag;
66 #define VIO_TX_DRING 0x0001
67 #define VIO_RX_DRING 0x0002
71 };
72 
74  struct vio_msg_tag tag;
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 
85  struct vio_msg_tag tag;
91 #define VIO_DRING_ACTIVE 0x01
92 #define VIO_DRING_STOPPED 0x02
93 
97  u64 __par4[2];
98 };
99 
102 #define VIO_DESC_FREE 0x01
103 #define VIO_DESC_READY 0x02
104 #define VIO_DESC_ACCEPTED 0x03
105 #define VIO_DESC_DONE 0x04
107 #define VIO_ACK_ENABLE 0x01
108 #define VIO_ACK_DISABLE 0x00
109 
112 };
113 
114 /* VIO disk specific structures and defines */
116  struct vio_msg_tag tag;
119 #define VD_DISK_TYPE_SLICE 0x01 /* Slice in block device */
120 #define VD_DISK_TYPE_DISK 0x02 /* Entire block device */
126  u64 resv2[2];
127 };
128 
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 */
154 };
155 
156 #define VIO_DISK_VNAME_LEN 8
157 #define VIO_DISK_ALABEL_LEN 128
158 #define VIO_DISK_NUM_PART 8
159 
165  struct {
172 };
173 
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 
192  char id[0];
193 };
194 
195 struct vio_disk_efi {
198  char data[0];
199 };
200 
201 /* VIO net specific structures and defines */
203  struct vio_msg_tag tag;
206 #define VNET_ADDR_ETHERMAC 0x01
211  u64 resv2[3];
212 };
213 
214 #define VNET_NUM_MCAST 7
215 
217  struct vio_msg_tag tag;
218  u8 set;
222 };
223 
224 struct vio_net_desc {
229 };
230 
231 #define VIO_MAX_RING_COOKIES 24
232 
235  void *base;
243  int ncookies;
245 };
246 
247 static inline void *vio_dring_cur(struct vio_dring_state *dr)
248 {
249  return dr->base + (dr->entry_size * dr->prod);
250 }
251 
252 static 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 
258 static 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 
268 struct vio_dev {
270  struct device_node *dp;
271 
275 
277 
278  unsigned long channel_id;
279 
280  unsigned int tx_irq;
281  unsigned int rx_irq;
282 
283  struct device dev;
284 };
285 
286 struct vio_driver {
287  const char *name;
288  struct list_head node;
289  const struct vio_device_id *id_table;
290  int (*probe)(struct vio_dev *dev, const struct vio_device_id *id);
291  int (*remove)(struct vio_dev *dev);
292  void (*shutdown)(struct vio_dev *dev);
293  unsigned long driver_data;
295 };
296 
297 struct vio_version {
300 };
301 
302 struct vio_driver_state;
304  int (*send_attr)(struct vio_driver_state *vio);
305  int (*handle_attr)(struct vio_driver_state *vio, void *pkt);
307 };
308 
310  struct completion com;
311  int err;
313 };
314 
316  /* Protects VIO handshake and, optionally, driver private state. */
318 
319  struct ldc_channel *lp;
320 
324 #define VIO_DRIVER_TX_RING 0
325 #define VIO_DRIVER_RX_RING 1
326 
328 #define VIO_HS_INVALID 0x00
329 #define VIO_HS_GOTVERS 0x01
330 #define VIO_HS_GOT_ATTR 0x04
331 #define VIO_HS_SENT_DREG 0x08
332 #define VIO_HS_SENT_RDX 0x10
333 #define VIO_HS_GOT_RDX_ACK 0x20
334 #define VIO_HS_GOT_RDX 0x40
335 #define VIO_HS_SENT_RDX_ACK 0x80
336 #define VIO_HS_COMPLETE (VIO_HS_GOT_RDX_ACK | VIO_HS_SENT_RDX_ACK)
337 
339 
341 #define VIO_DR_STATE_TXREG 0x01
342 #define VIO_DR_STATE_RXREG 0x02
343 #define VIO_DR_STATE_TXREQ 0x10
344 #define VIO_DR_STATE_RXREQ 0x20
345 
347 #define VIO_DEBUG_HS 0x01
348 #define VIO_DEBUG_DATA 0x02
349 
350  void *desc_buf;
351  unsigned int desc_buf_len;
352 
354 
355  struct vio_dev *vdev;
356 
358 
359  struct vio_version ver;
360 
363 
364  char *name;
365 
367 };
368 
369 #define viodbg(TYPE, f, a...) \
370 do { if (vio->debug & VIO_DEBUG_##TYPE) \
371  printk(KERN_INFO "vio: ID[%lu] " f, \
372  vio->vdev->channel_id, ## a); \
373 } while (0)
374 
375 extern int __vio_register_driver(struct vio_driver *drv, struct module *owner,
376  const char *mod_name);
377 /*
378  * vio_register_driver must be a macro so that KBUILD_MODNAME can be expanded
379  */
380 #define vio_register_driver(driver) \
381  __vio_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
382 extern void vio_unregister_driver(struct vio_driver *drv);
383 
384 static inline struct vio_driver *to_vio_driver(struct device_driver *drv)
385 {
386  return container_of(drv, struct vio_driver, driver);
387 }
388 
389 static inline struct vio_dev *to_vio_dev(struct device *dev)
390 {
391  return container_of(dev, struct vio_dev, dev);
392 }
393 
394 extern int vio_ldc_send(struct vio_driver_state *vio, void *data, int len);
395 extern void vio_link_state_change(struct vio_driver_state *vio, int event);
396 extern void vio_conn_reset(struct vio_driver_state *vio);
397 extern int vio_control_pkt_engine(struct vio_driver_state *vio, void *pkt);
398 extern int vio_validate_sid(struct vio_driver_state *vio,
399  struct vio_msg_tag *tp);
400 extern u32 vio_send_sid(struct vio_driver_state *vio);
401 extern int vio_ldc_alloc(struct vio_driver_state *vio,
402  struct ldc_channel_config *base_cfg, void *event_arg);
403 extern void vio_ldc_free(struct vio_driver_state *vio);
404 extern int vio_driver_init(struct vio_driver_state *vio, struct vio_dev *vdev,
405  u8 dev_class, struct vio_version *ver_table,
406  int ver_table_size, struct vio_driver_ops *ops,
407  char *name);
408 
409 extern void vio_port_up(struct vio_driver_state *vio);
410 
411 #endif /* _SPARC64_VIO_H */