vio.h 10 KB

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