/* Names used in this framework: * ae handle (handle): * a set of queues provided by AE * ring buffer queue (rbq): * the channel between upper layer and the AE, can do tx and rx * ring: * a tx or rx channel within a rbq * ring description (desc): * an element in the ring with packet information * buffer: * a memory region referred by desc with the full packet payload * * "num" means a static number set as a parameter, "count" mean a dynamic * number set while running * "cb" means control block
*/
/* some said the RX and TX RCB format should not be the same in the future. But * it is the same now...
*/ #define RCB_REG_BASEADDR_L 0x00 /* P660 support only 32bit accessing */ #define RCB_REG_BASEADDR_H 0x04 #define RCB_REG_BD_NUM 0x08 #define RCB_REG_BD_LEN 0x0C #define RCB_REG_PKTLINE 0x10 #define RCB_REG_TAIL 0x18 #define RCB_REG_HEAD 0x1C #define RCB_REG_FBDNUM 0x20 #define RCB_REG_OFFSET 0x24 /* pkt num to be handled */ #define RCB_REG_PKTNUM_RECORD 0x2C /* total pkt received */
struct hnae_ring {
u8 __iomem *io_base; /* base io address for the ring */ struct hnae_desc *desc; /* dma map address space */ struct hnae_desc_cb *desc_cb; struct hnae_queue *q; int irq; char ring_name[RCB_RING_NAME_LEN];
/* statistic */ struct ring_stats stats;
dma_addr_t desc_dma_addr;
u32 buf_size; /* size for hnae_desc->addr, preset by AE */
u16 desc_num; /* total number of desc */
u16 max_desc_num_per_pkt;
u16 max_raw_data_sz_per_desc;
u16 max_pkt_size; int next_to_use; /* idx of next spare desc */
/* idx of lastest sent desc, the ring is empty when equal to * next_to_use
*/ int next_to_clean;
int flags; /* ring attribute */ int irq_init_flag;
/* total rx bytes after last rx rate calucated */
u64 coal_last_rx_bytes; unsignedlong coal_last_jiffies;
u32 coal_param;
u32 coal_rx_rate; /* rx rate in MB */
};
/* the distance between [begin, end) in a ring buffer * note: there is a unuse slot between the begin and the end
*/ staticinlineint ring_dist(struct hnae_ring *ring, int begin, int end)
{
assert_is_ring_idx(ring, begin);
assert_is_ring_idx(ring, end);
return (end - begin + ring->desc_num) % ring->desc_num;
}
/* mac media type */ enum hnae_media_type {
HNAE_MEDIA_TYPE_UNKNOWN = 0,
HNAE_MEDIA_TYPE_FIBER,
HNAE_MEDIA_TYPE_COPPER,
HNAE_MEDIA_TYPE_BACKPLANE,
};
/* This struct defines the operation on the handle. * * get_handle(): (mandatory) * Get a handle from AE according to its name and options. * the AE driver should manage the space used by handle and its queues while * the HNAE framework will allocate desc and desc_cb for all rings in the * queues. * put_handle(): * Release the handle. * start(): * Enable the hardware, include all queues * stop(): * Disable the hardware * set_opts(): (mandatory) * Set options to the AE * get_opts(): (mandatory) * Get options from the AE * get_status(): * Get the carrier state of the back channel of the handle, 1 for ok, 0 for * non-ok * toggle_ring_irq(): (mandatory) * Set the ring irq to be enabled(0) or disable(1) * toggle_queue_status(): (mandatory) * Set the queue to be enabled(1) or disable(0), this will not change the * ring irq state * adjust_link() * adjust link status * set_loopback() * set loopback * get_ring_bdnum_limit() * get ring bd number limit * get_pauseparam() * get tx and rx of pause frame use * set_pauseparam() * set tx and rx of pause frame use * get_coalesce_usecs() * get usecs to delay a TX interrupt after a packet is sent * get_rx_max_coalesced_frames() * get Maximum number of packets to be sent before a TX interrupt. * set_coalesce_usecs() * set usecs to delay a TX interrupt after a packet is sent * set_coalesce_frames() * set Maximum number of packets to be sent before a TX interrupt. * get_ringnum() * get RX/TX ring number * get_max_ringnum() * get RX/TX ring maximum number * get_mac_addr() * get mac address * set_mac_addr() * set mac address * clr_mc_addr() * clear mcast tcam table * set_mc_addr() * set multicast mode * add_uc_addr() * add ucast address * rm_uc_addr() * remove ucast address * set_mtu() * set mtu * update_stats() * update Old network device statistics * get_ethtool_stats() * get ethtool network device statistics * get_strings() * get a set of strings that describe the requested objects * get_sset_count() * get number of strings that @get_strings will write * update_led_status() * update the led status * set_led_id() * set led id * get_regs() * get regs dump * get_regs_len() * get the len of the regs dump
*/ struct hnae_ae_ops { struct hnae_handle *(*get_handle)(struct hnae_ae_dev *dev,
u32 port_id); void (*put_handle)(struct hnae_handle *handle); void (*init_queue)(struct hnae_queue *q); void (*fini_queue)(struct hnae_queue *q); int (*start)(struct hnae_handle *handle); void (*stop)(struct hnae_handle *handle); void (*reset)(struct hnae_handle *handle); int (*set_opts)(struct hnae_handle *handle, int type, void *opts); int (*get_opts)(struct hnae_handle *handle, int type, void **opts); int (*get_status)(struct hnae_handle *handle); int (*get_info)(struct hnae_handle *handle,
u8 *auto_neg, u16 *speed, u8 *duplex); void (*toggle_ring_irq)(struct hnae_ring *ring, u32 val); void (*adjust_link)(struct hnae_handle *handle, int speed, int duplex); bool (*need_adjust_link)(struct hnae_handle *handle, int speed, int duplex); int (*set_loopback)(struct hnae_handle *handle, enum hnae_loop loop_mode, int en); void (*get_ring_bdnum_limit)(struct hnae_queue *queue,
u32 *uplimit); void (*get_pauseparam)(struct hnae_handle *handle,
u32 *auto_neg, u32 *rx_en, u32 *tx_en); int (*set_pauseparam)(struct hnae_handle *handle,
u32 auto_neg, u32 rx_en, u32 tx_en); void (*get_coalesce_usecs)(struct hnae_handle *handle,
u32 *tx_usecs, u32 *rx_usecs); void (*get_max_coalesced_frames)(struct hnae_handle *handle,
u32 *tx_frames, u32 *rx_frames); int (*set_coalesce_usecs)(struct hnae_handle *handle, u32 timeout); int (*set_coalesce_frames)(struct hnae_handle *handle,
u32 tx_frames, u32 rx_frames); void (*get_coalesce_range)(struct hnae_handle *handle,
u32 *tx_frames_low, u32 *rx_frames_low,
u32 *tx_frames_high, u32 *rx_frames_high,
u32 *tx_usecs_low, u32 *rx_usecs_low,
u32 *tx_usecs_high, u32 *rx_usecs_high); void (*set_promisc_mode)(struct hnae_handle *handle, u32 en); int (*get_mac_addr)(struct hnae_handle *handle, void **p); int (*set_mac_addr)(struct hnae_handle *handle, constvoid *p); int (*add_uc_addr)(struct hnae_handle *handle, constunsignedchar *addr); int (*rm_uc_addr)(struct hnae_handle *handle, constunsignedchar *addr); int (*clr_mc_addr)(struct hnae_handle *handle); int (*set_mc_addr)(struct hnae_handle *handle, void *addr); int (*set_mtu)(struct hnae_handle *handle, int new_mtu); void (*set_tso_stats)(struct hnae_handle *handle, int enable); void (*update_stats)(struct hnae_handle *handle, struct net_device_stats *net_stats); void (*get_stats)(struct hnae_handle *handle, u64 *data); void (*get_strings)(struct hnae_handle *handle,
u32 stringset, u8 **data); int (*get_sset_count)(struct hnae_handle *handle, int stringset); void (*update_led_status)(struct hnae_handle *handle); int (*set_led_id)(struct hnae_handle *handle, enum hnae_led_state status); void (*get_regs)(struct hnae_handle *handle, void *data); int (*get_regs_len)(struct hnae_handle *handle);
u32 (*get_rss_key_size)(struct hnae_handle *handle);
u32 (*get_rss_indir_size)(struct hnae_handle *handle); int (*get_rss)(struct hnae_handle *handle, u32 *indir, u8 *key,
u8 *hfunc); int (*set_rss)(struct hnae_handle *handle, const u32 *indir, const u8 *key, const u8 hfunc);
};
struct hnae_ae_dev { struct device cls_dev; /* the class dev */ struct device *dev; /* the presented dev */ struct hnae_ae_ops *ops; struct list_head node; struct module *owner; /* the module who provides this dev */ int id; char name[AE_NAME_SIZE]; struct list_head handle_list;
spinlock_t lock; /* lock to protect the handle_list */
};
struct hnae_handle { struct device *owner_dev; /* the device which make use of this handle */ struct hnae_ae_dev *dev; /* the device who provides this handle */ struct phy_device *phy_dev;
phy_interface_t phy_if;
u32 if_support; int q_num; int vf_id; unsignedlong coal_last_jiffies;
u32 coal_param; /* self adapt coalesce param */ /* the ring index of last ring that set coal param */
u32 coal_ring_idx;
u32 eport_id;
u32 dport_id; /* v2 tx bd should fill the dport_id */ bool coal_adapt_en; enum hnae_port_type port_type; enum hnae_media_type media_type; struct list_head node; /* list to hnae_ae_dev->handle_list */ struct hnae_buf_ops *bops; /* operation for the buffer */ struct hnae_queue *qs[]; /* flexible array of all queues */
};
/* detach a in-used buffer and replace with a reserved one */ staticinlinevoid hnae_replace_buffer(struct hnae_ring *ring, int i, struct hnae_desc_cb *res_cb)
{ struct hnae_buf_ops *bops = ring->q->handle->bops;
/* when reinit buffer size, we should reinit buffer description */ staticinlinevoid hnae_reinit_all_ring_desc(struct hnae_handle *h)
{ int i, j; struct hnae_ring *ring;
for (i = 0; i < h->q_num; i++) {
ring = &h->qs[i]->rx_ring; for (j = 0; j < ring->desc_num; j++)
ring->desc[j].addr = cpu_to_le64(ring->desc_cb[j].dma);
}
wmb(); /* commit all data before submit */
}
/* when reinit buffer size, we should reinit page offset */ staticinlinevoid hnae_reinit_all_ring_page_off(struct hnae_handle *h)
{ int i, j; struct hnae_ring *ring;
for (i = 0; i < h->q_num; i++) {
ring = &h->qs[i]->rx_ring; for (j = 0; j < ring->desc_num; j++) {
ring->desc_cb[j].page_offset = 0; if (ring->desc[j].addr !=
cpu_to_le64(ring->desc_cb[j].dma))
ring->desc[j].addr =
cpu_to_le64(ring->desc_cb[j].dma);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.