hns_enet.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (c) 2014-2015 Hisilicon Limited.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. */
  9. #ifndef __HNS_ENET_H
  10. #define __HNS_ENET_H
  11. #include <linux/netdevice.h>
  12. #include <linux/of_net.h>
  13. #include <linux/of_mdio.h>
  14. #include <linux/timer.h>
  15. #include <linux/workqueue.h>
  16. #include "hnae.h"
  17. #define HNS_DEBUG_OFFSET 6
  18. #define HNS_SRV_OFFSET 2
  19. enum hns_nic_state {
  20. NIC_STATE_TESTING = 0,
  21. NIC_STATE_RESETTING,
  22. NIC_STATE_REINITING,
  23. NIC_STATE_DOWN,
  24. NIC_STATE_DISABLED,
  25. NIC_STATE_REMOVING,
  26. NIC_STATE_SERVICE_INITED,
  27. NIC_STATE_SERVICE_SCHED,
  28. NIC_STATE2_RESET_REQUESTED,
  29. NIC_STATE_MAX
  30. };
  31. struct hns_nic_ring_data {
  32. struct hnae_ring *ring;
  33. struct napi_struct napi;
  34. cpumask_t mask; /* affinity mask */
  35. u32 queue_index;
  36. int (*poll_one)(struct hns_nic_ring_data *, int, void *);
  37. void (*ex_process)(struct hns_nic_ring_data *, struct sk_buff *);
  38. bool (*fini_process)(struct hns_nic_ring_data *);
  39. };
  40. /* compatible the difference between two versions */
  41. struct hns_nic_ops {
  42. void (*fill_desc)(struct hnae_ring *ring, void *priv,
  43. int size, dma_addr_t dma, int frag_end,
  44. int buf_num, enum hns_desc_type type, int mtu);
  45. int (*maybe_stop_tx)(struct sk_buff **out_skb,
  46. int *bnum, struct hnae_ring *ring);
  47. void (*get_rxd_bnum)(u32 bnum_flag, int *out_bnum);
  48. };
  49. struct hns_nic_priv {
  50. const struct fwnode_handle *fwnode;
  51. u32 enet_ver;
  52. u32 port_id;
  53. int phy_mode;
  54. int phy_led_val;
  55. struct net_device *netdev;
  56. struct device *dev;
  57. struct hnae_handle *ae_handle;
  58. struct hns_nic_ops ops;
  59. /* the cb for nic to manage the ring buffer, the first half of the
  60. * array is for tx_ring and vice versa for the second half
  61. */
  62. struct hns_nic_ring_data *ring_data;
  63. /* The most recently read link state */
  64. int link;
  65. u64 tx_timeout_count;
  66. unsigned long state;
  67. struct timer_list service_timer;
  68. struct work_struct service_task;
  69. struct notifier_block notifier_block;
  70. };
  71. #define tx_ring_data(priv, idx) ((priv)->ring_data[idx])
  72. #define rx_ring_data(priv, idx) \
  73. ((priv)->ring_data[(priv)->ae_handle->q_num + (idx)])
  74. void hns_ethtool_set_ops(struct net_device *ndev);
  75. void hns_nic_net_reset(struct net_device *ndev);
  76. void hns_nic_net_reinit(struct net_device *netdev);
  77. int hns_nic_init_phy(struct net_device *ndev, struct hnae_handle *h);
  78. netdev_tx_t hns_nic_net_xmit_hw(struct net_device *ndev,
  79. struct sk_buff *skb,
  80. struct hns_nic_ring_data *ring_data);
  81. #endif /**__HNS_ENET_H */