enic.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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.20"
  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. /* Per-instance private data structure */
  121. struct enic {
  122. struct net_device *netdev;
  123. struct pci_dev *pdev;
  124. struct vnic_enet_config config;
  125. struct vnic_dev_bar bar[ENIC_BARS_MAX];
  126. struct vnic_dev *vdev;
  127. struct timer_list notify_timer;
  128. struct work_struct reset;
  129. struct work_struct tx_hang_reset;
  130. struct work_struct change_mtu_work;
  131. struct msix_entry msix_entry[ENIC_INTR_MAX];
  132. struct enic_msix_entry msix[ENIC_INTR_MAX];
  133. u32 msg_enable;
  134. spinlock_t devcmd_lock;
  135. u8 mac_addr[ETH_ALEN];
  136. unsigned int flags;
  137. unsigned int priv_flags;
  138. unsigned int mc_count;
  139. unsigned int uc_count;
  140. u32 port_mtu;
  141. struct enic_rx_coal rx_coalesce_setting;
  142. u32 rx_coalesce_usecs;
  143. u32 tx_coalesce_usecs;
  144. #ifdef CONFIG_PCI_IOV
  145. u16 num_vfs;
  146. #endif
  147. spinlock_t enic_api_lock;
  148. struct enic_port_profile *pp;
  149. /* work queue cache line section */
  150. ____cacheline_aligned struct vnic_wq wq[ENIC_WQ_MAX];
  151. spinlock_t wq_lock[ENIC_WQ_MAX];
  152. unsigned int wq_count;
  153. u16 loop_enable;
  154. u16 loop_tag;
  155. /* receive queue cache line section */
  156. ____cacheline_aligned struct vnic_rq rq[ENIC_RQ_MAX];
  157. unsigned int rq_count;
  158. u64 rq_truncated_pkts;
  159. u64 rq_bad_fcs;
  160. struct napi_struct napi[ENIC_RQ_MAX + ENIC_WQ_MAX];
  161. /* interrupt resource cache line section */
  162. ____cacheline_aligned struct vnic_intr intr[ENIC_INTR_MAX];
  163. unsigned int intr_count;
  164. u32 __iomem *legacy_pba; /* memory-mapped */
  165. /* completion queue cache line section */
  166. ____cacheline_aligned struct vnic_cq cq[ENIC_CQ_MAX];
  167. unsigned int cq_count;
  168. struct enic_rfs_flw_tbl rfs_h;
  169. u32 rx_copybreak;
  170. u8 rss_key[ENIC_RSS_LEN];
  171. struct vnic_gen_stats gen_stats;
  172. };
  173. static inline struct net_device *vnic_get_netdev(struct vnic_dev *vdev)
  174. {
  175. struct enic *enic = vdev->priv;
  176. return enic->netdev;
  177. }
  178. /* wrappers function for kernel log
  179. * Make sure variable vdev of struct vnic_dev is available in the block where
  180. * these macros are used
  181. */
  182. #define vdev_info(args...) dev_info(&vdev->pdev->dev, args)
  183. #define vdev_warn(args...) dev_warn(&vdev->pdev->dev, args)
  184. #define vdev_err(args...) dev_err(&vdev->pdev->dev, args)
  185. #define vdev_netinfo(args...) netdev_info(vnic_get_netdev(vdev), args)
  186. #define vdev_netwarn(args...) netdev_warn(vnic_get_netdev(vdev), args)
  187. #define vdev_neterr(args...) netdev_err(vnic_get_netdev(vdev), args)
  188. static inline struct device *enic_get_dev(struct enic *enic)
  189. {
  190. return &(enic->pdev->dev);
  191. }
  192. static inline unsigned int enic_cq_rq(struct enic *enic, unsigned int rq)
  193. {
  194. return rq;
  195. }
  196. static inline unsigned int enic_cq_wq(struct enic *enic, unsigned int wq)
  197. {
  198. return enic->rq_count + wq;
  199. }
  200. static inline unsigned int enic_legacy_io_intr(void)
  201. {
  202. return 0;
  203. }
  204. static inline unsigned int enic_legacy_err_intr(void)
  205. {
  206. return 1;
  207. }
  208. static inline unsigned int enic_legacy_notify_intr(void)
  209. {
  210. return 2;
  211. }
  212. static inline unsigned int enic_msix_rq_intr(struct enic *enic,
  213. unsigned int rq)
  214. {
  215. return enic->cq[enic_cq_rq(enic, rq)].interrupt_offset;
  216. }
  217. static inline unsigned int enic_msix_wq_intr(struct enic *enic,
  218. unsigned int wq)
  219. {
  220. return enic->cq[enic_cq_wq(enic, wq)].interrupt_offset;
  221. }
  222. static inline unsigned int enic_msix_err_intr(struct enic *enic)
  223. {
  224. return enic->rq_count + enic->wq_count;
  225. }
  226. static inline unsigned int enic_msix_notify_intr(struct enic *enic)
  227. {
  228. return enic->rq_count + enic->wq_count + 1;
  229. }
  230. static inline bool enic_is_err_intr(struct enic *enic, int intr)
  231. {
  232. switch (vnic_dev_get_intr_mode(enic->vdev)) {
  233. case VNIC_DEV_INTR_MODE_INTX:
  234. return intr == enic_legacy_err_intr();
  235. case VNIC_DEV_INTR_MODE_MSIX:
  236. return intr == enic_msix_err_intr(enic);
  237. case VNIC_DEV_INTR_MODE_MSI:
  238. default:
  239. return false;
  240. }
  241. }
  242. static inline bool enic_is_notify_intr(struct enic *enic, int intr)
  243. {
  244. switch (vnic_dev_get_intr_mode(enic->vdev)) {
  245. case VNIC_DEV_INTR_MODE_INTX:
  246. return intr == enic_legacy_notify_intr();
  247. case VNIC_DEV_INTR_MODE_MSIX:
  248. return intr == enic_msix_notify_intr(enic);
  249. case VNIC_DEV_INTR_MODE_MSI:
  250. default:
  251. return false;
  252. }
  253. }
  254. static inline int enic_dma_map_check(struct enic *enic, dma_addr_t dma_addr)
  255. {
  256. if (unlikely(pci_dma_mapping_error(enic->pdev, dma_addr))) {
  257. net_warn_ratelimited("%s: PCI dma mapping failed!\n",
  258. enic->netdev->name);
  259. enic->gen_stats.dma_map_error++;
  260. return -ENOMEM;
  261. }
  262. return 0;
  263. }
  264. void enic_reset_addr_lists(struct enic *enic);
  265. int enic_sriov_enabled(struct enic *enic);
  266. int enic_is_valid_vf(struct enic *enic, int vf);
  267. int enic_is_dynamic(struct enic *enic);
  268. void enic_set_ethtool_ops(struct net_device *netdev);
  269. int __enic_set_rsskey(struct enic *enic);
  270. #endif /* _ENIC_H_ */