Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*lcs.h*/
0003 
0004 #include <linux/interrupt.h>
0005 #include <linux/netdevice.h>
0006 #include <linux/skbuff.h>
0007 #include <linux/workqueue.h>
0008 #include <linux/refcount.h>
0009 #include <asm/ccwdev.h>
0010 
0011 #define LCS_DBF_TEXT(level, name, text) \
0012     do { \
0013         debug_text_event(lcs_dbf_##name, level, text); \
0014     } while (0)
0015 
0016 #define LCS_DBF_HEX(level,name,addr,len) \
0017 do { \
0018     debug_event(lcs_dbf_##name,level,(void*)(addr),len); \
0019 } while (0)
0020 
0021 #define LCS_DBF_TEXT_(level,name,text...) \
0022     do { \
0023         if (debug_level_enabled(lcs_dbf_##name, level)) { \
0024             sprintf(debug_buffer, text); \
0025             debug_text_event(lcs_dbf_##name, level, debug_buffer); \
0026         } \
0027     } while (0)
0028 
0029 /**
0030  *  sysfs related stuff
0031  */
0032 #define CARD_FROM_DEV(cdev) \
0033     (struct lcs_card *) dev_get_drvdata( \
0034         &((struct ccwgroup_device *)dev_get_drvdata(&cdev->dev))->dev);
0035 
0036 /**
0037  * Enum for classifying detected devices.
0038  */
0039 enum lcs_channel_types {
0040     /* Device is not a channel  */
0041     lcs_channel_type_none,
0042 
0043     /* Device is a 2216 channel */
0044     lcs_channel_type_parallel,
0045 
0046     /* Device is a 2216 channel */
0047     lcs_channel_type_2216,
0048 
0049     /* Device is a OSA2 card */
0050     lcs_channel_type_osa2
0051 };
0052 
0053 /**
0054  * CCW commands used in this driver
0055  */
0056 #define LCS_CCW_WRITE       0x01
0057 #define LCS_CCW_READ        0x02
0058 #define LCS_CCW_TRANSFER    0x08
0059 
0060 /**
0061  * LCS device status primitives
0062  */
0063 #define LCS_CMD_STARTLAN    0x01
0064 #define LCS_CMD_STOPLAN     0x02
0065 #define LCS_CMD_LANSTAT     0x04
0066 #define LCS_CMD_STARTUP     0x07
0067 #define LCS_CMD_SHUTDOWN    0x08
0068 #define LCS_CMD_QIPASSIST   0xb2
0069 #define LCS_CMD_SETIPM      0xb4
0070 #define LCS_CMD_DELIPM      0xb5
0071 
0072 #define LCS_INITIATOR_TCPIP 0x00
0073 #define LCS_INITIATOR_LGW   0x01
0074 #define LCS_STD_CMD_SIZE    16
0075 #define LCS_MULTICAST_CMD_SIZE  404
0076 
0077 /**
0078  * LCS IPASSIST MASKS,only used when multicast is switched on
0079  */
0080 /* Not supported by LCS */
0081 #define LCS_IPASS_ARP_PROCESSING    0x0001
0082 #define LCS_IPASS_IN_CHECKSUM_SUPPORT   0x0002
0083 #define LCS_IPASS_OUT_CHECKSUM_SUPPORT  0x0004
0084 #define LCS_IPASS_IP_FRAG_REASSEMBLY    0x0008
0085 #define LCS_IPASS_IP_FILTERING      0x0010
0086 /* Supported by lcs 3172 */
0087 #define LCS_IPASS_IPV6_SUPPORT      0x0020
0088 #define LCS_IPASS_MULTICAST_SUPPORT 0x0040
0089 
0090 /**
0091  * LCS sense byte definitions
0092  */
0093 #define LCS_SENSE_BYTE_0        0
0094 #define LCS_SENSE_BYTE_1        1
0095 #define LCS_SENSE_BYTE_2        2
0096 #define LCS_SENSE_BYTE_3        3
0097 #define LCS_SENSE_INTERFACE_DISCONNECT  0x01
0098 #define LCS_SENSE_EQUIPMENT_CHECK   0x10
0099 #define LCS_SENSE_BUS_OUT_CHECK     0x20
0100 #define LCS_SENSE_INTERVENTION_REQUIRED 0x40
0101 #define LCS_SENSE_CMD_REJECT        0x80
0102 #define LCS_SENSE_RESETTING_EVENT   0x80
0103 #define LCS_SENSE_DEVICE_ONLINE     0x20
0104 
0105 /**
0106  * LCS packet type definitions
0107  */
0108 #define LCS_FRAME_TYPE_CONTROL      0
0109 #define LCS_FRAME_TYPE_ENET     1
0110 #define LCS_FRAME_TYPE_TR       2
0111 #define LCS_FRAME_TYPE_FDDI     7
0112 #define LCS_FRAME_TYPE_AUTO     -1
0113 
0114 /**
0115  * some more definitions,we will sort them later
0116  */
0117 #define LCS_ILLEGAL_OFFSET      0xffff
0118 #define LCS_IOBUFFERSIZE        0x5000
0119 #define LCS_NUM_BUFFS           32  /* needs to be power of 2 */
0120 #define LCS_MAC_LENGTH          6
0121 #define LCS_INVALID_PORT_NO     -1
0122 #define LCS_LANCMD_TIMEOUT_DEFAULT      5
0123 
0124 /**
0125  * Multicast state
0126  */
0127 #define  LCS_IPM_STATE_SET_REQUIRED 0
0128 #define  LCS_IPM_STATE_DEL_REQUIRED 1
0129 #define  LCS_IPM_STATE_ON_CARD      2
0130 
0131 /**
0132  * LCS IP Assist declarations
0133  * seems to be only used for multicast
0134  */
0135 #define  LCS_IPASS_ARP_PROCESSING   0x0001
0136 #define  LCS_IPASS_INBOUND_CSUM_SUPP    0x0002
0137 #define  LCS_IPASS_OUTBOUND_CSUM_SUPP   0x0004
0138 #define  LCS_IPASS_IP_FRAG_REASSEMBLY   0x0008
0139 #define  LCS_IPASS_IP_FILTERING     0x0010
0140 #define  LCS_IPASS_IPV6_SUPPORT     0x0020
0141 #define  LCS_IPASS_MULTICAST_SUPPORT    0x0040
0142 
0143 /**
0144  * LCS Buffer states
0145  */
0146 enum lcs_buffer_states {
0147     LCS_BUF_STATE_EMPTY,    /* buffer is empty */
0148     LCS_BUF_STATE_LOCKED,   /* buffer is locked, don't touch */
0149     LCS_BUF_STATE_READY,    /* buffer is ready for read/write */
0150     LCS_BUF_STATE_PROCESSED,
0151 };
0152 
0153 /**
0154  * LCS Channel State Machine declarations
0155  */
0156 enum lcs_channel_states {
0157     LCS_CH_STATE_INIT,
0158     LCS_CH_STATE_HALTED,
0159     LCS_CH_STATE_STOPPED,
0160     LCS_CH_STATE_RUNNING,
0161     LCS_CH_STATE_SUSPENDED,
0162     LCS_CH_STATE_CLEARED,
0163     LCS_CH_STATE_ERROR,
0164 };
0165 
0166 /**
0167  * LCS device state machine
0168  */
0169 enum lcs_dev_states {
0170     DEV_STATE_DOWN,
0171     DEV_STATE_UP,
0172     DEV_STATE_RECOVER,
0173 };
0174 
0175 enum lcs_threads {
0176     LCS_SET_MC_THREAD   = 1,
0177     LCS_RECOVERY_THREAD     = 2,
0178 };
0179 
0180 /**
0181  * LCS struct declarations
0182  */
0183 struct lcs_header {
0184     __u16  offset;
0185     __u8   type;
0186     __u8   slot;
0187 }  __attribute__ ((packed));
0188 
0189 struct lcs_ip_mac_pair {
0190     __be32  ip_addr;
0191     __u8   mac_addr[LCS_MAC_LENGTH];
0192     __u8   reserved[2];
0193 }  __attribute__ ((packed));
0194 
0195 struct lcs_ipm_list {
0196     struct list_head list;
0197     struct lcs_ip_mac_pair ipm;
0198     __u8 ipm_state;
0199 };
0200 
0201 struct lcs_cmd {
0202     __u16  offset;
0203     __u8   type;
0204     __u8   slot;
0205     __u8   cmd_code;
0206     __u8   initiator;
0207     __u16  sequence_no;
0208     __u16  return_code;
0209     union {
0210         struct {
0211             __u8   lan_type;
0212             __u8   portno;
0213             __u16  parameter_count;
0214             __u8   operator_flags[3];
0215             __u8   reserved[3];
0216         } lcs_std_cmd;
0217         struct {
0218             __u16  unused1;
0219             __u16  buff_size;
0220             __u8   unused2[6];
0221         } lcs_startup;
0222         struct {
0223             __u8   lan_type;
0224             __u8   portno;
0225             __u8   unused[10];
0226             __u8   mac_addr[LCS_MAC_LENGTH];
0227             __u32  num_packets_deblocked;
0228             __u32  num_packets_blocked;
0229             __u32  num_packets_tx_on_lan;
0230             __u32  num_tx_errors_detected;
0231             __u32  num_tx_packets_disgarded;
0232             __u32  num_packets_rx_from_lan;
0233             __u32  num_rx_errors_detected;
0234             __u32  num_rx_discarded_nobuffs_avail;
0235             __u32  num_rx_packets_too_large;
0236         } lcs_lanstat_cmd;
0237 #ifdef CONFIG_IP_MULTICAST
0238         struct {
0239             __u8   lan_type;
0240             __u8   portno;
0241             __u16  num_ip_pairs;
0242             __u16  ip_assists_supported;
0243             __u16  ip_assists_enabled;
0244             __u16  version;
0245             struct {
0246                 struct lcs_ip_mac_pair
0247                 ip_mac_pair[32];
0248                 __u32     response_data;
0249             } lcs_ipass_ctlmsg __attribute ((packed));
0250         } lcs_qipassist __attribute__ ((packed));
0251 #endif /*CONFIG_IP_MULTICAST */
0252     } cmd __attribute__ ((packed));
0253 }  __attribute__ ((packed));
0254 
0255 /**
0256  * Forward declarations.
0257  */
0258 struct lcs_card;
0259 struct lcs_channel;
0260 
0261 /**
0262  * Definition of an lcs buffer.
0263  */
0264 struct lcs_buffer {
0265     enum lcs_buffer_states state;
0266     void *data;
0267     int count;
0268     /* Callback for completion notification. */
0269     void (*callback)(struct lcs_channel *, struct lcs_buffer *);
0270 };
0271 
0272 struct lcs_reply {
0273     struct list_head list;
0274     __u16 sequence_no;
0275     refcount_t refcnt;
0276     /* Callback for completion notification. */
0277     void (*callback)(struct lcs_card *, struct lcs_cmd *);
0278     wait_queue_head_t wait_q;
0279     struct lcs_card *card;
0280     struct timer_list timer;
0281     int received;
0282     int rc;
0283 };
0284 
0285 /**
0286  * Definition of an lcs channel
0287  */
0288 struct lcs_channel {
0289     enum lcs_channel_states state;
0290     struct ccw_device *ccwdev;
0291     struct ccw1 ccws[LCS_NUM_BUFFS + 1];
0292     wait_queue_head_t wait_q;
0293     struct tasklet_struct irq_tasklet;
0294     struct lcs_buffer iob[LCS_NUM_BUFFS];
0295     int io_idx;
0296     int buf_idx;
0297 };
0298 
0299 
0300 /**
0301  * definition of the lcs card
0302  */
0303 struct lcs_card {
0304     spinlock_t lock;
0305     spinlock_t ipm_lock;
0306     enum lcs_dev_states state;
0307     struct net_device *dev;
0308     struct net_device_stats stats;
0309     __be16 (*lan_type_trans)(struct sk_buff *skb,
0310                      struct net_device *dev);
0311     struct ccwgroup_device *gdev;
0312     struct lcs_channel read;
0313     struct lcs_channel write;
0314     struct lcs_buffer *tx_buffer;
0315     int tx_emitted;
0316     struct list_head lancmd_waiters;
0317     int lancmd_timeout;
0318 
0319     struct work_struct kernel_thread_starter;
0320     spinlock_t mask_lock;
0321     unsigned long thread_start_mask;
0322     unsigned long thread_running_mask;
0323     unsigned long thread_allowed_mask;
0324     wait_queue_head_t wait_q;
0325 
0326 #ifdef CONFIG_IP_MULTICAST
0327     struct list_head ipm_list;
0328 #endif
0329     __u8 mac[LCS_MAC_LENGTH];
0330     __u16 ip_assists_supported;
0331     __u16 ip_assists_enabled;
0332     __s8 lan_type;
0333     __u32 pkt_seq;
0334     __u16 sequence_no;
0335     __s16 portno;
0336     /* Some info copied from probeinfo */
0337     u8 device_forced;
0338     u8 max_port_no;
0339     u8 hint_port_no;
0340     s16 port_protocol_no;
0341 }  __attribute__ ((aligned(8)));
0342