Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * Copyright Gavin Shan, IBM Corporation 2016.
0004  */
0005 
0006 #ifndef __NCSI_INTERNAL_H__
0007 #define __NCSI_INTERNAL_H__
0008 
0009 enum {
0010     NCSI_CAP_BASE       = 0,
0011     NCSI_CAP_GENERIC    = 0,
0012     NCSI_CAP_BC,
0013     NCSI_CAP_MC,
0014     NCSI_CAP_BUFFER,
0015     NCSI_CAP_AEN,
0016     NCSI_CAP_VLAN,
0017     NCSI_CAP_MAX
0018 };
0019 
0020 enum {
0021     NCSI_CAP_GENERIC_HWA             = 0x01, /* HW arbitration           */
0022     NCSI_CAP_GENERIC_HDS             = 0x02, /* HNC driver status change */
0023     NCSI_CAP_GENERIC_FC              = 0x04, /* HNC to MC flow control   */
0024     NCSI_CAP_GENERIC_FC1             = 0x08, /* MC to HNC flow control   */
0025     NCSI_CAP_GENERIC_MC              = 0x10, /* Global MC filtering      */
0026     NCSI_CAP_GENERIC_HWA_UNKNOWN     = 0x00, /* Unknown HW arbitration   */
0027     NCSI_CAP_GENERIC_HWA_SUPPORT     = 0x20, /* Supported HW arbitration */
0028     NCSI_CAP_GENERIC_HWA_NOT_SUPPORT = 0x40, /* No HW arbitration        */
0029     NCSI_CAP_GENERIC_HWA_RESERVED    = 0x60, /* Reserved HW arbitration  */
0030     NCSI_CAP_GENERIC_HWA_MASK        = 0x60, /* Mask for HW arbitration  */
0031     NCSI_CAP_GENERIC_MASK            = 0x7f,
0032     NCSI_CAP_BC_ARP                  = 0x01, /* ARP packet filtering     */
0033     NCSI_CAP_BC_DHCPC                = 0x02, /* DHCP client filtering    */
0034     NCSI_CAP_BC_DHCPS                = 0x04, /* DHCP server filtering    */
0035     NCSI_CAP_BC_NETBIOS              = 0x08, /* NetBIOS packet filtering */
0036     NCSI_CAP_BC_MASK                 = 0x0f,
0037     NCSI_CAP_MC_IPV6_NEIGHBOR        = 0x01, /* IPv6 neighbor filtering  */
0038     NCSI_CAP_MC_IPV6_ROUTER          = 0x02, /* IPv6 router filering     */
0039     NCSI_CAP_MC_DHCPV6_RELAY         = 0x04, /* DHCPv6 relay / server MC */
0040     NCSI_CAP_MC_DHCPV6_WELL_KNOWN    = 0x08, /* DHCPv6 well-known MC     */
0041     NCSI_CAP_MC_IPV6_MLD             = 0x10, /* IPv6 MLD filtering       */
0042     NCSI_CAP_MC_IPV6_NEIGHBOR_S      = 0x20, /* IPv6 neighbour filtering */
0043     NCSI_CAP_MC_MASK                 = 0x3f,
0044     NCSI_CAP_AEN_LSC                 = 0x01, /* Link status change       */
0045     NCSI_CAP_AEN_CR                  = 0x02, /* Configuration required   */
0046     NCSI_CAP_AEN_HDS                 = 0x04, /* HNC driver status        */
0047     NCSI_CAP_AEN_MASK                = 0x07,
0048     NCSI_CAP_VLAN_ONLY               = 0x01, /* Filter VLAN packet only  */
0049     NCSI_CAP_VLAN_NO                 = 0x02, /* Filter VLAN and non-VLAN */
0050     NCSI_CAP_VLAN_ANY                = 0x04, /* Filter Any-and-non-VLAN  */
0051     NCSI_CAP_VLAN_MASK               = 0x07
0052 };
0053 
0054 enum {
0055     NCSI_MODE_BASE      = 0,
0056     NCSI_MODE_ENABLE    = 0,
0057     NCSI_MODE_TX_ENABLE,
0058     NCSI_MODE_LINK,
0059     NCSI_MODE_VLAN,
0060     NCSI_MODE_BC,
0061     NCSI_MODE_MC,
0062     NCSI_MODE_AEN,
0063     NCSI_MODE_FC,
0064     NCSI_MODE_MAX
0065 };
0066 
0067 /* Supported media status bits for Mellanox Mac affinity command.
0068  * Bit (0-2) for different protocol support; Bit 1 for RBT support,
0069  * bit 1 for SMBUS support and bit 2 for PCIE support. Bit (3-5)
0070  * for different protocol availability. Bit 4 for RBT, bit 4 for
0071  * SMBUS and bit 5 for PCIE.
0072  */
0073 enum {
0074     MLX_MC_RBT_SUPPORT  = 0x01, /* MC supports RBT         */
0075     MLX_MC_RBT_AVL      = 0x08, /* RBT medium is available */
0076 };
0077 
0078 /* OEM Vendor Manufacture ID */
0079 #define NCSI_OEM_MFR_MLX_ID             0x8119
0080 #define NCSI_OEM_MFR_BCM_ID             0x113d
0081 #define NCSI_OEM_MFR_INTEL_ID           0x157
0082 /* Intel specific OEM command */
0083 #define NCSI_OEM_INTEL_CMD_GMA          0x06   /* CMD ID for Get MAC */
0084 #define NCSI_OEM_INTEL_CMD_KEEP_PHY     0x20   /* CMD ID for Keep PHY up */
0085 /* Broadcom specific OEM Command */
0086 #define NCSI_OEM_BCM_CMD_GMA            0x01   /* CMD ID for Get MAC */
0087 /* Mellanox specific OEM Command */
0088 #define NCSI_OEM_MLX_CMD_GMA            0x00   /* CMD ID for Get MAC */
0089 #define NCSI_OEM_MLX_CMD_GMA_PARAM      0x1b   /* Parameter for GMA  */
0090 #define NCSI_OEM_MLX_CMD_SMAF           0x01   /* CMD ID for Set MC Affinity */
0091 #define NCSI_OEM_MLX_CMD_SMAF_PARAM     0x07   /* Parameter for SMAF         */
0092 /* OEM Command payload lengths*/
0093 #define NCSI_OEM_INTEL_CMD_GMA_LEN      5
0094 #define NCSI_OEM_INTEL_CMD_KEEP_PHY_LEN 7
0095 #define NCSI_OEM_BCM_CMD_GMA_LEN        12
0096 #define NCSI_OEM_MLX_CMD_GMA_LEN        8
0097 #define NCSI_OEM_MLX_CMD_SMAF_LEN        60
0098 /* Offset in OEM request */
0099 #define MLX_SMAF_MAC_ADDR_OFFSET         8     /* Offset for MAC in SMAF    */
0100 #define MLX_SMAF_MED_SUPPORT_OFFSET      14    /* Offset for medium in SMAF */
0101 /* Mac address offset in OEM response */
0102 #define BCM_MAC_ADDR_OFFSET             28
0103 #define MLX_MAC_ADDR_OFFSET             8
0104 #define INTEL_MAC_ADDR_OFFSET           1
0105 
0106 
0107 struct ncsi_channel_version {
0108     u32 version;        /* Supported BCD encoded NCSI version */
0109     u32 alpha2;     /* Supported BCD encoded NCSI version */
0110     u8  fw_name[12];    /* Firmware name string                */
0111     u32 fw_version;     /* Firmware version                   */
0112     u16 pci_ids[4];     /* PCI identification                 */
0113     u32 mf_id;      /* Manufacture ID                     */
0114 };
0115 
0116 struct ncsi_channel_cap {
0117     u32 index;  /* Index of channel capabilities */
0118     u32 cap;    /* NCSI channel capability       */
0119 };
0120 
0121 struct ncsi_channel_mode {
0122     u32 index;  /* Index of channel modes      */
0123     u32 enable; /* Enabled or disabled         */
0124     u32 size;   /* Valid entries in ncm_data[] */
0125     u32 data[8];    /* Data entries                */
0126 };
0127 
0128 struct ncsi_channel_mac_filter {
0129     u8  n_uc;
0130     u8  n_mc;
0131     u8  n_mixed;
0132     u64 bitmap;
0133     unsigned char   *addrs;
0134 };
0135 
0136 struct ncsi_channel_vlan_filter {
0137     u8  n_vids;
0138     u64 bitmap;
0139     u16 *vids;
0140 };
0141 
0142 struct ncsi_channel_stats {
0143     u32 hnc_cnt_hi;     /* Counter cleared            */
0144     u32 hnc_cnt_lo;     /* Counter cleared            */
0145     u32 hnc_rx_bytes;   /* Rx bytes                   */
0146     u32 hnc_tx_bytes;   /* Tx bytes                   */
0147     u32 hnc_rx_uc_pkts; /* Rx UC packets              */
0148     u32 hnc_rx_mc_pkts;     /* Rx MC packets              */
0149     u32 hnc_rx_bc_pkts; /* Rx BC packets              */
0150     u32 hnc_tx_uc_pkts; /* Tx UC packets              */
0151     u32 hnc_tx_mc_pkts; /* Tx MC packets              */
0152     u32 hnc_tx_bc_pkts; /* Tx BC packets              */
0153     u32 hnc_fcs_err;    /* FCS errors                 */
0154     u32 hnc_align_err;  /* Alignment errors           */
0155     u32 hnc_false_carrier;  /* False carrier detection    */
0156     u32 hnc_runt_pkts;  /* Rx runt packets            */
0157     u32 hnc_jabber_pkts;    /* Rx jabber packets          */
0158     u32 hnc_rx_pause_xon;   /* Rx pause XON frames        */
0159     u32 hnc_rx_pause_xoff;  /* Rx XOFF frames             */
0160     u32 hnc_tx_pause_xon;   /* Tx XON frames              */
0161     u32 hnc_tx_pause_xoff;  /* Tx XOFF frames             */
0162     u32 hnc_tx_s_collision; /* Single collision frames    */
0163     u32 hnc_tx_m_collision; /* Multiple collision frames  */
0164     u32 hnc_l_collision;    /* Late collision frames      */
0165     u32 hnc_e_collision;    /* Excessive collision frames */
0166     u32 hnc_rx_ctl_frames;  /* Rx control frames          */
0167     u32 hnc_rx_64_frames;   /* Rx 64-bytes frames         */
0168     u32 hnc_rx_127_frames;  /* Rx 65-127 bytes frames     */
0169     u32 hnc_rx_255_frames;  /* Rx 128-255 bytes frames    */
0170     u32 hnc_rx_511_frames;  /* Rx 256-511 bytes frames    */
0171     u32 hnc_rx_1023_frames; /* Rx 512-1023 bytes frames   */
0172     u32 hnc_rx_1522_frames; /* Rx 1024-1522 bytes frames  */
0173     u32 hnc_rx_9022_frames; /* Rx 1523-9022 bytes frames  */
0174     u32 hnc_tx_64_frames;   /* Tx 64-bytes frames         */
0175     u32 hnc_tx_127_frames;  /* Tx 65-127 bytes frames     */
0176     u32 hnc_tx_255_frames;  /* Tx 128-255 bytes frames    */
0177     u32 hnc_tx_511_frames;  /* Tx 256-511 bytes frames    */
0178     u32 hnc_tx_1023_frames; /* Tx 512-1023 bytes frames   */
0179     u32 hnc_tx_1522_frames; /* Tx 1024-1522 bytes frames  */
0180     u32 hnc_tx_9022_frames; /* Tx 1523-9022 bytes frames  */
0181     u32 hnc_rx_valid_bytes; /* Rx valid bytes             */
0182     u32 hnc_rx_runt_pkts;   /* Rx error runt packets      */
0183     u32 hnc_rx_jabber_pkts; /* Rx error jabber packets    */
0184     u32 ncsi_rx_cmds;   /* Rx NCSI commands           */
0185     u32 ncsi_dropped_cmds;  /* Dropped commands           */
0186     u32 ncsi_cmd_type_errs; /* Command type errors        */
0187     u32 ncsi_cmd_csum_errs; /* Command checksum errors    */
0188     u32 ncsi_rx_pkts;   /* Rx NCSI packets            */
0189     u32 ncsi_tx_pkts;   /* Tx NCSI packets            */
0190     u32 ncsi_tx_aen_pkts;   /* Tx AEN packets             */
0191     u32 pt_tx_pkts;     /* Tx packets                 */
0192     u32 pt_tx_dropped;  /* Tx dropped packets         */
0193     u32 pt_tx_channel_err;  /* Tx channel errors          */
0194     u32 pt_tx_us_err;   /* Tx undersize errors        */
0195     u32 pt_rx_pkts;     /* Rx packets                 */
0196     u32 pt_rx_dropped;  /* Rx dropped packets         */
0197     u32 pt_rx_channel_err;  /* Rx channel errors          */
0198     u32 pt_rx_us_err;   /* Rx undersize errors        */
0199     u32 pt_rx_os_err;   /* Rx oversize errors         */
0200 };
0201 
0202 struct ncsi_dev_priv;
0203 struct ncsi_package;
0204 
0205 #define NCSI_PACKAGE_SHIFT  5
0206 #define NCSI_PACKAGE_INDEX(c)   (((c) >> NCSI_PACKAGE_SHIFT) & 0x7)
0207 #define NCSI_RESERVED_CHANNEL   0x1f
0208 #define NCSI_CHANNEL_INDEX(c)   ((c) & ((1 << NCSI_PACKAGE_SHIFT) - 1))
0209 #define NCSI_TO_CHANNEL(p, c)   (((p) << NCSI_PACKAGE_SHIFT) | (c))
0210 #define NCSI_MAX_PACKAGE    8
0211 #define NCSI_MAX_CHANNEL    32
0212 
0213 struct ncsi_channel {
0214     unsigned char               id;
0215     int                         state;
0216 #define NCSI_CHANNEL_INACTIVE       1
0217 #define NCSI_CHANNEL_ACTIVE     2
0218 #define NCSI_CHANNEL_INVISIBLE      3
0219     bool                        reconfigure_needed;
0220     spinlock_t                  lock;   /* Protect filters etc */
0221     struct ncsi_package         *package;
0222     struct ncsi_channel_version version;
0223     struct ncsi_channel_cap     caps[NCSI_CAP_MAX];
0224     struct ncsi_channel_mode    modes[NCSI_MODE_MAX];
0225     /* Filtering Settings */
0226     struct ncsi_channel_mac_filter  mac_filter;
0227     struct ncsi_channel_vlan_filter vlan_filter;
0228     struct ncsi_channel_stats   stats;
0229     struct {
0230         struct timer_list   timer;
0231         bool                enabled;
0232         unsigned int        state;
0233 #define NCSI_CHANNEL_MONITOR_START  0
0234 #define NCSI_CHANNEL_MONITOR_RETRY  1
0235 #define NCSI_CHANNEL_MONITOR_WAIT   2
0236 #define NCSI_CHANNEL_MONITOR_WAIT_MAX   5
0237     } monitor;
0238     struct list_head            node;
0239     struct list_head            link;
0240 };
0241 
0242 struct ncsi_package {
0243     unsigned char        id;          /* NCSI 3-bits package ID */
0244     unsigned char        uuid[16];    /* UUID                   */
0245     struct ncsi_dev_priv *ndp;        /* NCSI device            */
0246     spinlock_t           lock;        /* Protect the package    */
0247     unsigned int         channel_num; /* Number of channels     */
0248     struct list_head     channels;    /* List of channels        */
0249     struct list_head     node;        /* Form list of packages  */
0250 
0251     bool                 multi_channel; /* Enable multiple channels  */
0252     u32                  channel_whitelist; /* Channels to configure */
0253     struct ncsi_channel  *preferred_channel; /* Primary channel      */
0254 };
0255 
0256 struct ncsi_request {
0257     unsigned char        id;      /* Request ID - 0 to 255           */
0258     bool                 used;    /* Request that has been assigned  */
0259     unsigned int         flags;   /* NCSI request property           */
0260 #define NCSI_REQ_FLAG_EVENT_DRIVEN  1
0261 #define NCSI_REQ_FLAG_NETLINK_DRIVEN    2
0262     struct ncsi_dev_priv *ndp;    /* Associated NCSI device          */
0263     struct sk_buff       *cmd;    /* Associated NCSI command packet  */
0264     struct sk_buff       *rsp;    /* Associated NCSI response packet */
0265     struct timer_list    timer;   /* Timer on waiting for response   */
0266     bool                 enabled; /* Time has been enabled or not    */
0267     u32                  snd_seq;     /* netlink sending sequence number */
0268     u32                  snd_portid;  /* netlink portid of sender        */
0269     struct nlmsghdr      nlhdr;       /* netlink message header          */
0270 };
0271 
0272 enum {
0273     ncsi_dev_state_major        = 0xff00,
0274     ncsi_dev_state_minor        = 0x00ff,
0275     ncsi_dev_state_probe_deselect   = 0x0201,
0276     ncsi_dev_state_probe_package,
0277     ncsi_dev_state_probe_channel,
0278     ncsi_dev_state_probe_mlx_gma,
0279     ncsi_dev_state_probe_mlx_smaf,
0280     ncsi_dev_state_probe_cis,
0281     ncsi_dev_state_probe_keep_phy,
0282     ncsi_dev_state_probe_gvi,
0283     ncsi_dev_state_probe_gc,
0284     ncsi_dev_state_probe_gls,
0285     ncsi_dev_state_probe_dp,
0286     ncsi_dev_state_config_sp    = 0x0301,
0287     ncsi_dev_state_config_cis,
0288     ncsi_dev_state_config_oem_gma,
0289     ncsi_dev_state_config_clear_vids,
0290     ncsi_dev_state_config_svf,
0291     ncsi_dev_state_config_ev,
0292     ncsi_dev_state_config_sma,
0293     ncsi_dev_state_config_ebf,
0294     ncsi_dev_state_config_dgmf,
0295     ncsi_dev_state_config_ecnt,
0296     ncsi_dev_state_config_ec,
0297     ncsi_dev_state_config_ae,
0298     ncsi_dev_state_config_gls,
0299     ncsi_dev_state_config_done,
0300     ncsi_dev_state_suspend_select   = 0x0401,
0301     ncsi_dev_state_suspend_gls,
0302     ncsi_dev_state_suspend_dcnt,
0303     ncsi_dev_state_suspend_dc,
0304     ncsi_dev_state_suspend_deselect,
0305     ncsi_dev_state_suspend_done
0306 };
0307 
0308 struct vlan_vid {
0309     struct list_head list;
0310     __be16 proto;
0311     u16 vid;
0312 };
0313 
0314 struct ncsi_dev_priv {
0315     struct ncsi_dev     ndev;            /* Associated NCSI device     */
0316     unsigned int        flags;           /* NCSI device flags          */
0317 #define NCSI_DEV_PROBED     1            /* Finalized NCSI topology    */
0318 #define NCSI_DEV_HWA        2            /* Enabled HW arbitration     */
0319 #define NCSI_DEV_RESHUFFLE  4
0320 #define NCSI_DEV_RESET      8            /* Reset state of NC          */
0321     unsigned int        gma_flag;        /* OEM GMA flag               */
0322     spinlock_t          lock;            /* Protect the NCSI device    */
0323     unsigned int        package_probe_id;/* Current ID during probe    */
0324     unsigned int        package_num;     /* Number of packages         */
0325     struct list_head    packages;        /* List of packages           */
0326     struct ncsi_channel *hot_channel;    /* Channel was ever active    */
0327     struct ncsi_request requests[256];   /* Request table              */
0328     unsigned int        request_id;      /* Last used request ID       */
0329 #define NCSI_REQ_START_IDX  1
0330     unsigned int        pending_req_num; /* Number of pending requests */
0331     struct ncsi_package *active_package; /* Currently handled package  */
0332     struct ncsi_channel *active_channel; /* Currently handled channel  */
0333     struct list_head    channel_queue;   /* Config queue of channels   */
0334     struct work_struct  work;            /* For channel management     */
0335     struct packet_type  ptype;           /* NCSI packet Rx handler     */
0336     struct list_head    node;            /* Form NCSI device list      */
0337 #define NCSI_MAX_VLAN_VIDS  15
0338     struct list_head    vlan_vids;       /* List of active VLAN IDs */
0339 
0340     bool                multi_package;   /* Enable multiple packages   */
0341     bool                mlx_multi_host;  /* Enable multi host Mellanox */
0342     u32                 package_whitelist; /* Packages to configure    */
0343 };
0344 
0345 struct ncsi_cmd_arg {
0346     struct ncsi_dev_priv *ndp;        /* Associated NCSI device        */
0347     unsigned char        type;        /* Command in the NCSI packet    */
0348     unsigned char        id;          /* Request ID (sequence number)  */
0349     unsigned char        package;     /* Destination package ID        */
0350     unsigned char        channel;     /* Destination channel ID or 0x1f */
0351     unsigned short       payload;     /* Command packet payload length */
0352     unsigned int         req_flags;   /* NCSI request properties       */
0353     union {
0354         unsigned char  bytes[16]; /* Command packet specific data  */
0355         unsigned short words[8];
0356         unsigned int   dwords[4];
0357     };
0358     unsigned char        *data;       /* NCSI OEM data                 */
0359     struct genl_info     *info;       /* Netlink information           */
0360 };
0361 
0362 extern struct list_head ncsi_dev_list;
0363 extern spinlock_t ncsi_dev_lock;
0364 
0365 #define TO_NCSI_DEV_PRIV(nd) \
0366     container_of(nd, struct ncsi_dev_priv, ndev)
0367 #define NCSI_FOR_EACH_DEV(ndp) \
0368     list_for_each_entry_rcu(ndp, &ncsi_dev_list, node)
0369 #define NCSI_FOR_EACH_PACKAGE(ndp, np) \
0370     list_for_each_entry_rcu(np, &ndp->packages, node)
0371 #define NCSI_FOR_EACH_CHANNEL(np, nc) \
0372     list_for_each_entry_rcu(nc, &np->channels, node)
0373 
0374 /* Resources */
0375 int ncsi_reset_dev(struct ncsi_dev *nd);
0376 void ncsi_start_channel_monitor(struct ncsi_channel *nc);
0377 void ncsi_stop_channel_monitor(struct ncsi_channel *nc);
0378 struct ncsi_channel *ncsi_find_channel(struct ncsi_package *np,
0379                        unsigned char id);
0380 struct ncsi_channel *ncsi_add_channel(struct ncsi_package *np,
0381                       unsigned char id);
0382 struct ncsi_package *ncsi_find_package(struct ncsi_dev_priv *ndp,
0383                        unsigned char id);
0384 struct ncsi_package *ncsi_add_package(struct ncsi_dev_priv *ndp,
0385                       unsigned char id);
0386 void ncsi_remove_package(struct ncsi_package *np);
0387 void ncsi_find_package_and_channel(struct ncsi_dev_priv *ndp,
0388                    unsigned char id,
0389                    struct ncsi_package **np,
0390                    struct ncsi_channel **nc);
0391 struct ncsi_request *ncsi_alloc_request(struct ncsi_dev_priv *ndp,
0392                     unsigned int req_flags);
0393 void ncsi_free_request(struct ncsi_request *nr);
0394 struct ncsi_dev *ncsi_find_dev(struct net_device *dev);
0395 int ncsi_process_next_channel(struct ncsi_dev_priv *ndp);
0396 bool ncsi_channel_has_link(struct ncsi_channel *channel);
0397 bool ncsi_channel_is_last(struct ncsi_dev_priv *ndp,
0398               struct ncsi_channel *channel);
0399 int ncsi_update_tx_channel(struct ncsi_dev_priv *ndp,
0400                struct ncsi_package *np,
0401                struct ncsi_channel *disable,
0402                struct ncsi_channel *enable);
0403 
0404 /* Packet handlers */
0405 u32 ncsi_calculate_checksum(unsigned char *data, int len);
0406 int ncsi_xmit_cmd(struct ncsi_cmd_arg *nca);
0407 int ncsi_rcv_rsp(struct sk_buff *skb, struct net_device *dev,
0408          struct packet_type *pt, struct net_device *orig_dev);
0409 int ncsi_aen_handler(struct ncsi_dev_priv *ndp, struct sk_buff *skb);
0410 
0411 #endif /* __NCSI_INTERNAL_H__ */