lcs.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*lcs.h*/
  3. #include <linux/interrupt.h>
  4. #include <linux/netdevice.h>
  5. #include <linux/skbuff.h>
  6. #include <linux/workqueue.h>
  7. #include <asm/ccwdev.h>
  8. #define LCS_DBF_TEXT(level, name, text) \
  9. do { \
  10. debug_text_event(lcs_dbf_##name, level, text); \
  11. } while (0)
  12. #define LCS_DBF_HEX(level,name,addr,len) \
  13. do { \
  14. debug_event(lcs_dbf_##name,level,(void*)(addr),len); \
  15. } while (0)
  16. #define LCS_DBF_TEXT_(level,name,text...) \
  17. do { \
  18. if (debug_level_enabled(lcs_dbf_##name, level)) { \
  19. sprintf(debug_buffer, text); \
  20. debug_text_event(lcs_dbf_##name, level, debug_buffer); \
  21. } \
  22. } while (0)
  23. /**
  24. * sysfs related stuff
  25. */
  26. #define CARD_FROM_DEV(cdev) \
  27. (struct lcs_card *) dev_get_drvdata( \
  28. &((struct ccwgroup_device *)dev_get_drvdata(&cdev->dev))->dev);
  29. /**
  30. * Enum for classifying detected devices.
  31. */
  32. enum lcs_channel_types {
  33. /* Device is not a channel */
  34. lcs_channel_type_none,
  35. /* Device is a 2216 channel */
  36. lcs_channel_type_parallel,
  37. /* Device is a 2216 channel */
  38. lcs_channel_type_2216,
  39. /* Device is a OSA2 card */
  40. lcs_channel_type_osa2
  41. };
  42. /**
  43. * CCW commands used in this driver
  44. */
  45. #define LCS_CCW_WRITE 0x01
  46. #define LCS_CCW_READ 0x02
  47. #define LCS_CCW_TRANSFER 0x08
  48. /**
  49. * LCS device status primitives
  50. */
  51. #define LCS_CMD_STARTLAN 0x01
  52. #define LCS_CMD_STOPLAN 0x02
  53. #define LCS_CMD_LANSTAT 0x04
  54. #define LCS_CMD_STARTUP 0x07
  55. #define LCS_CMD_SHUTDOWN 0x08
  56. #define LCS_CMD_QIPASSIST 0xb2
  57. #define LCS_CMD_SETIPM 0xb4
  58. #define LCS_CMD_DELIPM 0xb5
  59. #define LCS_INITIATOR_TCPIP 0x00
  60. #define LCS_INITIATOR_LGW 0x01
  61. #define LCS_STD_CMD_SIZE 16
  62. #define LCS_MULTICAST_CMD_SIZE 404
  63. /**
  64. * LCS IPASSIST MASKS,only used when multicast is switched on
  65. */
  66. /* Not supported by LCS */
  67. #define LCS_IPASS_ARP_PROCESSING 0x0001
  68. #define LCS_IPASS_IN_CHECKSUM_SUPPORT 0x0002
  69. #define LCS_IPASS_OUT_CHECKSUM_SUPPORT 0x0004
  70. #define LCS_IPASS_IP_FRAG_REASSEMBLY 0x0008
  71. #define LCS_IPASS_IP_FILTERING 0x0010
  72. /* Supported by lcs 3172 */
  73. #define LCS_IPASS_IPV6_SUPPORT 0x0020
  74. #define LCS_IPASS_MULTICAST_SUPPORT 0x0040
  75. /**
  76. * LCS sense byte definitions
  77. */
  78. #define LCS_SENSE_BYTE_0 0
  79. #define LCS_SENSE_BYTE_1 1
  80. #define LCS_SENSE_BYTE_2 2
  81. #define LCS_SENSE_BYTE_3 3
  82. #define LCS_SENSE_INTERFACE_DISCONNECT 0x01
  83. #define LCS_SENSE_EQUIPMENT_CHECK 0x10
  84. #define LCS_SENSE_BUS_OUT_CHECK 0x20
  85. #define LCS_SENSE_INTERVENTION_REQUIRED 0x40
  86. #define LCS_SENSE_CMD_REJECT 0x80
  87. #define LCS_SENSE_RESETTING_EVENT 0x80
  88. #define LCS_SENSE_DEVICE_ONLINE 0x20
  89. /**
  90. * LCS packet type definitions
  91. */
  92. #define LCS_FRAME_TYPE_CONTROL 0
  93. #define LCS_FRAME_TYPE_ENET 1
  94. #define LCS_FRAME_TYPE_TR 2
  95. #define LCS_FRAME_TYPE_FDDI 7
  96. #define LCS_FRAME_TYPE_AUTO -1
  97. /**
  98. * some more definitions,we will sort them later
  99. */
  100. #define LCS_ILLEGAL_OFFSET 0xffff
  101. #define LCS_IOBUFFERSIZE 0x5000
  102. #define LCS_NUM_BUFFS 32 /* needs to be power of 2 */
  103. #define LCS_MAC_LENGTH 6
  104. #define LCS_INVALID_PORT_NO -1
  105. #define LCS_LANCMD_TIMEOUT_DEFAULT 5
  106. /**
  107. * Multicast state
  108. */
  109. #define LCS_IPM_STATE_SET_REQUIRED 0
  110. #define LCS_IPM_STATE_DEL_REQUIRED 1
  111. #define LCS_IPM_STATE_ON_CARD 2
  112. /**
  113. * LCS IP Assist declarations
  114. * seems to be only used for multicast
  115. */
  116. #define LCS_IPASS_ARP_PROCESSING 0x0001
  117. #define LCS_IPASS_INBOUND_CSUM_SUPP 0x0002
  118. #define LCS_IPASS_OUTBOUND_CSUM_SUPP 0x0004
  119. #define LCS_IPASS_IP_FRAG_REASSEMBLY 0x0008
  120. #define LCS_IPASS_IP_FILTERING 0x0010
  121. #define LCS_IPASS_IPV6_SUPPORT 0x0020
  122. #define LCS_IPASS_MULTICAST_SUPPORT 0x0040
  123. /**
  124. * LCS Buffer states
  125. */
  126. enum lcs_buffer_states {
  127. LCS_BUF_STATE_EMPTY, /* buffer is empty */
  128. LCS_BUF_STATE_LOCKED, /* buffer is locked, don't touch */
  129. LCS_BUF_STATE_READY, /* buffer is ready for read/write */
  130. LCS_BUF_STATE_PROCESSED,
  131. };
  132. /**
  133. * LCS Channel State Machine declarations
  134. */
  135. enum lcs_channel_states {
  136. LCS_CH_STATE_INIT,
  137. LCS_CH_STATE_HALTED,
  138. LCS_CH_STATE_STOPPED,
  139. LCS_CH_STATE_RUNNING,
  140. LCS_CH_STATE_SUSPENDED,
  141. LCS_CH_STATE_CLEARED,
  142. LCS_CH_STATE_ERROR,
  143. };
  144. /**
  145. * LCS device state machine
  146. */
  147. enum lcs_dev_states {
  148. DEV_STATE_DOWN,
  149. DEV_STATE_UP,
  150. DEV_STATE_RECOVER,
  151. };
  152. enum lcs_threads {
  153. LCS_SET_MC_THREAD = 1,
  154. LCS_RECOVERY_THREAD = 2,
  155. };
  156. /**
  157. * LCS struct declarations
  158. */
  159. struct lcs_header {
  160. __u16 offset;
  161. __u8 type;
  162. __u8 slot;
  163. } __attribute__ ((packed));
  164. struct lcs_ip_mac_pair {
  165. __be32 ip_addr;
  166. __u8 mac_addr[LCS_MAC_LENGTH];
  167. __u8 reserved[2];
  168. } __attribute__ ((packed));
  169. struct lcs_ipm_list {
  170. struct list_head list;
  171. struct lcs_ip_mac_pair ipm;
  172. __u8 ipm_state;
  173. };
  174. struct lcs_cmd {
  175. __u16 offset;
  176. __u8 type;
  177. __u8 slot;
  178. __u8 cmd_code;
  179. __u8 initiator;
  180. __u16 sequence_no;
  181. __u16 return_code;
  182. union {
  183. struct {
  184. __u8 lan_type;
  185. __u8 portno;
  186. __u16 parameter_count;
  187. __u8 operator_flags[3];
  188. __u8 reserved[3];
  189. } lcs_std_cmd;
  190. struct {
  191. __u16 unused1;
  192. __u16 buff_size;
  193. __u8 unused2[6];
  194. } lcs_startup;
  195. struct {
  196. __u8 lan_type;
  197. __u8 portno;
  198. __u8 unused[10];
  199. __u8 mac_addr[LCS_MAC_LENGTH];
  200. __u32 num_packets_deblocked;
  201. __u32 num_packets_blocked;
  202. __u32 num_packets_tx_on_lan;
  203. __u32 num_tx_errors_detected;
  204. __u32 num_tx_packets_disgarded;
  205. __u32 num_packets_rx_from_lan;
  206. __u32 num_rx_errors_detected;
  207. __u32 num_rx_discarded_nobuffs_avail;
  208. __u32 num_rx_packets_too_large;
  209. } lcs_lanstat_cmd;
  210. #ifdef CONFIG_IP_MULTICAST
  211. struct {
  212. __u8 lan_type;
  213. __u8 portno;
  214. __u16 num_ip_pairs;
  215. __u16 ip_assists_supported;
  216. __u16 ip_assists_enabled;
  217. __u16 version;
  218. struct {
  219. struct lcs_ip_mac_pair
  220. ip_mac_pair[32];
  221. __u32 response_data;
  222. } lcs_ipass_ctlmsg __attribute ((packed));
  223. } lcs_qipassist __attribute__ ((packed));
  224. #endif /*CONFIG_IP_MULTICAST */
  225. } cmd __attribute__ ((packed));
  226. } __attribute__ ((packed));
  227. /**
  228. * Forward declarations.
  229. */
  230. struct lcs_card;
  231. struct lcs_channel;
  232. /**
  233. * Definition of an lcs buffer.
  234. */
  235. struct lcs_buffer {
  236. enum lcs_buffer_states state;
  237. void *data;
  238. int count;
  239. /* Callback for completion notification. */
  240. void (*callback)(struct lcs_channel *, struct lcs_buffer *);
  241. };
  242. struct lcs_reply {
  243. struct list_head list;
  244. __u16 sequence_no;
  245. atomic_t refcnt;
  246. /* Callback for completion notification. */
  247. void (*callback)(struct lcs_card *, struct lcs_cmd *);
  248. wait_queue_head_t wait_q;
  249. struct lcs_card *card;
  250. int received;
  251. int rc;
  252. };
  253. /**
  254. * Definition of an lcs channel
  255. */
  256. struct lcs_channel {
  257. enum lcs_channel_states state;
  258. struct ccw_device *ccwdev;
  259. struct ccw1 ccws[LCS_NUM_BUFFS + 1];
  260. wait_queue_head_t wait_q;
  261. struct tasklet_struct irq_tasklet;
  262. struct lcs_buffer iob[LCS_NUM_BUFFS];
  263. int io_idx;
  264. int buf_idx;
  265. };
  266. /**
  267. * definition of the lcs card
  268. */
  269. struct lcs_card {
  270. spinlock_t lock;
  271. spinlock_t ipm_lock;
  272. enum lcs_dev_states state;
  273. struct net_device *dev;
  274. struct net_device_stats stats;
  275. __be16 (*lan_type_trans)(struct sk_buff *skb,
  276. struct net_device *dev);
  277. struct ccwgroup_device *gdev;
  278. struct lcs_channel read;
  279. struct lcs_channel write;
  280. struct lcs_buffer *tx_buffer;
  281. int tx_emitted;
  282. struct list_head lancmd_waiters;
  283. int lancmd_timeout;
  284. struct work_struct kernel_thread_starter;
  285. spinlock_t mask_lock;
  286. unsigned long thread_start_mask;
  287. unsigned long thread_running_mask;
  288. unsigned long thread_allowed_mask;
  289. wait_queue_head_t wait_q;
  290. #ifdef CONFIG_IP_MULTICAST
  291. struct list_head ipm_list;
  292. #endif
  293. __u8 mac[LCS_MAC_LENGTH];
  294. __u16 ip_assists_supported;
  295. __u16 ip_assists_enabled;
  296. __s8 lan_type;
  297. __u32 pkt_seq;
  298. __u16 sequence_no;
  299. __s16 portno;
  300. /* Some info copied from probeinfo */
  301. u8 device_forced;
  302. u8 max_port_no;
  303. u8 hint_port_no;
  304. s16 port_protocol_no;
  305. } __attribute__ ((aligned(8)));