enic.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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.31"
  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. cpumask_var_t affinity_mask;
  47. };
  48. /* Store only the lower range. Higher range is given by fw. */
  49. struct enic_intr_mod_range {
  50. u32 small_pkt_range_start;
  51. u32 large_pkt_range_start;
  52. };
  53. struct enic_intr_mod_table {
  54. u32 rx_rate;
  55. u32 range_percent;
  56. };
  57. #define ENIC_MAX_LINK_SPEEDS 3
  58. #define ENIC_LINK_SPEED_10G 10000
  59. #define ENIC_LINK_SPEED_4G 4000
  60. #define ENIC_LINK_40G_INDEX 2
  61. #define ENIC_LINK_10G_INDEX 1
  62. #define ENIC_LINK_4G_INDEX 0
  63. #define ENIC_RX_COALESCE_RANGE_END 125
  64. #define ENIC_AIC_TS_BREAK 100
  65. struct enic_rx_coal {
  66. u32 small_pkt_range_start;
  67. u32 large_pkt_range_start;
  68. u32 range_end;
  69. u32 use_adaptive_rx_coalesce;
  70. };
  71. /* priv_flags */
  72. #define ENIC_SRIOV_ENABLED (1 << 0)
  73. /* enic port profile set flags */
  74. #define ENIC_PORT_REQUEST_APPLIED (1 << 0)
  75. #define ENIC_SET_REQUEST (1 << 1)
  76. #define ENIC_SET_NAME (1 << 2)
  77. #define ENIC_SET_INSTANCE (1 << 3)
  78. #define ENIC_SET_HOST (1 << 4)
  79. struct enic_port_profile {
  80. u32 set;
  81. u8 request;
  82. char name[PORT_PROFILE_MAX];
  83. u8 instance_uuid[PORT_UUID_MAX];
  84. u8 host_uuid[PORT_UUID_MAX];
  85. u8 vf_mac[ETH_ALEN];
  86. u8 mac_addr[ETH_ALEN];
  87. };
  88. /* enic_rfs_fltr_node - rfs filter node in hash table
  89. * @@keys: IPv4 5 tuple
  90. * @flow_id: flow_id of clsf filter provided by kernel
  91. * @fltr_id: filter id of clsf filter returned by adaptor
  92. * @rq_id: desired rq index
  93. * @node: hlist_node
  94. */
  95. struct enic_rfs_fltr_node {
  96. struct flow_keys keys;
  97. u32 flow_id;
  98. u16 fltr_id;
  99. u16 rq_id;
  100. struct hlist_node node;
  101. };
  102. /* enic_rfs_flw_tbl - rfs flow table
  103. * @max: Maximum number of filters vNIC supports
  104. * @free: Number of free filters available
  105. * @toclean: hash table index to clean next
  106. * @ht_head: hash table list head
  107. * @lock: spin lock
  108. * @rfs_may_expire: timer function for enic_rps_may_expire_flow
  109. */
  110. struct enic_rfs_flw_tbl {
  111. u16 max;
  112. int free;
  113. #define ENIC_RFS_FLW_BITSHIFT (10)
  114. #define ENIC_RFS_FLW_MASK ((1 << ENIC_RFS_FLW_BITSHIFT) - 1)
  115. u16 toclean:ENIC_RFS_FLW_BITSHIFT;
  116. struct hlist_head ht_head[1 << ENIC_RFS_FLW_BITSHIFT];
  117. spinlock_t lock;
  118. struct timer_list rfs_may_expire;
  119. };
  120. struct vxlan_offload {
  121. u16 vxlan_udp_port_number;
  122. u8 patch_level;
  123. };
  124. /* Per-instance private data structure */
  125. struct enic {
  126. struct net_device *netdev;
  127. struct pci_dev *pdev;
  128. struct vnic_enet_config config;
  129. struct vnic_dev_bar bar[ENIC_BARS_MAX];
  130. struct vnic_dev *vdev;
  131. struct timer_list notify_timer;
  132. struct work_struct reset;
  133. struct work_struct tx_hang_reset;
  134. struct work_struct change_mtu_work;
  135. struct msix_entry msix_entry[ENIC_INTR_MAX];
  136. struct enic_msix_entry msix[ENIC_INTR_MAX];
  137. u32 msg_enable;
  138. spinlock_t devcmd_lock;
  139. u8 mac_addr[ETH_ALEN];
  140. unsigned int flags;
  141. unsigned int priv_flags;
  142. unsigned int mc_count;
  143. unsigned int uc_count;
  144. u32 port_mtu;
  145. struct enic_rx_coal rx_coalesce_setting;
  146. u32 rx_coalesce_usecs;
  147. u32 tx_coalesce_usecs;
  148. #ifdef CONFIG_PCI_IOV
  149. u16 num_vfs;
  150. #endif
  151. spinlock_t enic_api_lock;
  152. struct enic_port_profile *pp;
  153. /* work queue cache line section */
  154. ____cacheline_aligned struct vnic_wq wq[ENIC_WQ_MAX];
  155. spinlock_t wq_lock[ENIC_WQ_MAX];
  156. unsigned int wq_count;
  157. u16 loop_enable;
  158. u16 loop_tag;
  159. /* receive queue cache line section */
  160. ____cacheline_aligned struct vnic_rq rq[ENIC_RQ_MAX];
  161. unsigned int rq_count;
  162. struct vxlan_offload vxlan;
  163. u64 rq_truncated_pkts;
  164. u64 rq_bad_fcs;
  165. struct napi_struct napi[ENIC_RQ_MAX + ENIC_WQ_MAX];
  166. /* interrupt resource cache line section */
  167. ____cacheline_aligned struct vnic_intr intr[ENIC_INTR_MAX];
  168. unsigned int intr_count;
  169. u32 __iomem *legacy_pba; /* memory-mapped */
  170. /* completion queue cache line section */
  171. ____cacheline_aligned struct vnic_cq cq[ENIC_CQ_MAX];
  172. unsigned int cq_count;
  173. struct enic_rfs_flw_tbl rfs_h;
  174. u32 rx_copybreak;
  175. u8 rss_key[ENIC_RSS_LEN];
  176. struct vnic_gen_stats gen_stats;
  177. };
  178. static inline struct net_device *vnic_get_netdev(struct vnic_dev *vdev)
  179. {
  180. struct enic *enic = vdev->priv;
  181. return enic->netdev;
  182. }
  183. /* wrappers function for kernel log
  184. */
  185. #define vdev_err(vdev, fmt, ...) \
  186. dev_err(&(vdev)->pdev->dev, fmt, ##__VA_ARGS__)
  187. #define vdev_warn(vdev, fmt, ...) \
  188. dev_warn(&(vdev)->pdev->dev, fmt, ##__VA_ARGS__)
  189. #define vdev_info(vdev, fmt, ...) \
  190. dev_info(&(vdev)->pdev->dev, fmt, ##__VA_ARGS__)
  191. #define vdev_neterr(vdev, fmt, ...) \
  192. netdev_err(vnic_get_netdev(vdev), fmt, ##__VA_ARGS__)
  193. #define vdev_netwarn(vdev, fmt, ...) \
  194. netdev_warn(vnic_get_netdev(vdev), fmt, ##__VA_ARGS__)
  195. #define vdev_netinfo(vdev, fmt, ...) \
  196. netdev_info(vnic_get_netdev(vdev), fmt, ##__VA_ARGS__)
  197. static inline struct device *enic_get_dev(struct enic *enic)
  198. {
  199. return &(enic->pdev->dev);
  200. }
  201. static inline unsigned int enic_cq_rq(struct enic *enic, unsigned int rq)
  202. {
  203. return rq;
  204. }
  205. static inline unsigned int enic_cq_wq(struct enic *enic, unsigned int wq)
  206. {
  207. return enic->rq_count + wq;
  208. }
  209. static inline unsigned int enic_legacy_io_intr(void)
  210. {
  211. return 0;
  212. }
  213. static inline unsigned int enic_legacy_err_intr(void)
  214. {
  215. return 1;
  216. }
  217. static inline unsigned int enic_legacy_notify_intr(void)
  218. {
  219. return 2;
  220. }
  221. static inline unsigned int enic_msix_rq_intr(struct enic *enic,
  222. unsigned int rq)
  223. {
  224. return enic->cq[enic_cq_rq(enic, rq)].interrupt_offset;
  225. }
  226. static inline unsigned int enic_msix_wq_intr(struct enic *enic,
  227. unsigned int wq)
  228. {
  229. return enic->cq[enic_cq_wq(enic, wq)].interrupt_offset;
  230. }
  231. static inline unsigned int enic_msix_err_intr(struct enic *enic)
  232. {
  233. return enic->rq_count + enic->wq_count;
  234. }
  235. static inline unsigned int enic_msix_notify_intr(struct enic *enic)
  236. {
  237. return enic->rq_count + enic->wq_count + 1;
  238. }
  239. static inline bool enic_is_err_intr(struct enic *enic, int intr)
  240. {
  241. switch (vnic_dev_get_intr_mode(enic->vdev)) {
  242. case VNIC_DEV_INTR_MODE_INTX:
  243. return intr == enic_legacy_err_intr();
  244. case VNIC_DEV_INTR_MODE_MSIX:
  245. return intr == enic_msix_err_intr(enic);
  246. case VNIC_DEV_INTR_MODE_MSI:
  247. default:
  248. return false;
  249. }
  250. }
  251. static inline bool enic_is_notify_intr(struct enic *enic, int intr)
  252. {
  253. switch (vnic_dev_get_intr_mode(enic->vdev)) {
  254. case VNIC_DEV_INTR_MODE_INTX:
  255. return intr == enic_legacy_notify_intr();
  256. case VNIC_DEV_INTR_MODE_MSIX:
  257. return intr == enic_msix_notify_intr(enic);
  258. case VNIC_DEV_INTR_MODE_MSI:
  259. default:
  260. return false;
  261. }
  262. }
  263. static inline int enic_dma_map_check(struct enic *enic, dma_addr_t dma_addr)
  264. {
  265. if (unlikely(pci_dma_mapping_error(enic->pdev, dma_addr))) {
  266. net_warn_ratelimited("%s: PCI dma mapping failed!\n",
  267. enic->netdev->name);
  268. enic->gen_stats.dma_map_error++;
  269. return -ENOMEM;
  270. }
  271. return 0;
  272. }
  273. void enic_reset_addr_lists(struct enic *enic);
  274. int enic_sriov_enabled(struct enic *enic);
  275. int enic_is_valid_vf(struct enic *enic, int vf);
  276. int enic_is_dynamic(struct enic *enic);
  277. void enic_set_ethtool_ops(struct net_device *netdev);
  278. int __enic_set_rsskey(struct enic *enic);
  279. #endif /* _ENIC_H_ */