0001
0002 #ifndef _SPARC64_VIO_H
0003 #define _SPARC64_VIO_H
0004
0005 #include <linux/kernel.h>
0006 #include <linux/device.h>
0007 #include <linux/mod_devicetable.h>
0008 #include <linux/timer.h>
0009 #include <linux/spinlock.h>
0010 #include <linux/completion.h>
0011 #include <linux/list.h>
0012 #include <linux/log2.h>
0013
0014 #include <asm/ldc.h>
0015 #include <asm/mdesc.h>
0016
0017 struct vio_msg_tag {
0018 u8 type;
0019 #define VIO_TYPE_CTRL 0x01
0020 #define VIO_TYPE_DATA 0x02
0021 #define VIO_TYPE_ERR 0x04
0022
0023 u8 stype;
0024 #define VIO_SUBTYPE_INFO 0x01
0025 #define VIO_SUBTYPE_ACK 0x02
0026 #define VIO_SUBTYPE_NACK 0x04
0027
0028 u16 stype_env;
0029 #define VIO_VER_INFO 0x0001
0030 #define VIO_ATTR_INFO 0x0002
0031 #define VIO_DRING_REG 0x0003
0032 #define VIO_DRING_UNREG 0x0004
0033 #define VIO_RDX 0x0005
0034 #define VIO_PKT_DATA 0x0040
0035 #define VIO_DESC_DATA 0x0041
0036 #define VIO_DRING_DATA 0x0042
0037 #define VNET_MCAST_INFO 0x0101
0038
0039 u32 sid;
0040 };
0041
0042 struct vio_rdx {
0043 struct vio_msg_tag tag;
0044 u64 resv[6];
0045 };
0046
0047 struct vio_ver_info {
0048 struct vio_msg_tag tag;
0049 u16 major;
0050 u16 minor;
0051 u8 dev_class;
0052 #define VDEV_NETWORK 0x01
0053 #define VDEV_NETWORK_SWITCH 0x02
0054 #define VDEV_DISK 0x03
0055 #define VDEV_DISK_SERVER 0x04
0056 #define VDEV_CONSOLE_CON 0x05
0057
0058 u8 resv1[3];
0059 u64 resv2[5];
0060 };
0061
0062 struct vio_dring_register {
0063 struct vio_msg_tag tag;
0064 u64 dring_ident;
0065 u32 num_descr;
0066 u32 descr_size;
0067 u16 options;
0068 #define VIO_TX_DRING 0x0001
0069 #define VIO_RX_DRING 0x0002
0070 #define VIO_RX_DRING_DATA 0x0004
0071 u16 resv;
0072 u32 num_cookies;
0073 struct ldc_trans_cookie cookies[];
0074 };
0075
0076 struct vio_dring_unregister {
0077 struct vio_msg_tag tag;
0078 u64 dring_ident;
0079 u64 resv[5];
0080 };
0081
0082
0083 #define VIO_PKT_MODE 0x01
0084 #define VIO_DESC_MODE 0x02
0085 #define VIO_DRING_MODE 0x03
0086
0087 #define VIO_NEW_DRING_MODE 0x04
0088
0089 struct vio_dring_data {
0090 struct vio_msg_tag tag;
0091 u64 seq;
0092 u64 dring_ident;
0093 u32 start_idx;
0094 u32 end_idx;
0095 u8 state;
0096 #define VIO_DRING_ACTIVE 0x01
0097 #define VIO_DRING_STOPPED 0x02
0098
0099 u8 __pad1;
0100 u16 __pad2;
0101 u32 __pad3;
0102 u64 __par4[2];
0103 };
0104
0105 struct vio_dring_hdr {
0106 u8 state;
0107 #define VIO_DESC_FREE 0x01
0108 #define VIO_DESC_READY 0x02
0109 #define VIO_DESC_ACCEPTED 0x03
0110 #define VIO_DESC_DONE 0x04
0111 u8 ack;
0112 #define VIO_ACK_ENABLE 0x01
0113 #define VIO_ACK_DISABLE 0x00
0114
0115 u16 __pad1;
0116 u32 __pad2;
0117 };
0118
0119
0120 struct vio_disk_attr_info {
0121 struct vio_msg_tag tag;
0122 u8 xfer_mode;
0123 u8 vdisk_type;
0124 #define VD_DISK_TYPE_SLICE 0x01
0125 #define VD_DISK_TYPE_DISK 0x02
0126 u8 vdisk_mtype;
0127 #define VD_MEDIA_TYPE_FIXED 0x01
0128 #define VD_MEDIA_TYPE_CD 0x02
0129 #define VD_MEDIA_TYPE_DVD 0x03
0130 u8 resv1;
0131 u32 vdisk_block_size;
0132 u64 operations;
0133 u64 vdisk_size;
0134 u64 max_xfer_size;
0135 u32 phys_block_size;
0136 u32 resv2;
0137 u64 resv3[1];
0138 };
0139
0140 struct vio_disk_desc {
0141 struct vio_dring_hdr hdr;
0142 u64 req_id;
0143 u8 operation;
0144 #define VD_OP_BREAD 0x01
0145 #define VD_OP_BWRITE 0x02
0146 #define VD_OP_FLUSH 0x03
0147 #define VD_OP_GET_WCE 0x04
0148 #define VD_OP_SET_WCE 0x05
0149 #define VD_OP_GET_VTOC 0x06
0150 #define VD_OP_SET_VTOC 0x07
0151 #define VD_OP_GET_DISKGEOM 0x08
0152 #define VD_OP_SET_DISKGEOM 0x09
0153 #define VD_OP_SCSICMD 0x0a
0154 #define VD_OP_GET_DEVID 0x0b
0155 #define VD_OP_GET_EFI 0x0c
0156 #define VD_OP_SET_EFI 0x0d
0157 u8 slice;
0158 u16 resv1;
0159 u32 status;
0160 u64 offset;
0161 u64 size;
0162 u32 ncookies;
0163 u32 resv2;
0164 struct ldc_trans_cookie cookies[];
0165 };
0166
0167 #define VIO_DISK_VNAME_LEN 8
0168 #define VIO_DISK_ALABEL_LEN 128
0169 #define VIO_DISK_NUM_PART 8
0170
0171 struct vio_disk_vtoc {
0172 u8 volume_name[VIO_DISK_VNAME_LEN];
0173 u16 sector_size;
0174 u16 num_partitions;
0175 u8 ascii_label[VIO_DISK_ALABEL_LEN];
0176 struct {
0177 u16 id;
0178 u16 perm_flags;
0179 u32 resv;
0180 u64 start_block;
0181 u64 num_blocks;
0182 } partitions[VIO_DISK_NUM_PART];
0183 };
0184
0185 struct vio_disk_geom {
0186 u16 num_cyl;
0187 u16 alt_cyl;
0188 u16 beg_cyl;
0189 u16 num_hd;
0190 u16 num_sec;
0191 u16 ifact;
0192 u16 apc;
0193 u16 rpm;
0194 u16 phy_cyl;
0195 u16 wr_skip;
0196 u16 rd_skip;
0197 };
0198
0199 struct vio_disk_devid {
0200 u16 resv;
0201 u16 type;
0202 u32 len;
0203 char id[];
0204 };
0205
0206 struct vio_disk_efi {
0207 u64 lba;
0208 u64 len;
0209 char data[];
0210 };
0211
0212
0213 struct vio_net_attr_info {
0214 struct vio_msg_tag tag;
0215 u8 xfer_mode;
0216 u8 addr_type;
0217 #define VNET_ADDR_ETHERMAC 0x01
0218 u16 ack_freq;
0219 u8 plnk_updt;
0220 #define PHYSLINK_UPDATE_NONE 0x00
0221 #define PHYSLINK_UPDATE_STATE 0x01
0222 #define PHYSLINK_UPDATE_STATE_ACK 0x02
0223 #define PHYSLINK_UPDATE_STATE_NACK 0x03
0224 u8 options;
0225 u16 resv1;
0226 u64 addr;
0227 u64 mtu;
0228 u16 cflags;
0229 #define VNET_LSO_IPV4_CAPAB 0x0001
0230 u16 ipv4_lso_maxlen;
0231 u32 resv2;
0232 u64 resv3[2];
0233 };
0234
0235 #define VNET_NUM_MCAST 7
0236
0237 struct vio_net_mcast_info {
0238 struct vio_msg_tag tag;
0239 u8 set;
0240 u8 count;
0241 u8 mcast_addr[VNET_NUM_MCAST * 6];
0242 u32 resv;
0243 };
0244
0245 struct vio_net_desc {
0246 struct vio_dring_hdr hdr;
0247 u32 size;
0248 u32 ncookies;
0249 struct ldc_trans_cookie cookies[];
0250 };
0251
0252 struct vio_net_dext {
0253 u8 flags;
0254 #define VNET_PKT_HASH 0x01
0255 #define VNET_PKT_HCK_IPV4_HDRCKSUM 0x02
0256 #define VNET_PKT_HCK_FULLCKSUM 0x04
0257 #define VNET_PKT_IPV4_LSO 0x08
0258 #define VNET_PKT_HCK_IPV4_HDRCKSUM_OK 0x10
0259 #define VNET_PKT_HCK_FULLCKSUM_OK 0x20
0260
0261 u8 vnet_hashval;
0262 u16 ipv4_lso_mss;
0263 u32 resv3;
0264 };
0265
0266 static inline struct vio_net_dext *vio_net_ext(struct vio_net_desc *desc)
0267 {
0268 return (struct vio_net_dext *)&desc->cookies[2];
0269 }
0270
0271 #define VIO_MAX_RING_COOKIES 24
0272
0273 struct vio_dring_state {
0274 u64 ident;
0275 void *base;
0276 u64 snd_nxt;
0277 u64 rcv_nxt;
0278 u32 entry_size;
0279 u32 num_entries;
0280 u32 prod;
0281 u32 cons;
0282 u32 pending;
0283 int ncookies;
0284 struct ldc_trans_cookie cookies[VIO_MAX_RING_COOKIES];
0285 };
0286
0287 #define VIO_TAG_SIZE ((int)sizeof(struct vio_msg_tag))
0288 #define VIO_VCC_MTU_SIZE (LDC_PACKET_SIZE - VIO_TAG_SIZE)
0289
0290 struct vio_vcc {
0291 struct vio_msg_tag tag;
0292 char data[VIO_VCC_MTU_SIZE];
0293 };
0294
0295 static inline void *vio_dring_cur(struct vio_dring_state *dr)
0296 {
0297 return dr->base + (dr->entry_size * dr->prod);
0298 }
0299
0300 static inline void *vio_dring_entry(struct vio_dring_state *dr,
0301 unsigned int index)
0302 {
0303 return dr->base + (dr->entry_size * index);
0304 }
0305
0306 static inline u32 vio_dring_avail(struct vio_dring_state *dr,
0307 unsigned int ring_size)
0308 {
0309 return (dr->pending -
0310 ((dr->prod - dr->cons) & (ring_size - 1)) - 1);
0311 }
0312
0313 static inline u32 vio_dring_next(struct vio_dring_state *dr, u32 index)
0314 {
0315 if (++index == dr->num_entries)
0316 index = 0;
0317 return index;
0318 }
0319
0320 static inline u32 vio_dring_prev(struct vio_dring_state *dr, u32 index)
0321 {
0322 if (index == 0)
0323 return dr->num_entries - 1;
0324 else
0325 return index - 1;
0326 }
0327
0328 #define VIO_MAX_TYPE_LEN 32
0329 #define VIO_MAX_NAME_LEN 32
0330 #define VIO_MAX_COMPAT_LEN 64
0331
0332 struct vio_dev {
0333 u64 mp;
0334 struct device_node *dp;
0335
0336 char node_name[VIO_MAX_NAME_LEN];
0337 char type[VIO_MAX_TYPE_LEN];
0338 char compat[VIO_MAX_COMPAT_LEN];
0339 int compat_len;
0340
0341 u64 dev_no;
0342
0343 unsigned long port_id;
0344 unsigned long channel_id;
0345
0346 unsigned int tx_irq;
0347 unsigned int rx_irq;
0348 u64 rx_ino;
0349 u64 tx_ino;
0350
0351
0352 u64 cdev_handle;
0353
0354
0355 union md_node_info md_node_info;
0356
0357 struct device dev;
0358 };
0359
0360 struct vio_driver {
0361 const char *name;
0362 struct list_head node;
0363 const struct vio_device_id *id_table;
0364 int (*probe)(struct vio_dev *dev, const struct vio_device_id *id);
0365 void (*remove)(struct vio_dev *dev);
0366 void (*shutdown)(struct vio_dev *dev);
0367 unsigned long driver_data;
0368 struct device_driver driver;
0369 bool no_irq;
0370 };
0371
0372 struct vio_version {
0373 u16 major;
0374 u16 minor;
0375 };
0376
0377 struct vio_driver_state;
0378 struct vio_driver_ops {
0379 int (*send_attr)(struct vio_driver_state *vio);
0380 int (*handle_attr)(struct vio_driver_state *vio, void *pkt);
0381 void (*handshake_complete)(struct vio_driver_state *vio);
0382 };
0383
0384 struct vio_completion {
0385 struct completion com;
0386 int err;
0387 int waiting_for;
0388 };
0389
0390 struct vio_driver_state {
0391
0392 spinlock_t lock;
0393
0394 struct ldc_channel *lp;
0395
0396 u32 _peer_sid;
0397 u32 _local_sid;
0398 struct vio_dring_state drings[2];
0399 #define VIO_DRIVER_TX_RING 0
0400 #define VIO_DRIVER_RX_RING 1
0401
0402 u8 hs_state;
0403 #define VIO_HS_INVALID 0x00
0404 #define VIO_HS_GOTVERS 0x01
0405 #define VIO_HS_GOT_ATTR 0x04
0406 #define VIO_HS_SENT_DREG 0x08
0407 #define VIO_HS_SENT_RDX 0x10
0408 #define VIO_HS_GOT_RDX_ACK 0x20
0409 #define VIO_HS_GOT_RDX 0x40
0410 #define VIO_HS_SENT_RDX_ACK 0x80
0411 #define VIO_HS_COMPLETE (VIO_HS_GOT_RDX_ACK | VIO_HS_SENT_RDX_ACK)
0412
0413 u8 dev_class;
0414
0415 u8 dr_state;
0416 #define VIO_DR_STATE_TXREG 0x01
0417 #define VIO_DR_STATE_RXREG 0x02
0418 #define VIO_DR_STATE_TXREQ 0x10
0419 #define VIO_DR_STATE_RXREQ 0x20
0420
0421 u8 debug;
0422 #define VIO_DEBUG_HS 0x01
0423 #define VIO_DEBUG_DATA 0x02
0424
0425 void *desc_buf;
0426 unsigned int desc_buf_len;
0427
0428 struct vio_completion *cmp;
0429
0430 struct vio_dev *vdev;
0431
0432 struct timer_list timer;
0433
0434 struct vio_version ver;
0435
0436 struct vio_version *ver_table;
0437 int ver_table_entries;
0438
0439 char *name;
0440
0441 struct vio_driver_ops *ops;
0442 };
0443
0444 static inline bool vio_version_before(struct vio_driver_state *vio,
0445 u16 major, u16 minor)
0446 {
0447 u32 have = (u32)vio->ver.major << 16 | vio->ver.minor;
0448 u32 want = (u32)major << 16 | minor;
0449
0450 return have < want;
0451 }
0452
0453 static inline bool vio_version_after(struct vio_driver_state *vio,
0454 u16 major, u16 minor)
0455 {
0456 u32 have = (u32)vio->ver.major << 16 | vio->ver.minor;
0457 u32 want = (u32)major << 16 | minor;
0458
0459 return have > want;
0460 }
0461
0462 static inline bool vio_version_after_eq(struct vio_driver_state *vio,
0463 u16 major, u16 minor)
0464 {
0465 u32 have = (u32)vio->ver.major << 16 | vio->ver.minor;
0466 u32 want = (u32)major << 16 | minor;
0467
0468 return have >= want;
0469 }
0470
0471 #define viodbg(TYPE, f, a...) \
0472 do { if (vio->debug & VIO_DEBUG_##TYPE) \
0473 printk(KERN_INFO "vio: ID[%lu] " f, \
0474 vio->vdev->channel_id, ## a); \
0475 } while (0)
0476
0477 int __vio_register_driver(struct vio_driver *drv, struct module *owner,
0478 const char *mod_name);
0479
0480
0481
0482 #define vio_register_driver(driver) \
0483 __vio_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
0484 void vio_unregister_driver(struct vio_driver *drv);
0485
0486 static inline struct vio_driver *to_vio_driver(struct device_driver *drv)
0487 {
0488 return container_of(drv, struct vio_driver, driver);
0489 }
0490
0491 static inline struct vio_dev *to_vio_dev(struct device *dev)
0492 {
0493 return container_of(dev, struct vio_dev, dev);
0494 }
0495
0496 int vio_ldc_send(struct vio_driver_state *vio, void *data, int len);
0497 void vio_link_state_change(struct vio_driver_state *vio, int event);
0498 void vio_conn_reset(struct vio_driver_state *vio);
0499 int vio_control_pkt_engine(struct vio_driver_state *vio, void *pkt);
0500 int vio_validate_sid(struct vio_driver_state *vio,
0501 struct vio_msg_tag *tp);
0502 u32 vio_send_sid(struct vio_driver_state *vio);
0503 int vio_ldc_alloc(struct vio_driver_state *vio,
0504 struct ldc_channel_config *base_cfg, void *event_arg);
0505 void vio_ldc_free(struct vio_driver_state *vio);
0506 int vio_driver_init(struct vio_driver_state *vio, struct vio_dev *vdev,
0507 u8 dev_class, struct vio_version *ver_table,
0508 int ver_table_size, struct vio_driver_ops *ops,
0509 char *name);
0510
0511 void vio_port_up(struct vio_driver_state *vio);
0512 int vio_set_intr(unsigned long dev_ino, int state);
0513 u64 vio_vdev_node(struct mdesc_handle *hp, struct vio_dev *vdev);
0514
0515 #endif