enic.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /*
  2. * Copyright 2008-2010 Cisco Systems, Inc. All rights reserved.
  3. * Copyright 2007 Nuova Systems, Inc. All rights reserved.
  4. *
  5. * This program is free software; you may redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; version 2 of the License.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  10. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  11. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  12. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  13. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  14. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  15. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  16. * SOFTWARE.
  17. *
  18. */
  19. #ifndef _ENIC_H_
  20. #define _ENIC_H_
  21. #include "vnic_enet.h"
  22. #include "vnic_dev.h"
  23. #include "vnic_wq.h"
  24. #include "vnic_rq.h"
  25. #include "vnic_cq.h"
  26. #include "vnic_intr.h"
  27. #include "vnic_stats.h"
  28. #include "vnic_nic.h"
  29. #include "vnic_rss.h"
  30. #include <linux/irq.h>
  31. #define DRV_NAME "enic"
  32. #define DRV_DESCRIPTION "Cisco VIC Ethernet NIC Driver"
  33. #define DRV_VERSION "2.3.0.12"
  34. #define DRV_COPYRIGHT "Copyright 2008-2013 Cisco Systems, Inc"
  35. #define ENIC_BARS_MAX 6
  36. #define ENIC_WQ_MAX 8
  37. #define ENIC_RQ_MAX 8
  38. #define ENIC_CQ_MAX (ENIC_WQ_MAX + ENIC_RQ_MAX)
  39. #define ENIC_INTR_MAX (ENIC_CQ_MAX + 2)
  40. #define ENIC_AIC_LARGE_PKT_DIFF 3
  41. struct enic_msix_entry {
  42. int requested;
  43. char devname[IFNAMSIZ];
  44. irqreturn_t (*isr)(int, void *);
  45. void *devid;
  46. };
  47. /* Store only the lower range. Higher range is given by fw. */
  48. struct enic_intr_mod_range {
  49. u32 small_pkt_range_start;
  50. u32 large_pkt_range_start;
  51. };
  52. struct enic_intr_mod_table {
  53. u32 rx_rate;
  54. u32 range_percent;
  55. };
  56. #define ENIC_MAX_LINK_SPEEDS 3
  57. #define ENIC_LINK_SPEED_10G 10000
  58. #define ENIC_LINK_SPEED_4G 4000
  59. #define ENIC_LINK_40G_INDEX 2
  60. #define ENIC_LINK_10G_INDEX 1
  61. #define ENIC_LINK_4G_INDEX 0
  62. #define ENIC_RX_COALESCE_RANGE_END 125
  63. #define ENIC_AIC_TS_BREAK 100
  64. struct enic_rx_coal {
  65. u32 small_pkt_range_start;
  66. u32 large_pkt_range_start;
  67. u32 range_end;
  68. u32 use_adaptive_rx_coalesce;
  69. };
  70. /* priv_flags */
  71. #define ENIC_SRIOV_ENABLED (1 << 0)
  72. /* enic port profile set flags */
  73. #define ENIC_PORT_REQUEST_APPLIED (1 << 0)
  74. #define ENIC_SET_REQUEST (1 << 1)
  75. #define ENIC_SET_NAME (1 << 2)
  76. #define ENIC_SET_INSTANCE (1 << 3)
  77. #define ENIC_SET_HOST (1 << 4)
  78. struct enic_port_profile {
  79. u32 set;
  80. u8 request;
  81. char name[PORT_PROFILE_MAX];
  82. u8 instance_uuid[PORT_UUID_MAX];
  83. u8 host_uuid[PORT_UUID_MAX];
  84. u8 vf_mac[ETH_ALEN];
  85. u8 mac_addr[ETH_ALEN];
  86. };
  87. /* enic_rfs_fltr_node - rfs filter node in hash table
  88. * @@keys: IPv4 5 tuple
  89. * @flow_id: flow_id of clsf filter provided by kernel
  90. * @fltr_id: filter id of clsf filter returned by adaptor
  91. * @rq_id: desired rq index
  92. * @node: hlist_node
  93. */
  94. struct enic_rfs_fltr_node {
  95. struct flow_keys keys;
  96. u32 flow_id;
  97. u16 fltr_id;
  98. u16 rq_id;
  99. struct hlist_node node;
  100. };
  101. /* enic_rfs_flw_tbl - rfs flow table
  102. * @max: Maximum number of filters vNIC supports
  103. * @free: Number of free filters available
  104. * @toclean: hash table index to clean next
  105. * @ht_head: hash table list head
  106. * @lock: spin lock
  107. * @rfs_may_expire: timer function for enic_rps_may_expire_flow
  108. */
  109. struct enic_rfs_flw_tbl {
  110. u16 max;
  111. int free;
  112. #define ENIC_RFS_FLW_BITSHIFT (10)
  113. #define ENIC_RFS_FLW_MASK ((1 << ENIC_RFS_FLW_BITSHIFT) - 1)
  114. u16 toclean:ENIC_RFS_FLW_BITSHIFT;
  115. struct hlist_head ht_head[1 << ENIC_RFS_FLW_BITSHIFT];
  116. spinlock_t lock;
  117. struct timer_list rfs_may_expire;
  118. };
  119. /* Per-instance private data structure */
  120. struct enic {
  121. struct net_device *netdev;
  122. struct pci_dev *pdev;
  123. struct vnic_enet_config config;
  124. struct vnic_dev_bar bar[ENIC_BARS_MAX];
  125. struct vnic_dev *vdev;
  126. struct timer_list notify_timer;
  127. struct work_struct reset;
  128. struct work_struct change_mtu_work;
  129. struct msix_entry msix_entry[ENIC_INTR_MAX];
  130. struct enic_msix_entry msix[ENIC_INTR_MAX];
  131. u32 msg_enable;
  132. spinlock_t devcmd_lock;
  133. u8 mac_addr[ETH_ALEN];
  134. unsigned int flags;
  135. unsigned int priv_flags;
  136. unsigned int mc_count;
  137. unsigned int uc_count;
  138. u32 port_mtu;
  139. struct enic_rx_coal rx_coalesce_setting;
  140. u32 rx_coalesce_usecs;
  141. u32 tx_coalesce_usecs;
  142. #ifdef CONFIG_PCI_IOV
  143. u16 num_vfs;
  144. #endif
  145. spinlock_t enic_api_lock;
  146. struct enic_port_profile *pp;
  147. /* work queue cache line section */
  148. ____cacheline_aligned struct vnic_wq wq[ENIC_WQ_MAX];
  149. spinlock_t wq_lock[ENIC_WQ_MAX];
  150. unsigned int wq_count;
  151. u16 loop_enable;
  152. u16 loop_tag;
  153. /* receive queue cache line section */
  154. ____cacheline_aligned struct vnic_rq rq[ENIC_RQ_MAX];
  155. unsigned int rq_count;
  156. u64 rq_truncated_pkts;
  157. u64 rq_bad_fcs;
  158. struct napi_struct napi[ENIC_RQ_MAX + ENIC_WQ_MAX];
  159. /* interrupt resource cache line section */
  160. ____cacheline_aligned struct vnic_intr intr[ENIC_INTR_MAX];
  161. unsigned int intr_count;
  162. u32 __iomem *legacy_pba; /* memory-mapped */
  163. /* completion queue cache line section */
  164. ____cacheline_aligned struct vnic_cq cq[ENIC_CQ_MAX];
  165. unsigned int cq_count;
  166. struct enic_rfs_flw_tbl rfs_h;
  167. u32 rx_copybreak;
  168. u8 rss_key[ENIC_RSS_LEN];
  169. struct vnic_gen_stats gen_stats;
  170. };
  171. static inline struct net_device *vnic_get_netdev(struct vnic_dev *vdev)
  172. {
  173. struct enic *enic = vdev->priv;
  174. return enic->netdev;
  175. }
  176. /* wrappers function for kernel log
  177. * Make sure variable vdev of struct vnic_dev is available in the block where
  178. * these macros are used
  179. */
  180. #define vdev_info(args...) dev_info(&vdev->pdev->dev, args)
  181. #define vdev_warn(args...) dev_warn(&vdev->pdev->dev, args)
  182. #define vdev_err(args...) dev_err(&vdev->pdev->dev, args)
  183. #define vdev_netinfo(args...) netdev_info(vnic_get_netdev(vdev), args)
  184. #define vdev_netwarn(args...) netdev_warn(vnic_get_netdev(vdev), args)
  185. #define vdev_neterr(args...) netdev_err(vnic_get_netdev(vdev), args)
  186. static inline struct device *enic_get_dev(struct enic *enic)
  187. {
  188. return &(enic->pdev->dev);
  189. }
  190. static inline unsigned int enic_cq_rq(struct enic *enic, unsigned int rq)
  191. {
  192. return rq;
  193. }
  194. static inline unsigned int enic_cq_wq(struct enic *enic, unsigned int wq)
  195. {
  196. return enic->rq_count + wq;
  197. }
  198. static inline unsigned int enic_legacy_io_intr(void)
  199. {
  200. return 0;
  201. }
  202. static inline unsigned int enic_legacy_err_intr(void)
  203. {
  204. return 1;
  205. }
  206. static inline unsigned int enic_legacy_notify_intr(void)
  207. {
  208. return 2;
  209. }
  210. static inline unsigned int enic_msix_rq_intr(struct enic *enic,
  211. unsigned int rq)
  212. {
  213. return enic->cq[enic_cq_rq(enic, rq)].interrupt_offset;
  214. }
  215. static inline unsigned int enic_msix_wq_intr(struct enic *enic,
  216. unsigned int wq)
  217. {
  218. return enic->cq[enic_cq_wq(enic, wq)].interrupt_offset;
  219. }
  220. static inline unsigned int enic_msix_err_intr(struct enic *enic)
  221. {
  222. return enic->rq_count + enic->wq_count;
  223. }
  224. static inline unsigned int enic_msix_notify_intr(struct enic *enic)
  225. {
  226. return enic->rq_count + enic->wq_count + 1;
  227. }
  228. static inline int enic_dma_map_check(struct enic *enic, dma_addr_t dma_addr)
  229. {
  230. if (unlikely(pci_dma_mapping_error(enic->pdev, dma_addr))) {
  231. net_warn_ratelimited("%s: PCI dma mapping failed!\n",
  232. enic->netdev->name);
  233. enic->gen_stats.dma_map_error++;
  234. return -ENOMEM;
  235. }
  236. return 0;
  237. }
  238. void enic_reset_addr_lists(struct enic *enic);
  239. int enic_sriov_enabled(struct enic *enic);
  240. int enic_is_valid_vf(struct enic *enic, int vf);
  241. int enic_is_dynamic(struct enic *enic);
  242. void enic_set_ethtool_ops(struct net_device *netdev);
  243. int __enic_set_rsskey(struct enic *enic);
  244. #endif /* _ENIC_H_ */