lcs.h 7.6 KB

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