vio.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  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. struct vio_net_dext {
  223. u8 flags;
  224. #define VNET_PKT_HASH 0x01
  225. #define VNET_PKT_HCK_IPV4_HDRCKSUM 0x02
  226. #define VNET_PKT_HCK_FULLCKSUM 0x04
  227. #define VNET_PKT_IPV4_LSO 0x08
  228. #define VNET_PKT_HCK_IPV4_HDRCKSUM_OK 0x10
  229. #define VNET_PKT_HCK_FULLCKSUM_OK 0x20
  230. u8 vnet_hashval;
  231. u16 ipv4_lso_mss;
  232. u32 resv3;
  233. };
  234. static inline struct vio_net_dext *vio_net_ext(struct vio_net_desc *desc)
  235. {
  236. return (struct vio_net_dext *)&desc->cookies[2];
  237. }
  238. #define VIO_MAX_RING_COOKIES 24
  239. struct vio_dring_state {
  240. u64 ident;
  241. void *base;
  242. u64 snd_nxt;
  243. u64 rcv_nxt;
  244. u32 entry_size;
  245. u32 num_entries;
  246. u32 prod;
  247. u32 cons;
  248. u32 pending;
  249. int ncookies;
  250. struct ldc_trans_cookie cookies[VIO_MAX_RING_COOKIES];
  251. };
  252. static inline void *vio_dring_cur(struct vio_dring_state *dr)
  253. {
  254. return dr->base + (dr->entry_size * dr->prod);
  255. }
  256. static inline void *vio_dring_entry(struct vio_dring_state *dr,
  257. unsigned int index)
  258. {
  259. return dr->base + (dr->entry_size * index);
  260. }
  261. static inline u32 vio_dring_avail(struct vio_dring_state *dr,
  262. unsigned int ring_size)
  263. {
  264. return (dr->pending -
  265. ((dr->prod - dr->cons) & (ring_size - 1)) - 1);
  266. }
  267. static inline u32 vio_dring_next(struct vio_dring_state *dr, u32 index)
  268. {
  269. if (++index == dr->num_entries)
  270. index = 0;
  271. return index;
  272. }
  273. static inline u32 vio_dring_prev(struct vio_dring_state *dr, u32 index)
  274. {
  275. if (index == 0)
  276. return dr->num_entries - 1;
  277. else
  278. return index - 1;
  279. }
  280. #define VIO_MAX_TYPE_LEN 32
  281. #define VIO_MAX_COMPAT_LEN 64
  282. struct vio_dev {
  283. u64 mp;
  284. struct device_node *dp;
  285. char type[VIO_MAX_TYPE_LEN];
  286. char compat[VIO_MAX_COMPAT_LEN];
  287. int compat_len;
  288. u64 dev_no;
  289. u64 id;
  290. unsigned long channel_id;
  291. unsigned int tx_irq;
  292. unsigned int rx_irq;
  293. u64 rx_ino;
  294. struct device dev;
  295. };
  296. struct vio_driver {
  297. const char *name;
  298. struct list_head node;
  299. const struct vio_device_id *id_table;
  300. int (*probe)(struct vio_dev *dev, const struct vio_device_id *id);
  301. int (*remove)(struct vio_dev *dev);
  302. void (*shutdown)(struct vio_dev *dev);
  303. unsigned long driver_data;
  304. struct device_driver driver;
  305. };
  306. struct vio_version {
  307. u16 major;
  308. u16 minor;
  309. };
  310. struct vio_driver_state;
  311. struct vio_driver_ops {
  312. int (*send_attr)(struct vio_driver_state *vio);
  313. int (*handle_attr)(struct vio_driver_state *vio, void *pkt);
  314. void (*handshake_complete)(struct vio_driver_state *vio);
  315. };
  316. struct vio_completion {
  317. struct completion com;
  318. int err;
  319. int waiting_for;
  320. };
  321. struct vio_driver_state {
  322. /* Protects VIO handshake and, optionally, driver private state. */
  323. spinlock_t lock;
  324. struct ldc_channel *lp;
  325. u32 _peer_sid;
  326. u32 _local_sid;
  327. struct vio_dring_state drings[2];
  328. #define VIO_DRIVER_TX_RING 0
  329. #define VIO_DRIVER_RX_RING 1
  330. u8 hs_state;
  331. #define VIO_HS_INVALID 0x00
  332. #define VIO_HS_GOTVERS 0x01
  333. #define VIO_HS_GOT_ATTR 0x04
  334. #define VIO_HS_SENT_DREG 0x08
  335. #define VIO_HS_SENT_RDX 0x10
  336. #define VIO_HS_GOT_RDX_ACK 0x20
  337. #define VIO_HS_GOT_RDX 0x40
  338. #define VIO_HS_SENT_RDX_ACK 0x80
  339. #define VIO_HS_COMPLETE (VIO_HS_GOT_RDX_ACK | VIO_HS_SENT_RDX_ACK)
  340. u8 dev_class;
  341. u8 dr_state;
  342. #define VIO_DR_STATE_TXREG 0x01
  343. #define VIO_DR_STATE_RXREG 0x02
  344. #define VIO_DR_STATE_TXREQ 0x10
  345. #define VIO_DR_STATE_RXREQ 0x20
  346. u8 debug;
  347. #define VIO_DEBUG_HS 0x01
  348. #define VIO_DEBUG_DATA 0x02
  349. void *desc_buf;
  350. unsigned int desc_buf_len;
  351. struct vio_completion *cmp;
  352. struct vio_dev *vdev;
  353. struct timer_list timer;
  354. struct vio_version ver;
  355. struct vio_version *ver_table;
  356. int ver_table_entries;
  357. char *name;
  358. struct vio_driver_ops *ops;
  359. };
  360. static inline bool vio_version_before(struct vio_driver_state *vio,
  361. u16 major, u16 minor)
  362. {
  363. u32 have = (u32)vio->ver.major << 16 | vio->ver.minor;
  364. u32 want = (u32)major << 16 | minor;
  365. return have < want;
  366. }
  367. static inline bool vio_version_after(struct vio_driver_state *vio,
  368. u16 major, u16 minor)
  369. {
  370. u32 have = (u32)vio->ver.major << 16 | vio->ver.minor;
  371. u32 want = (u32)major << 16 | minor;
  372. return have > want;
  373. }
  374. static inline bool vio_version_after_eq(struct vio_driver_state *vio,
  375. u16 major, u16 minor)
  376. {
  377. u32 have = (u32)vio->ver.major << 16 | vio->ver.minor;
  378. u32 want = (u32)major << 16 | minor;
  379. return have >= want;
  380. }
  381. #define viodbg(TYPE, f, a...) \
  382. do { if (vio->debug & VIO_DEBUG_##TYPE) \
  383. printk(KERN_INFO "vio: ID[%lu] " f, \
  384. vio->vdev->channel_id, ## a); \
  385. } while (0)
  386. int __vio_register_driver(struct vio_driver *drv, struct module *owner,
  387. const char *mod_name);
  388. /*
  389. * vio_register_driver must be a macro so that KBUILD_MODNAME can be expanded
  390. */
  391. #define vio_register_driver(driver) \
  392. __vio_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
  393. void vio_unregister_driver(struct vio_driver *drv);
  394. static inline struct vio_driver *to_vio_driver(struct device_driver *drv)
  395. {
  396. return container_of(drv, struct vio_driver, driver);
  397. }
  398. static inline struct vio_dev *to_vio_dev(struct device *dev)
  399. {
  400. return container_of(dev, struct vio_dev, dev);
  401. }
  402. int vio_ldc_send(struct vio_driver_state *vio, void *data, int len);
  403. void vio_link_state_change(struct vio_driver_state *vio, int event);
  404. void vio_conn_reset(struct vio_driver_state *vio);
  405. int vio_control_pkt_engine(struct vio_driver_state *vio, void *pkt);
  406. int vio_validate_sid(struct vio_driver_state *vio,
  407. struct vio_msg_tag *tp);
  408. u32 vio_send_sid(struct vio_driver_state *vio);
  409. int vio_ldc_alloc(struct vio_driver_state *vio,
  410. struct ldc_channel_config *base_cfg, void *event_arg);
  411. void vio_ldc_free(struct vio_driver_state *vio);
  412. int vio_driver_init(struct vio_driver_state *vio, struct vio_dev *vdev,
  413. u8 dev_class, struct vio_version *ver_table,
  414. int ver_table_size, struct vio_driver_ops *ops,
  415. char *name);
  416. void vio_port_up(struct vio_driver_state *vio);
  417. int vio_set_intr(unsigned long dev_ino, int state);
  418. #endif /* _SPARC64_VIO_H */