lcs.h 7.5 KB

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