common.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. /*****************************************************************************
  2. * *
  3. * File: common.h *
  4. * $Revision: 1.21 $ *
  5. * $Date: 2005/06/22 00:43:25 $ *
  6. * Description: *
  7. * part of the Chelsio 10Gb Ethernet Driver. *
  8. * *
  9. * This program is free software; you can redistribute it and/or modify *
  10. * it under the terms of the GNU General Public License, version 2, as *
  11. * published by the Free Software Foundation. *
  12. * *
  13. * You should have received a copy of the GNU General Public License along *
  14. * with this program; if not, write to the Free Software Foundation, Inc., *
  15. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  16. * *
  17. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED *
  18. * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF *
  19. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. *
  20. * *
  21. * http://www.chelsio.com *
  22. * *
  23. * Copyright (c) 2003 - 2005 Chelsio Communications, Inc. *
  24. * All rights reserved. *
  25. * *
  26. * Maintainers: maintainers@chelsio.com *
  27. * *
  28. * Authors: Dimitrios Michailidis <dm@chelsio.com> *
  29. * Tina Yang <tainay@chelsio.com> *
  30. * Felix Marti <felix@chelsio.com> *
  31. * Scott Bardone <sbardone@chelsio.com> *
  32. * Kurt Ottaway <kottaway@chelsio.com> *
  33. * Frank DiMambro <frank@chelsio.com> *
  34. * *
  35. * History: *
  36. * *
  37. ****************************************************************************/
  38. #ifndef _CXGB_COMMON_H_
  39. #define _CXGB_COMMON_H_
  40. #include <linux/module.h>
  41. #include <linux/netdevice.h>
  42. #include <linux/types.h>
  43. #include <linux/delay.h>
  44. #include <linux/pci.h>
  45. #include <linux/ethtool.h>
  46. #include <linux/mii.h>
  47. #include <linux/crc32.h>
  48. #include <linux/init.h>
  49. #include <asm/io.h>
  50. #include <linux/pci_ids.h>
  51. #define DRV_DESCRIPTION "Chelsio 10Gb Ethernet Driver"
  52. #define DRV_NAME "cxgb"
  53. #define DRV_VERSION "2.1.1"
  54. #define PFX DRV_NAME ": "
  55. #define CH_ERR(fmt, ...) printk(KERN_ERR PFX fmt, ## __VA_ARGS__)
  56. #define CH_WARN(fmt, ...) printk(KERN_WARNING PFX fmt, ## __VA_ARGS__)
  57. #define CH_ALERT(fmt, ...) printk(KERN_ALERT PFX fmt, ## __VA_ARGS__)
  58. #define CH_DEVICE(devid, ssid, idx) \
  59. { PCI_VENDOR_ID_CHELSIO, devid, PCI_ANY_ID, ssid, 0, 0, idx }
  60. #define SUPPORTED_PAUSE (1 << 13)
  61. #define SUPPORTED_LOOPBACK (1 << 15)
  62. #define ADVERTISED_PAUSE (1 << 13)
  63. #define ADVERTISED_ASYM_PAUSE (1 << 14)
  64. typedef struct adapter adapter_t;
  65. void t1_elmer0_ext_intr(adapter_t *adapter);
  66. void t1_link_changed(adapter_t *adapter, int port_id, int link_status,
  67. int speed, int duplex, int fc);
  68. struct t1_rx_mode {
  69. struct net_device *dev;
  70. u32 idx;
  71. struct dev_mc_list *list;
  72. };
  73. #define t1_rx_mode_promisc(rm) (rm->dev->flags & IFF_PROMISC)
  74. #define t1_rx_mode_allmulti(rm) (rm->dev->flags & IFF_ALLMULTI)
  75. #define t1_rx_mode_mc_cnt(rm) (rm->dev->mc_count)
  76. static inline u8 *t1_get_next_mcaddr(struct t1_rx_mode *rm)
  77. {
  78. u8 *addr = NULL;
  79. if (rm->idx++ < rm->dev->mc_count) {
  80. addr = rm->list->dmi_addr;
  81. rm->list = rm->list->next;
  82. }
  83. return addr;
  84. }
  85. #define MAX_NPORTS 4
  86. #define SPEED_INVALID 0xffff
  87. #define DUPLEX_INVALID 0xff
  88. enum {
  89. CHBT_BOARD_N110,
  90. CHBT_BOARD_N210
  91. };
  92. enum {
  93. CHBT_TERM_T1,
  94. CHBT_TERM_T2
  95. };
  96. enum {
  97. CHBT_MAC_PM3393,
  98. };
  99. enum {
  100. CHBT_PHY_88X2010,
  101. };
  102. enum {
  103. PAUSE_RX = 1 << 0,
  104. PAUSE_TX = 1 << 1,
  105. PAUSE_AUTONEG = 1 << 2
  106. };
  107. /* Revisions of T1 chip */
  108. enum {
  109. TERM_T1A = 0,
  110. TERM_T1B = 1,
  111. TERM_T2 = 3
  112. };
  113. struct sge_params {
  114. unsigned int cmdQ_size[2];
  115. unsigned int freelQ_size[2];
  116. unsigned int large_buf_capacity;
  117. unsigned int rx_coalesce_usecs;
  118. unsigned int last_rx_coalesce_raw;
  119. unsigned int default_rx_coalesce_usecs;
  120. unsigned int sample_interval_usecs;
  121. unsigned int coalesce_enable;
  122. unsigned int polling;
  123. };
  124. struct chelsio_pci_params {
  125. unsigned short speed;
  126. unsigned char width;
  127. unsigned char is_pcix;
  128. };
  129. struct adapter_params {
  130. struct sge_params sge;
  131. struct chelsio_pci_params pci;
  132. const struct board_info *brd_info;
  133. unsigned int nports; /* # of ethernet ports */
  134. unsigned int stats_update_period;
  135. unsigned short chip_revision;
  136. unsigned char chip_version;
  137. };
  138. struct link_config {
  139. unsigned int supported; /* link capabilities */
  140. unsigned int advertising; /* advertised capabilities */
  141. unsigned short requested_speed; /* speed user has requested */
  142. unsigned short speed; /* actual link speed */
  143. unsigned char requested_duplex; /* duplex user has requested */
  144. unsigned char duplex; /* actual link duplex */
  145. unsigned char requested_fc; /* flow control user has requested */
  146. unsigned char fc; /* actual link flow control */
  147. unsigned char autoneg; /* autonegotiating? */
  148. };
  149. struct cmac;
  150. struct cphy;
  151. struct port_info {
  152. struct net_device *dev;
  153. struct cmac *mac;
  154. struct cphy *phy;
  155. struct link_config link_config;
  156. struct net_device_stats netstats;
  157. };
  158. struct sge;
  159. struct peespi;
  160. struct adapter {
  161. u8 __iomem *regs;
  162. struct pci_dev *pdev;
  163. unsigned long registered_device_map;
  164. unsigned long open_device_map;
  165. unsigned long flags;
  166. const char *name;
  167. int msg_enable;
  168. u32 mmio_len;
  169. struct work_struct ext_intr_handler_task;
  170. struct adapter_params params;
  171. struct vlan_group *vlan_grp;
  172. /* Terminator modules. */
  173. struct sge *sge;
  174. struct peespi *espi;
  175. struct port_info port[MAX_NPORTS];
  176. struct work_struct stats_update_task;
  177. struct timer_list stats_update_timer;
  178. struct semaphore mib_mutex;
  179. spinlock_t tpi_lock;
  180. spinlock_t work_lock;
  181. /* guards async operations */
  182. spinlock_t async_lock ____cacheline_aligned;
  183. u32 slow_intr_mask;
  184. };
  185. enum { /* adapter flags */
  186. FULL_INIT_DONE = 1 << 0,
  187. TSO_CAPABLE = 1 << 2,
  188. TCP_CSUM_CAPABLE = 1 << 3,
  189. UDP_CSUM_CAPABLE = 1 << 4,
  190. VLAN_ACCEL_CAPABLE = 1 << 5,
  191. RX_CSUM_ENABLED = 1 << 6,
  192. };
  193. struct mdio_ops;
  194. struct gmac;
  195. struct gphy;
  196. struct board_info {
  197. unsigned char board;
  198. unsigned char port_number;
  199. unsigned long caps;
  200. unsigned char chip_term;
  201. unsigned char chip_mac;
  202. unsigned char chip_phy;
  203. unsigned int clock_core;
  204. unsigned int clock_mc3;
  205. unsigned int clock_mc4;
  206. unsigned int espi_nports;
  207. unsigned int clock_cspi;
  208. unsigned int clock_elmer0;
  209. unsigned char mdio_mdien;
  210. unsigned char mdio_mdiinv;
  211. unsigned char mdio_mdc;
  212. unsigned char mdio_phybaseaddr;
  213. struct gmac *gmac;
  214. struct gphy *gphy;
  215. struct mdio_ops *mdio_ops;
  216. const char *desc;
  217. };
  218. extern struct pci_device_id t1_pci_tbl[];
  219. static inline int adapter_matches_type(const adapter_t *adapter,
  220. int version, int revision)
  221. {
  222. return adapter->params.chip_version == version &&
  223. adapter->params.chip_revision == revision;
  224. }
  225. #define t1_is_T1B(adap) adapter_matches_type(adap, CHBT_TERM_T1, TERM_T1B)
  226. #define is_T2(adap) adapter_matches_type(adap, CHBT_TERM_T2, TERM_T2)
  227. /* Returns true if an adapter supports VLAN acceleration and TSO */
  228. static inline int vlan_tso_capable(const adapter_t *adapter)
  229. {
  230. return !t1_is_T1B(adapter);
  231. }
  232. #define for_each_port(adapter, iter) \
  233. for (iter = 0; iter < (adapter)->params.nports; ++iter)
  234. #define board_info(adapter) ((adapter)->params.brd_info)
  235. #define is_10G(adapter) (board_info(adapter)->caps & SUPPORTED_10000baseT_Full)
  236. static inline unsigned int core_ticks_per_usec(const adapter_t *adap)
  237. {
  238. return board_info(adap)->clock_core / 1000000;
  239. }
  240. extern int t1_tpi_write(adapter_t *adapter, u32 addr, u32 value);
  241. extern int t1_tpi_read(adapter_t *adapter, u32 addr, u32 *value);
  242. extern void t1_interrupts_enable(adapter_t *adapter);
  243. extern void t1_interrupts_disable(adapter_t *adapter);
  244. extern void t1_interrupts_clear(adapter_t *adapter);
  245. extern int elmer0_ext_intr_handler(adapter_t *adapter);
  246. extern int t1_slow_intr_handler(adapter_t *adapter);
  247. extern int t1_link_start(struct cphy *phy, struct cmac *mac, struct link_config *lc);
  248. extern const struct board_info *t1_get_board_info(unsigned int board_id);
  249. extern const struct board_info *t1_get_board_info_from_ids(unsigned int devid,
  250. unsigned short ssid);
  251. extern int t1_seeprom_read(adapter_t *adapter, u32 addr, u32 *data);
  252. extern int t1_get_board_rev(adapter_t *adapter, const struct board_info *bi,
  253. struct adapter_params *p);
  254. extern int t1_init_hw_modules(adapter_t *adapter);
  255. extern int t1_init_sw_modules(adapter_t *adapter, const struct board_info *bi);
  256. extern void t1_free_sw_modules(adapter_t *adapter);
  257. extern void t1_fatal_err(adapter_t *adapter);
  258. extern void t1_tp_set_udp_checksum_offload(adapter_t *adapter, int enable);
  259. extern void t1_tp_set_tcp_checksum_offload(adapter_t *adapter, int enable);
  260. extern void t1_tp_set_ip_checksum_offload(adapter_t *adapter, int enable);
  261. #endif /* _CXGB_COMMON_H_ */