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