1 
   2 
   3 
   4 
   5 
   6 #ifndef __NCSI_INTERNAL_H__
   7 #define __NCSI_INTERNAL_H__
   8 
   9 enum {
  10         NCSI_CAP_BASE           = 0,
  11         NCSI_CAP_GENERIC        = 0,
  12         NCSI_CAP_BC,
  13         NCSI_CAP_MC,
  14         NCSI_CAP_BUFFER,
  15         NCSI_CAP_AEN,
  16         NCSI_CAP_VLAN,
  17         NCSI_CAP_MAX
  18 };
  19 
  20 enum {
  21         NCSI_CAP_GENERIC_HWA             = 0x01, 
  22         NCSI_CAP_GENERIC_HDS             = 0x02, 
  23         NCSI_CAP_GENERIC_FC              = 0x04, 
  24         NCSI_CAP_GENERIC_FC1             = 0x08, 
  25         NCSI_CAP_GENERIC_MC              = 0x10, 
  26         NCSI_CAP_GENERIC_HWA_UNKNOWN     = 0x00, 
  27         NCSI_CAP_GENERIC_HWA_SUPPORT     = 0x20, 
  28         NCSI_CAP_GENERIC_HWA_NOT_SUPPORT = 0x40, 
  29         NCSI_CAP_GENERIC_HWA_RESERVED    = 0x60, 
  30         NCSI_CAP_GENERIC_HWA_MASK        = 0x60, 
  31         NCSI_CAP_GENERIC_MASK            = 0x7f,
  32         NCSI_CAP_BC_ARP                  = 0x01, 
  33         NCSI_CAP_BC_DHCPC                = 0x02, 
  34         NCSI_CAP_BC_DHCPS                = 0x04, 
  35         NCSI_CAP_BC_NETBIOS              = 0x08, 
  36         NCSI_CAP_BC_MASK                 = 0x0f,
  37         NCSI_CAP_MC_IPV6_NEIGHBOR        = 0x01, 
  38         NCSI_CAP_MC_IPV6_ROUTER          = 0x02, 
  39         NCSI_CAP_MC_DHCPV6_RELAY         = 0x04, 
  40         NCSI_CAP_MC_DHCPV6_WELL_KNOWN    = 0x08, 
  41         NCSI_CAP_MC_IPV6_MLD             = 0x10, 
  42         NCSI_CAP_MC_IPV6_NEIGHBOR_S      = 0x20, 
  43         NCSI_CAP_MC_MASK                 = 0x3f,
  44         NCSI_CAP_AEN_LSC                 = 0x01, 
  45         NCSI_CAP_AEN_CR                  = 0x02, 
  46         NCSI_CAP_AEN_HDS                 = 0x04, 
  47         NCSI_CAP_AEN_MASK                = 0x07,
  48         NCSI_CAP_VLAN_ONLY               = 0x01, 
  49         NCSI_CAP_VLAN_NO                 = 0x02, 
  50         NCSI_CAP_VLAN_ANY                = 0x04, 
  51         NCSI_CAP_VLAN_MASK               = 0x07
  52 };
  53 
  54 enum {
  55         NCSI_MODE_BASE          = 0,
  56         NCSI_MODE_ENABLE        = 0,
  57         NCSI_MODE_TX_ENABLE,
  58         NCSI_MODE_LINK,
  59         NCSI_MODE_VLAN,
  60         NCSI_MODE_BC,
  61         NCSI_MODE_MC,
  62         NCSI_MODE_AEN,
  63         NCSI_MODE_FC,
  64         NCSI_MODE_MAX
  65 };
  66 
  67 
  68 #define NCSI_OEM_MFR_MLX_ID             0x8119
  69 #define NCSI_OEM_MFR_BCM_ID             0x113d
  70 
  71 #define NCSI_OEM_BCM_CMD_GMA            0x01   
  72 
  73 #define NCSI_OEM_MLX_CMD_GMA            0x00   
  74 #define NCSI_OEM_MLX_CMD_GMA_PARAM      0x1b   
  75 
  76 #define NCSI_OEM_BCM_CMD_GMA_LEN        12
  77 #define NCSI_OEM_MLX_CMD_GMA_LEN        8
  78 
  79 #define BCM_MAC_ADDR_OFFSET             28
  80 #define MLX_MAC_ADDR_OFFSET             8
  81 
  82 
  83 struct ncsi_channel_version {
  84         u32 version;            
  85         u32 alpha2;             
  86         u8  fw_name[12];        
  87         u32 fw_version;         
  88         u16 pci_ids[4];         
  89         u32 mf_id;              
  90 };
  91 
  92 struct ncsi_channel_cap {
  93         u32 index;      
  94         u32 cap;        
  95 };
  96 
  97 struct ncsi_channel_mode {
  98         u32 index;      
  99         u32 enable;     
 100         u32 size;       
 101         u32 data[8];    
 102 };
 103 
 104 struct ncsi_channel_mac_filter {
 105         u8      n_uc;
 106         u8      n_mc;
 107         u8      n_mixed;
 108         u64     bitmap;
 109         unsigned char   *addrs;
 110 };
 111 
 112 struct ncsi_channel_vlan_filter {
 113         u8      n_vids;
 114         u64     bitmap;
 115         u16     *vids;
 116 };
 117 
 118 struct ncsi_channel_stats {
 119         u32 hnc_cnt_hi;         
 120         u32 hnc_cnt_lo;         
 121         u32 hnc_rx_bytes;       
 122         u32 hnc_tx_bytes;       
 123         u32 hnc_rx_uc_pkts;     
 124         u32 hnc_rx_mc_pkts;     
 125         u32 hnc_rx_bc_pkts;     
 126         u32 hnc_tx_uc_pkts;     
 127         u32 hnc_tx_mc_pkts;     
 128         u32 hnc_tx_bc_pkts;     
 129         u32 hnc_fcs_err;        
 130         u32 hnc_align_err;      
 131         u32 hnc_false_carrier;  
 132         u32 hnc_runt_pkts;      
 133         u32 hnc_jabber_pkts;    
 134         u32 hnc_rx_pause_xon;   
 135         u32 hnc_rx_pause_xoff;  
 136         u32 hnc_tx_pause_xon;   
 137         u32 hnc_tx_pause_xoff;  
 138         u32 hnc_tx_s_collision; 
 139         u32 hnc_tx_m_collision; 
 140         u32 hnc_l_collision;    
 141         u32 hnc_e_collision;    
 142         u32 hnc_rx_ctl_frames;  
 143         u32 hnc_rx_64_frames;   
 144         u32 hnc_rx_127_frames;  
 145         u32 hnc_rx_255_frames;  
 146         u32 hnc_rx_511_frames;  
 147         u32 hnc_rx_1023_frames; 
 148         u32 hnc_rx_1522_frames; 
 149         u32 hnc_rx_9022_frames; 
 150         u32 hnc_tx_64_frames;   
 151         u32 hnc_tx_127_frames;  
 152         u32 hnc_tx_255_frames;  
 153         u32 hnc_tx_511_frames;  
 154         u32 hnc_tx_1023_frames; 
 155         u32 hnc_tx_1522_frames; 
 156         u32 hnc_tx_9022_frames; 
 157         u32 hnc_rx_valid_bytes; 
 158         u32 hnc_rx_runt_pkts;   
 159         u32 hnc_rx_jabber_pkts; 
 160         u32 ncsi_rx_cmds;       
 161         u32 ncsi_dropped_cmds;  
 162         u32 ncsi_cmd_type_errs; 
 163         u32 ncsi_cmd_csum_errs; 
 164         u32 ncsi_rx_pkts;       
 165         u32 ncsi_tx_pkts;       
 166         u32 ncsi_tx_aen_pkts;   
 167         u32 pt_tx_pkts;         
 168         u32 pt_tx_dropped;      
 169         u32 pt_tx_channel_err;  
 170         u32 pt_tx_us_err;       
 171         u32 pt_rx_pkts;         
 172         u32 pt_rx_dropped;      
 173         u32 pt_rx_channel_err;  
 174         u32 pt_rx_us_err;       
 175         u32 pt_rx_os_err;       
 176 };
 177 
 178 struct ncsi_dev_priv;
 179 struct ncsi_package;
 180 
 181 #define NCSI_PACKAGE_SHIFT      5
 182 #define NCSI_PACKAGE_INDEX(c)   (((c) >> NCSI_PACKAGE_SHIFT) & 0x7)
 183 #define NCSI_RESERVED_CHANNEL   0x1f
 184 #define NCSI_CHANNEL_INDEX(c)   ((c) & ((1 << NCSI_PACKAGE_SHIFT) - 1))
 185 #define NCSI_TO_CHANNEL(p, c)   (((p) << NCSI_PACKAGE_SHIFT) | (c))
 186 #define NCSI_MAX_PACKAGE        8
 187 #define NCSI_MAX_CHANNEL        32
 188 
 189 struct ncsi_channel {
 190         unsigned char               id;
 191         int                         state;
 192 #define NCSI_CHANNEL_INACTIVE           1
 193 #define NCSI_CHANNEL_ACTIVE             2
 194 #define NCSI_CHANNEL_INVISIBLE          3
 195         bool                        reconfigure_needed;
 196         spinlock_t                  lock;       
 197         struct ncsi_package         *package;
 198         struct ncsi_channel_version version;
 199         struct ncsi_channel_cap     caps[NCSI_CAP_MAX];
 200         struct ncsi_channel_mode    modes[NCSI_MODE_MAX];
 201         
 202         struct ncsi_channel_mac_filter  mac_filter;
 203         struct ncsi_channel_vlan_filter vlan_filter;
 204         struct ncsi_channel_stats   stats;
 205         struct {
 206                 struct timer_list   timer;
 207                 bool                enabled;
 208                 unsigned int        state;
 209 #define NCSI_CHANNEL_MONITOR_START      0
 210 #define NCSI_CHANNEL_MONITOR_RETRY      1
 211 #define NCSI_CHANNEL_MONITOR_WAIT       2
 212 #define NCSI_CHANNEL_MONITOR_WAIT_MAX   5
 213         } monitor;
 214         struct list_head            node;
 215         struct list_head            link;
 216 };
 217 
 218 struct ncsi_package {
 219         unsigned char        id;          
 220         unsigned char        uuid[16];    
 221         struct ncsi_dev_priv *ndp;        
 222         spinlock_t           lock;        
 223         unsigned int         channel_num; 
 224         struct list_head     channels;    
 225         struct list_head     node;        
 226 
 227         bool                 multi_channel; 
 228         u32                  channel_whitelist; 
 229         struct ncsi_channel  *preferred_channel; 
 230 };
 231 
 232 struct ncsi_request {
 233         unsigned char        id;      
 234         bool                 used;    
 235         unsigned int         flags;   
 236 #define NCSI_REQ_FLAG_EVENT_DRIVEN      1
 237 #define NCSI_REQ_FLAG_NETLINK_DRIVEN    2
 238         struct ncsi_dev_priv *ndp;    
 239         struct sk_buff       *cmd;    
 240         struct sk_buff       *rsp;    
 241         struct timer_list    timer;   
 242         bool                 enabled; 
 243         u32                  snd_seq;     
 244         u32                  snd_portid;  
 245         struct nlmsghdr      nlhdr;       
 246 };
 247 
 248 enum {
 249         ncsi_dev_state_major            = 0xff00,
 250         ncsi_dev_state_minor            = 0x00ff,
 251         ncsi_dev_state_probe_deselect   = 0x0201,
 252         ncsi_dev_state_probe_package,
 253         ncsi_dev_state_probe_channel,
 254         ncsi_dev_state_probe_cis,
 255         ncsi_dev_state_probe_gvi,
 256         ncsi_dev_state_probe_gc,
 257         ncsi_dev_state_probe_gls,
 258         ncsi_dev_state_probe_dp,
 259         ncsi_dev_state_config_sp        = 0x0301,
 260         ncsi_dev_state_config_cis,
 261         ncsi_dev_state_config_oem_gma,
 262         ncsi_dev_state_config_clear_vids,
 263         ncsi_dev_state_config_svf,
 264         ncsi_dev_state_config_ev,
 265         ncsi_dev_state_config_sma,
 266         ncsi_dev_state_config_ebf,
 267         ncsi_dev_state_config_dgmf,
 268         ncsi_dev_state_config_ecnt,
 269         ncsi_dev_state_config_ec,
 270         ncsi_dev_state_config_ae,
 271         ncsi_dev_state_config_gls,
 272         ncsi_dev_state_config_done,
 273         ncsi_dev_state_suspend_select   = 0x0401,
 274         ncsi_dev_state_suspend_gls,
 275         ncsi_dev_state_suspend_dcnt,
 276         ncsi_dev_state_suspend_dc,
 277         ncsi_dev_state_suspend_deselect,
 278         ncsi_dev_state_suspend_done
 279 };
 280 
 281 struct vlan_vid {
 282         struct list_head list;
 283         __be16 proto;
 284         u16 vid;
 285 };
 286 
 287 struct ncsi_dev_priv {
 288         struct ncsi_dev     ndev;            
 289         unsigned int        flags;           
 290 #define NCSI_DEV_PROBED         1            
 291 #define NCSI_DEV_HWA            2            
 292 #define NCSI_DEV_RESHUFFLE      4
 293 #define NCSI_DEV_RESET          8            
 294         unsigned int        gma_flag;        
 295         spinlock_t          lock;            
 296         unsigned int        package_probe_id;
 297         unsigned int        package_num;     
 298         struct list_head    packages;        
 299         struct ncsi_channel *hot_channel;    
 300         struct ncsi_request requests[256];   
 301         unsigned int        request_id;      
 302 #define NCSI_REQ_START_IDX      1
 303         unsigned int        pending_req_num; 
 304         struct ncsi_package *active_package; 
 305         struct ncsi_channel *active_channel; 
 306         struct list_head    channel_queue;   
 307         struct work_struct  work;            
 308         struct packet_type  ptype;           
 309         struct list_head    node;            
 310 #define NCSI_MAX_VLAN_VIDS      15
 311         struct list_head    vlan_vids;       
 312 
 313         bool                multi_package;   
 314         u32                 package_whitelist; 
 315 };
 316 
 317 struct ncsi_cmd_arg {
 318         struct ncsi_dev_priv *ndp;        
 319         unsigned char        type;        
 320         unsigned char        id;          
 321         unsigned char        package;     
 322         unsigned char        channel;     
 323         unsigned short       payload;     
 324         unsigned int         req_flags;   
 325         union {
 326                 unsigned char  bytes[16]; 
 327                 unsigned short words[8];
 328                 unsigned int   dwords[4];
 329         };
 330         unsigned char        *data;       
 331         struct genl_info     *info;       
 332 };
 333 
 334 extern struct list_head ncsi_dev_list;
 335 extern spinlock_t ncsi_dev_lock;
 336 
 337 #define TO_NCSI_DEV_PRIV(nd) \
 338         container_of(nd, struct ncsi_dev_priv, ndev)
 339 #define NCSI_FOR_EACH_DEV(ndp) \
 340         list_for_each_entry_rcu(ndp, &ncsi_dev_list, node)
 341 #define NCSI_FOR_EACH_PACKAGE(ndp, np) \
 342         list_for_each_entry_rcu(np, &ndp->packages, node)
 343 #define NCSI_FOR_EACH_CHANNEL(np, nc) \
 344         list_for_each_entry_rcu(nc, &np->channels, node)
 345 
 346 
 347 int ncsi_reset_dev(struct ncsi_dev *nd);
 348 void ncsi_start_channel_monitor(struct ncsi_channel *nc);
 349 void ncsi_stop_channel_monitor(struct ncsi_channel *nc);
 350 struct ncsi_channel *ncsi_find_channel(struct ncsi_package *np,
 351                                        unsigned char id);
 352 struct ncsi_channel *ncsi_add_channel(struct ncsi_package *np,
 353                                       unsigned char id);
 354 struct ncsi_package *ncsi_find_package(struct ncsi_dev_priv *ndp,
 355                                        unsigned char id);
 356 struct ncsi_package *ncsi_add_package(struct ncsi_dev_priv *ndp,
 357                                       unsigned char id);
 358 void ncsi_remove_package(struct ncsi_package *np);
 359 void ncsi_find_package_and_channel(struct ncsi_dev_priv *ndp,
 360                                    unsigned char id,
 361                                    struct ncsi_package **np,
 362                                    struct ncsi_channel **nc);
 363 struct ncsi_request *ncsi_alloc_request(struct ncsi_dev_priv *ndp,
 364                                         unsigned int req_flags);
 365 void ncsi_free_request(struct ncsi_request *nr);
 366 struct ncsi_dev *ncsi_find_dev(struct net_device *dev);
 367 int ncsi_process_next_channel(struct ncsi_dev_priv *ndp);
 368 bool ncsi_channel_has_link(struct ncsi_channel *channel);
 369 bool ncsi_channel_is_last(struct ncsi_dev_priv *ndp,
 370                           struct ncsi_channel *channel);
 371 int ncsi_update_tx_channel(struct ncsi_dev_priv *ndp,
 372                            struct ncsi_package *np,
 373                            struct ncsi_channel *disable,
 374                            struct ncsi_channel *enable);
 375 
 376 
 377 u32 ncsi_calculate_checksum(unsigned char *data, int len);
 378 int ncsi_xmit_cmd(struct ncsi_cmd_arg *nca);
 379 int ncsi_rcv_rsp(struct sk_buff *skb, struct net_device *dev,
 380                  struct packet_type *pt, struct net_device *orig_dev);
 381 int ncsi_aen_handler(struct ncsi_dev_priv *ndp, struct sk_buff *skb);
 382 
 383 #endif