vio.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. #ifndef _SPARC64_VIO_H
  2. #define _SPARC64_VIO_H
  3. #include <linux/kernel.h>
  4. #include <linux/device.h>
  5. #include <linux/mod_devicetable.h>
  6. #include <linux/timer.h>
  7. #include <linux/spinlock.h>
  8. #include <linux/completion.h>
  9. #include <linux/list.h>
  10. #include <linux/log2.h>
  11. #include <asm/ldc.h>
  12. #include <asm/mdesc.h>
  13. struct vio_msg_tag {
  14. u8 type;
  15. #define VIO_TYPE_CTRL 0x01
  16. #define VIO_TYPE_DATA 0x02
  17. #define VIO_TYPE_ERR 0x04
  18. u8 stype;
  19. #define VIO_SUBTYPE_INFO 0x01
  20. #define VIO_SUBTYPE_ACK 0x02
  21. #define VIO_SUBTYPE_NACK 0x04
  22. u16 stype_env;
  23. #define VIO_VER_INFO 0x0001
  24. #define VIO_ATTR_INFO 0x0002
  25. #define VIO_DRING_REG 0x0003
  26. #define VIO_DRING_UNREG 0x0004
  27. #define VIO_RDX 0x0005
  28. #define VIO_PKT_DATA 0x0040
  29. #define VIO_DESC_DATA 0x0041
  30. #define VIO_DRING_DATA 0x0042
  31. #define VNET_MCAST_INFO 0x0101
  32. u32 sid;
  33. };
  34. struct vio_rdx {
  35. struct vio_msg_tag tag;
  36. u64 resv[6];
  37. };
  38. struct vio_ver_info {
  39. struct vio_msg_tag tag;
  40. u16 major;
  41. u16 minor;
  42. u8 dev_class;
  43. #define VDEV_NETWORK 0x01
  44. #define VDEV_NETWORK_SWITCH 0x02
  45. #define VDEV_DISK 0x03
  46. #define VDEV_DISK_SERVER 0x04
  47. u8 resv1[3];
  48. u64 resv2[5];
  49. };
  50. struct vio_dring_register {
  51. struct vio_msg_tag tag;
  52. u64 dring_ident;
  53. u32 num_descr;
  54. u32 descr_size;
  55. u16 options;
  56. #define VIO_TX_DRING 0x0001
  57. #define VIO_RX_DRING 0x0002
  58. u16 resv;
  59. u32 num_cookies;
  60. struct ldc_trans_cookie cookies[0];
  61. };
  62. struct vio_dring_unregister {
  63. struct vio_msg_tag tag;
  64. u64 dring_ident;
  65. u64 resv[5];
  66. };
  67. /* Data transfer modes */
  68. #define VIO_PKT_MODE 0x01 /* Packet based transfer */
  69. #define VIO_DESC_MODE 0x02 /* In-band descriptors */
  70. #define VIO_DRING_MODE 0x03 /* Descriptor rings */
  71. struct vio_dring_data {
  72. struct vio_msg_tag tag;
  73. u64 seq;
  74. u64 dring_ident;
  75. u32 start_idx;
  76. u32 end_idx;
  77. u8 state;
  78. #define VIO_DRING_ACTIVE 0x01
  79. #define VIO_DRING_STOPPED 0x02
  80. u8 __pad1;
  81. u16 __pad2;
  82. u32 __pad3;
  83. u64 __par4[2];
  84. };
  85. struct vio_dring_hdr {
  86. u8 state;
  87. #define VIO_DESC_FREE 0x01
  88. #define VIO_DESC_READY 0x02
  89. #define VIO_DESC_ACCEPTED 0x03
  90. #define VIO_DESC_DONE 0x04
  91. u8 ack;
  92. #define VIO_ACK_ENABLE 0x01
  93. #define VIO_ACK_DISABLE 0x00
  94. u16 __pad1;
  95. u32 __pad2;
  96. };
  97. /* VIO disk specific structures and defines */
  98. struct vio_disk_attr_info {
  99. struct vio_msg_tag tag;
  100. u8 xfer_mode;
  101. u8 vdisk_type;
  102. #define VD_DISK_TYPE_SLICE 0x01 /* Slice in block device */
  103. #define VD_DISK_TYPE_DISK 0x02 /* Entire block device */
  104. u16 resv1;
  105. u32 vdisk_block_size;
  106. u64 operations;
  107. u64 vdisk_size;
  108. u64 max_xfer_size;
  109. u64 resv2[2];
  110. };
  111. struct vio_disk_desc {
  112. struct vio_dring_hdr hdr;
  113. u64 req_id;
  114. u8 operation;
  115. #define VD_OP_BREAD 0x01 /* Block read */
  116. #define VD_OP_BWRITE 0x02 /* Block write */
  117. #define VD_OP_FLUSH 0x03 /* Flush disk contents */
  118. #define VD_OP_GET_WCE 0x04 /* Get write-cache status */
  119. #define VD_OP_SET_WCE 0x05 /* Enable/disable write-cache */
  120. #define VD_OP_GET_VTOC 0x06 /* Get VTOC */
  121. #define VD_OP_SET_VTOC 0x07 /* Set VTOC */
  122. #define VD_OP_GET_DISKGEOM 0x08 /* Get disk geometry */
  123. #define VD_OP_SET_DISKGEOM 0x09 /* Set disk geometry */
  124. #define VD_OP_SCSICMD 0x0a /* SCSI control command */
  125. #define VD_OP_GET_DEVID 0x0b /* Get device ID */
  126. #define VD_OP_GET_EFI 0x0c /* Get EFI */
  127. #define VD_OP_SET_EFI 0x0d /* Set EFI */
  128. u8 slice;
  129. u16 resv1;
  130. u32 status;
  131. u64 offset;
  132. u64 size;
  133. u32 ncookies;
  134. u32 resv2;
  135. struct ldc_trans_cookie cookies[0];
  136. };
  137. #define VIO_DISK_VNAME_LEN 8
  138. #define VIO_DISK_ALABEL_LEN 128
  139. #define VIO_DISK_NUM_PART 8
  140. struct vio_disk_vtoc {
  141. u8 volume_name[VIO_DISK_VNAME_LEN];
  142. u16 sector_size;
  143. u16 num_partitions;
  144. u8 ascii_label[VIO_DISK_ALABEL_LEN];
  145. struct {
  146. u16 id;
  147. u16 perm_flags;
  148. u32 resv;
  149. u64 start_block;
  150. u64 num_blocks;
  151. } partitions[VIO_DISK_NUM_PART];
  152. };
  153. struct vio_disk_geom {
  154. u16 num_cyl; /* Num data cylinders */
  155. u16 alt_cyl; /* Num alternate cylinders */
  156. u16 beg_cyl; /* Cyl off of fixed head area */
  157. u16 num_hd; /* Num heads */
  158. u16 num_sec; /* Num sectors */
  159. u16 ifact; /* Interleave factor */
  160. u16 apc; /* Alts per cylinder (SCSI) */
  161. u16 rpm; /* Revolutions per minute */
  162. u16 phy_cyl; /* Num physical cylinders */
  163. u16 wr_skip; /* Num sects to skip, writes */
  164. u16 rd_skip; /* Num sects to skip, writes */
  165. };
  166. struct vio_disk_devid {
  167. u16 resv;
  168. u16 type;
  169. u32 len;
  170. char id[0];
  171. };
  172. struct vio_disk_efi {
  173. u64 lba;
  174. u64 len;
  175. char data[0];
  176. };
  177. /* VIO net specific structures and defines */
  178. struct vio_net_attr_info {
  179. struct vio_msg_tag tag;
  180. u8 xfer_mode;
  181. u8 addr_type;
  182. #define VNET_ADDR_ETHERMAC 0x01
  183. u16 ack_freq;
  184. u32 resv1;
  185. u64 addr;
  186. u64 mtu;
  187. u64 resv2[3];
  188. };
  189. #define VNET_NUM_MCAST 7
  190. struct vio_net_mcast_info {
  191. struct vio_msg_tag tag;
  192. u8 set;
  193. u8 count;
  194. u8 mcast_addr[VNET_NUM_MCAST * 6];
  195. u32 resv;
  196. };
  197. struct vio_net_desc {
  198. struct vio_dring_hdr hdr;
  199. u32 size;
  200. u32 ncookies;
  201. struct ldc_trans_cookie cookies[0];
  202. };
  203. #define VIO_MAX_RING_COOKIES 24
  204. struct vio_dring_state {
  205. u64 ident;
  206. void *base;
  207. u64 snd_nxt;
  208. u64 rcv_nxt;
  209. u32 entry_size;
  210. u32 num_entries;
  211. u32 prod;
  212. u32 cons;
  213. u32 pending;
  214. int ncookies;
  215. struct ldc_trans_cookie cookies[VIO_MAX_RING_COOKIES];
  216. };
  217. static inline void *vio_dring_cur(struct vio_dring_state *dr)
  218. {
  219. return dr->base + (dr->entry_size * dr->prod);
  220. }
  221. static inline void *vio_dring_entry(struct vio_dring_state *dr,
  222. unsigned int index)
  223. {
  224. return dr->base + (dr->entry_size * index);
  225. }
  226. static inline u32 vio_dring_avail(struct vio_dring_state *dr,
  227. unsigned int ring_size)
  228. {
  229. BUILD_BUG_ON(!is_power_of_2(ring_size));
  230. return (dr->pending -
  231. ((dr->prod - dr->cons) & (ring_size - 1)));
  232. }
  233. #define VIO_MAX_TYPE_LEN 32
  234. #define VIO_MAX_COMPAT_LEN 64
  235. struct vio_dev {
  236. u64 mp;
  237. struct device_node *dp;
  238. char type[VIO_MAX_TYPE_LEN];
  239. char compat[VIO_MAX_COMPAT_LEN];
  240. int compat_len;
  241. u64 dev_no;
  242. unsigned long channel_id;
  243. unsigned int tx_irq;
  244. unsigned int rx_irq;
  245. struct device dev;
  246. };
  247. struct vio_driver {
  248. struct list_head node;
  249. const struct vio_device_id *id_table;
  250. int (*probe)(struct vio_dev *dev, const struct vio_device_id *id);
  251. int (*remove)(struct vio_dev *dev);
  252. void (*shutdown)(struct vio_dev *dev);
  253. unsigned long driver_data;
  254. struct device_driver driver;
  255. };
  256. struct vio_version {
  257. u16 major;
  258. u16 minor;
  259. };
  260. struct vio_driver_state;
  261. struct vio_driver_ops {
  262. int (*send_attr)(struct vio_driver_state *vio);
  263. int (*handle_attr)(struct vio_driver_state *vio, void *pkt);
  264. void (*handshake_complete)(struct vio_driver_state *vio);
  265. };
  266. struct vio_completion {
  267. struct completion com;
  268. int err;
  269. int waiting_for;
  270. };
  271. struct vio_driver_state {
  272. /* Protects VIO handshake and, optionally, driver private state. */
  273. spinlock_t lock;
  274. struct ldc_channel *lp;
  275. u32 _peer_sid;
  276. u32 _local_sid;
  277. struct vio_dring_state drings[2];
  278. #define VIO_DRIVER_TX_RING 0
  279. #define VIO_DRIVER_RX_RING 1
  280. u8 hs_state;
  281. #define VIO_HS_INVALID 0x00
  282. #define VIO_HS_GOTVERS 0x01
  283. #define VIO_HS_GOT_ATTR 0x04
  284. #define VIO_HS_SENT_DREG 0x08
  285. #define VIO_HS_SENT_RDX 0x10
  286. #define VIO_HS_GOT_RDX_ACK 0x20
  287. #define VIO_HS_GOT_RDX 0x40
  288. #define VIO_HS_SENT_RDX_ACK 0x80
  289. #define VIO_HS_COMPLETE (VIO_HS_GOT_RDX_ACK | VIO_HS_SENT_RDX_ACK)
  290. u8 dev_class;
  291. u8 dr_state;
  292. #define VIO_DR_STATE_TXREG 0x01
  293. #define VIO_DR_STATE_RXREG 0x02
  294. #define VIO_DR_STATE_TXREQ 0x10
  295. #define VIO_DR_STATE_RXREQ 0x20
  296. u8 debug;
  297. #define VIO_DEBUG_HS 0x01
  298. #define VIO_DEBUG_DATA 0x02
  299. void *desc_buf;
  300. unsigned int desc_buf_len;
  301. struct vio_completion *cmp;
  302. struct vio_dev *vdev;
  303. struct timer_list timer;
  304. struct vio_version ver;
  305. struct vio_version *ver_table;
  306. int ver_table_entries;
  307. char *name;
  308. struct vio_driver_ops *ops;
  309. };
  310. #define viodbg(TYPE, f, a...) \
  311. do { if (vio->debug & VIO_DEBUG_##TYPE) \
  312. printk(KERN_INFO "vio: ID[%lu] " f, \
  313. vio->vdev->channel_id, ## a); \
  314. } while (0)
  315. extern int vio_register_driver(struct vio_driver *drv);
  316. extern void vio_unregister_driver(struct vio_driver *drv);
  317. static inline struct vio_driver *to_vio_driver(struct device_driver *drv)
  318. {
  319. return container_of(drv, struct vio_driver, driver);
  320. }
  321. static inline struct vio_dev *to_vio_dev(struct device *dev)
  322. {
  323. return container_of(dev, struct vio_dev, dev);
  324. }
  325. extern int vio_ldc_send(struct vio_driver_state *vio, void *data, int len);
  326. extern void vio_link_state_change(struct vio_driver_state *vio, int event);
  327. extern void vio_conn_reset(struct vio_driver_state *vio);
  328. extern int vio_control_pkt_engine(struct vio_driver_state *vio, void *pkt);
  329. extern int vio_validate_sid(struct vio_driver_state *vio,
  330. struct vio_msg_tag *tp);
  331. extern u32 vio_send_sid(struct vio_driver_state *vio);
  332. extern int vio_ldc_alloc(struct vio_driver_state *vio,
  333. struct ldc_channel_config *base_cfg, void *event_arg);
  334. extern void vio_ldc_free(struct vio_driver_state *vio);
  335. extern int vio_driver_init(struct vio_driver_state *vio, struct vio_dev *vdev,
  336. u8 dev_class, struct vio_version *ver_table,
  337. int ver_table_size, struct vio_driver_ops *ops,
  338. char *name);
  339. extern void vio_port_up(struct vio_driver_state *vio);
  340. #endif /* _SPARC64_VIO_H */