vio.h 12 KB

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