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>
14 #include <asm/mdesc.h>
18 #define VIO_TYPE_CTRL 0x01
19 #define VIO_TYPE_DATA 0x02
20 #define VIO_TYPE_ERR 0x04
23 #define VIO_SUBTYPE_INFO 0x01
24 #define VIO_SUBTYPE_ACK 0x02
25 #define VIO_SUBTYPE_NACK 0x04
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
42 struct vio_msg_tag tag;
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
60 struct vio_dring_register {
61 struct vio_msg_tag tag;
66 #define VIO_TX_DRING 0x0001
67 #define VIO_RX_DRING 0x0002
68 #define VIO_RX_DRING_DATA 0x0004
71 struct ldc_trans_cookie cookies[0];
74 struct vio_dring_unregister {
75 struct vio_msg_tag tag;
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 */
84 /* in vers >= 1.2, VIO_DRING_MODE is 0x04 and transfer mode is a bitmask */
85 #define VIO_NEW_DRING_MODE 0x04
87 struct vio_dring_data {
88 struct vio_msg_tag tag;
94 #define VIO_DRING_ACTIVE 0x01
95 #define VIO_DRING_STOPPED 0x02
103 struct vio_dring_hdr {
105 #define VIO_DESC_FREE 0x01
106 #define VIO_DESC_READY 0x02
107 #define VIO_DESC_ACCEPTED 0x03
108 #define VIO_DESC_DONE 0x04
110 #define VIO_ACK_ENABLE 0x01
111 #define VIO_ACK_DISABLE 0x00
117 /* VIO disk specific structures and defines */
118 struct vio_disk_attr_info {
119 struct vio_msg_tag tag;
122 #define VD_DISK_TYPE_SLICE 0x01 /* Slice in block device */
123 #define VD_DISK_TYPE_DISK 0x02 /* Entire block device */
125 u32 vdisk_block_size;
132 struct vio_disk_desc {
133 struct vio_dring_hdr hdr;
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 */
156 struct ldc_trans_cookie cookies[0];
159 #define VIO_DISK_VNAME_LEN 8
160 #define VIO_DISK_ALABEL_LEN 128
161 #define VIO_DISK_NUM_PART 8
163 struct vio_disk_vtoc {
164 u8 volume_name[VIO_DISK_VNAME_LEN];
167 u8 ascii_label[VIO_DISK_ALABEL_LEN];
174 } partitions[VIO_DISK_NUM_PART];
177 struct 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 */
191 struct vio_disk_devid {
198 struct vio_disk_efi {
204 /* VIO net specific structures and defines */
205 struct vio_net_attr_info {
206 struct vio_msg_tag tag;
209 #define VNET_ADDR_ETHERMAC 0x01
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
221 #define VNET_LSO_IPV4_CAPAB 0x0001
227 #define VNET_NUM_MCAST 7
229 struct vio_net_mcast_info {
230 struct vio_msg_tag tag;
233 u8 mcast_addr[VNET_NUM_MCAST * 6];
237 struct vio_net_desc {
238 struct vio_dring_hdr hdr;
241 struct ldc_trans_cookie cookies[0];
244 #define VIO_MAX_RING_COOKIES 24
246 struct vio_dring_state {
257 struct ldc_trans_cookie cookies[VIO_MAX_RING_COOKIES];
260 static inline void *vio_dring_cur(struct vio_dring_state *dr)
262 return dr->base + (dr->entry_size * dr->prod);
265 static inline void *vio_dring_entry(struct vio_dring_state *dr,
268 return dr->base + (dr->entry_size * index);
271 static inline u32 vio_dring_avail(struct vio_dring_state *dr,
272 unsigned int ring_size)
274 return (dr->pending -
275 ((dr->prod - dr->cons) & (ring_size - 1)));
278 #define VIO_MAX_TYPE_LEN 32
279 #define VIO_MAX_COMPAT_LEN 64
283 struct device_node *dp;
285 char type[VIO_MAX_TYPE_LEN];
286 char compat[VIO_MAX_COMPAT_LEN];
291 unsigned long channel_id;
301 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;
315 struct vio_driver_state;
316 struct 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);
322 struct vio_completion {
323 struct completion com;
328 struct vio_driver_state {
329 /* Protects VIO handshake and, optionally, driver private state. */
332 struct ldc_channel *lp;
336 struct vio_dring_state drings[2];
337 #define VIO_DRIVER_TX_RING 0
338 #define VIO_DRIVER_RX_RING 1
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)
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
360 #define VIO_DEBUG_HS 0x01
361 #define VIO_DEBUG_DATA 0x02
364 unsigned int desc_buf_len;
366 struct vio_completion *cmp;
368 struct vio_dev *vdev;
370 struct timer_list timer;
372 struct vio_version ver;
374 struct vio_version *ver_table;
375 int ver_table_entries;
379 struct vio_driver_ops *ops;
382 static inline bool vio_version_before(struct vio_driver_state *vio,
383 u16 major, u16 minor)
385 u32 have = (u32)vio->ver.major << 16 | vio->ver.minor;
386 u32 want = (u32)major << 16 | minor;
391 static inline bool vio_version_after(struct vio_driver_state *vio,
392 u16 major, u16 minor)
394 u32 have = (u32)vio->ver.major << 16 | vio->ver.minor;
395 u32 want = (u32)major << 16 | minor;
400 static inline bool vio_version_after_eq(struct vio_driver_state *vio,
401 u16 major, u16 minor)
403 u32 have = (u32)vio->ver.major << 16 | vio->ver.minor;
404 u32 want = (u32)major << 16 | minor;
409 #define viodbg(TYPE, f, a...) \
410 do { if (vio->debug & VIO_DEBUG_##TYPE) \
411 printk(KERN_INFO "vio: ID[%lu] " f, \
412 vio->vdev->channel_id, ## a); \
415 int __vio_register_driver(struct vio_driver *drv, struct module *owner,
416 const char *mod_name);
418 * vio_register_driver must be a macro so that KBUILD_MODNAME can be expanded
420 #define vio_register_driver(driver) \
421 __vio_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
422 void vio_unregister_driver(struct vio_driver *drv);
424 static inline struct vio_driver *to_vio_driver(struct device_driver *drv)
426 return container_of(drv, struct vio_driver, driver);
429 static inline struct vio_dev *to_vio_dev(struct device *dev)
431 return container_of(dev, struct vio_dev, dev);
434 int vio_ldc_send(struct vio_driver_state *vio, void *data, int len);
435 void vio_link_state_change(struct vio_driver_state *vio, int event);
436 void vio_conn_reset(struct vio_driver_state *vio);
437 int vio_control_pkt_engine(struct vio_driver_state *vio, void *pkt);
438 int vio_validate_sid(struct vio_driver_state *vio,
439 struct vio_msg_tag *tp);
440 u32 vio_send_sid(struct vio_driver_state *vio);
441 int vio_ldc_alloc(struct vio_driver_state *vio,
442 struct ldc_channel_config *base_cfg, void *event_arg);
443 void vio_ldc_free(struct vio_driver_state *vio);
444 int 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,
449 void vio_port_up(struct vio_driver_state *vio);
451 #endif /* _SPARC64_VIO_H */