lcs.h 7.1 KB

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