^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * drivers/net/ethernet/rocker/rocker.h - Rocker switch device driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (c) 2014-2016 Jiri Pirko <jiri@mellanox.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2014 Scott Feldman <sfeldma@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #ifndef _ROCKER_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #define _ROCKER_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <net/neighbour.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <net/switchdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "rocker_hw.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct rocker_desc_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) char *data; /* mapped */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) size_t data_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) size_t tlv_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct rocker_desc *desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) dma_addr_t mapaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct rocker_dma_ring_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) u32 head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) u32 tail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct rocker_desc *desc; /* mapped */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) dma_addr_t mapaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct rocker_desc_info *desc_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) unsigned int type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct rocker;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct rocker_port {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct rocker *rocker;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) void *wpriv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) unsigned int port_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) u32 pport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct napi_struct napi_tx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct napi_struct napi_rx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct rocker_dma_ring_info tx_ring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct rocker_dma_ring_info rx_ring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct rocker_port *rocker_port_dev_lower_find(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct rocker *rocker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct rocker_world_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct rocker {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct pci_dev *pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) u8 __iomem *hw_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct msix_entry *msix_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) unsigned int port_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct rocker_port **ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) u64 id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) } hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) spinlock_t cmd_ring_lock; /* for cmd ring accesses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct rocker_dma_ring_info cmd_ring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct rocker_dma_ring_info event_ring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct notifier_block fib_nb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct rocker_world_ops *wops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct workqueue_struct *rocker_owq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) void *wpriv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) typedef int (*rocker_cmd_prep_cb_t)(const struct rocker_port *rocker_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct rocker_desc_info *desc_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) void *priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) typedef int (*rocker_cmd_proc_cb_t)(const struct rocker_port *rocker_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) const struct rocker_desc_info *desc_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) void *priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) int rocker_cmd_exec(struct rocker_port *rocker_port, bool nowait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) rocker_cmd_prep_cb_t prepare, void *prepare_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) rocker_cmd_proc_cb_t process, void *process_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) int rocker_port_set_learning(struct rocker_port *rocker_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) bool learning);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct rocker_world_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) const char *kind;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) size_t priv_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) size_t port_priv_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) u8 mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) int (*init)(struct rocker *rocker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) void (*fini)(struct rocker *rocker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) int (*port_pre_init)(struct rocker_port *rocker_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) int (*port_init)(struct rocker_port *rocker_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) void (*port_fini)(struct rocker_port *rocker_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) void (*port_post_fini)(struct rocker_port *rocker_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) int (*port_open)(struct rocker_port *rocker_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) void (*port_stop)(struct rocker_port *rocker_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int (*port_attr_stp_state_set)(struct rocker_port *rocker_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) u8 state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) int (*port_attr_bridge_flags_set)(struct rocker_port *rocker_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) unsigned long brport_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct switchdev_trans *trans);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) int (*port_attr_bridge_flags_support_get)(const struct rocker_port *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) rocker_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) unsigned long *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) p_brport_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) int (*port_attr_bridge_ageing_time_set)(struct rocker_port *rocker_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) u32 ageing_time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct switchdev_trans *trans);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) int (*port_obj_vlan_add)(struct rocker_port *rocker_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) const struct switchdev_obj_port_vlan *vlan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) int (*port_obj_vlan_del)(struct rocker_port *rocker_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) const struct switchdev_obj_port_vlan *vlan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) int (*port_obj_fdb_add)(struct rocker_port *rocker_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) u16 vid, const unsigned char *addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) int (*port_obj_fdb_del)(struct rocker_port *rocker_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) u16 vid, const unsigned char *addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) int (*port_master_linked)(struct rocker_port *rocker_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct net_device *master);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) int (*port_master_unlinked)(struct rocker_port *rocker_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct net_device *master);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) int (*port_neigh_update)(struct rocker_port *rocker_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct neighbour *n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) int (*port_neigh_destroy)(struct rocker_port *rocker_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct neighbour *n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) int (*port_ev_mac_vlan_seen)(struct rocker_port *rocker_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) const unsigned char *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) __be16 vlan_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) int (*fib4_add)(struct rocker *rocker,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) const struct fib_entry_notifier_info *fen_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) int (*fib4_del)(struct rocker *rocker,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) const struct fib_entry_notifier_info *fen_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) void (*fib4_abort)(struct rocker *rocker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) extern struct rocker_world_ops rocker_ofdpa_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) #endif