common.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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. #define pr_fmt(fmt) "cxgb: " fmt
  39. #ifndef _CXGB_COMMON_H_
  40. #define _CXGB_COMMON_H_
  41. #include <linux/module.h>
  42. #include <linux/netdevice.h>
  43. #include <linux/types.h>
  44. #include <linux/delay.h>
  45. #include <linux/pci.h>
  46. #include <linux/ethtool.h>
  47. #include <linux/if_vlan.h>
  48. #include <linux/mdio.h>
  49. #include <linux/crc32.h>
  50. #include <linux/init.h>
  51. #include <linux/slab.h>
  52. #include <asm/io.h>
  53. #include <linux/pci_ids.h>
  54. #define DRV_DESCRIPTION "Chelsio 10Gb Ethernet Driver"
  55. #define DRV_NAME "cxgb"
  56. #define DRV_VERSION "2.2"
  57. #define CH_DEVICE(devid, ssid, idx) \
  58. { PCI_VENDOR_ID_CHELSIO, devid, PCI_ANY_ID, ssid, 0, 0, idx }
  59. #define SUPPORTED_PAUSE (1 << 13)
  60. #define SUPPORTED_LOOPBACK (1 << 15)
  61. #define ADVERTISED_PAUSE (1 << 13)
  62. #define ADVERTISED_ASYM_PAUSE (1 << 14)
  63. typedef struct adapter adapter_t;
  64. struct t1_rx_mode {
  65. struct net_device *dev;
  66. };
  67. #define t1_rx_mode_promisc(rm) (rm->dev->flags & IFF_PROMISC)
  68. #define t1_rx_mode_allmulti(rm) (rm->dev->flags & IFF_ALLMULTI)
  69. #define t1_rx_mode_mc_cnt(rm) (netdev_mc_count(rm->dev))
  70. #define t1_get_netdev(rm) (rm->dev)
  71. #define MAX_NPORTS 4
  72. #define PORT_MASK ((1 << MAX_NPORTS) - 1)
  73. #define NMTUS 8
  74. #define TCB_SIZE 128
  75. #define SPEED_INVALID 0xffff
  76. #define DUPLEX_INVALID 0xff
  77. enum {
  78. CHBT_BOARD_N110,
  79. CHBT_BOARD_N210,
  80. CHBT_BOARD_7500,
  81. CHBT_BOARD_8000,
  82. CHBT_BOARD_CHT101,
  83. CHBT_BOARD_CHT110,
  84. CHBT_BOARD_CHT210,
  85. CHBT_BOARD_CHT204,
  86. CHBT_BOARD_CHT204V,
  87. CHBT_BOARD_CHT204E,
  88. CHBT_BOARD_CHN204,
  89. CHBT_BOARD_COUGAR,
  90. CHBT_BOARD_6800,
  91. CHBT_BOARD_SIMUL,
  92. };
  93. enum {
  94. CHBT_TERM_FPGA,
  95. CHBT_TERM_T1,
  96. CHBT_TERM_T2,
  97. CHBT_TERM_T3
  98. };
  99. enum {
  100. CHBT_MAC_CHELSIO_A,
  101. CHBT_MAC_IXF1010,
  102. CHBT_MAC_PM3393,
  103. CHBT_MAC_VSC7321,
  104. CHBT_MAC_DUMMY
  105. };
  106. enum {
  107. CHBT_PHY_88E1041,
  108. CHBT_PHY_88E1111,
  109. CHBT_PHY_88X2010,
  110. CHBT_PHY_XPAK,
  111. CHBT_PHY_MY3126,
  112. CHBT_PHY_8244,
  113. CHBT_PHY_DUMMY
  114. };
  115. enum {
  116. PAUSE_RX = 1 << 0,
  117. PAUSE_TX = 1 << 1,
  118. PAUSE_AUTONEG = 1 << 2
  119. };
  120. /* Revisions of T1 chip */
  121. enum {
  122. TERM_T1A = 0,
  123. TERM_T1B = 1,
  124. TERM_T2 = 3
  125. };
  126. struct sge_params {
  127. unsigned int cmdQ_size[2];
  128. unsigned int freelQ_size[2];
  129. unsigned int large_buf_capacity;
  130. unsigned int rx_coalesce_usecs;
  131. unsigned int last_rx_coalesce_raw;
  132. unsigned int default_rx_coalesce_usecs;
  133. unsigned int sample_interval_usecs;
  134. unsigned int coalesce_enable;
  135. unsigned int polling;
  136. };
  137. struct chelsio_pci_params {
  138. unsigned short speed;
  139. unsigned char width;
  140. unsigned char is_pcix;
  141. };
  142. struct tp_params {
  143. unsigned int pm_size;
  144. unsigned int cm_size;
  145. unsigned int pm_rx_base;
  146. unsigned int pm_tx_base;
  147. unsigned int pm_rx_pg_size;
  148. unsigned int pm_tx_pg_size;
  149. unsigned int pm_rx_num_pgs;
  150. unsigned int pm_tx_num_pgs;
  151. unsigned int rx_coalescing_size;
  152. unsigned int use_5tuple_mode;
  153. };
  154. struct mc5_params {
  155. unsigned int mode; /* selects MC5 width */
  156. unsigned int nservers; /* size of server region */
  157. unsigned int nroutes; /* size of routing region */
  158. };
  159. /* Default MC5 region sizes */
  160. #define DEFAULT_SERVER_REGION_LEN 256
  161. #define DEFAULT_RT_REGION_LEN 1024
  162. struct adapter_params {
  163. struct sge_params sge;
  164. struct mc5_params mc5;
  165. struct tp_params tp;
  166. struct chelsio_pci_params pci;
  167. const struct board_info *brd_info;
  168. unsigned short mtus[NMTUS];
  169. unsigned int nports; /* # of ethernet ports */
  170. unsigned int stats_update_period;
  171. unsigned short chip_revision;
  172. unsigned char chip_version;
  173. unsigned char is_asic;
  174. unsigned char has_msi;
  175. };
  176. struct link_config {
  177. unsigned int supported; /* link capabilities */
  178. unsigned int advertising; /* advertised capabilities */
  179. unsigned short requested_speed; /* speed user has requested */
  180. unsigned short speed; /* actual link speed */
  181. unsigned char requested_duplex; /* duplex user has requested */
  182. unsigned char duplex; /* actual link duplex */
  183. unsigned char requested_fc; /* flow control user has requested */
  184. unsigned char fc; /* actual link flow control */
  185. unsigned char autoneg; /* autonegotiating? */
  186. };
  187. struct cmac;
  188. struct cphy;
  189. struct port_info {
  190. struct net_device *dev;
  191. struct cmac *mac;
  192. struct cphy *phy;
  193. struct link_config link_config;
  194. struct net_device_stats netstats;
  195. };
  196. struct sge;
  197. struct peespi;
  198. struct adapter {
  199. u8 __iomem *regs;
  200. struct pci_dev *pdev;
  201. unsigned long registered_device_map;
  202. unsigned long open_device_map;
  203. unsigned long flags;
  204. const char *name;
  205. int msg_enable;
  206. u32 mmio_len;
  207. struct work_struct ext_intr_handler_task;
  208. struct adapter_params params;
  209. /* Terminator modules. */
  210. struct sge *sge;
  211. struct peespi *espi;
  212. struct petp *tp;
  213. struct napi_struct napi;
  214. struct port_info port[MAX_NPORTS];
  215. struct delayed_work stats_update_task;
  216. struct timer_list stats_update_timer;
  217. spinlock_t tpi_lock;
  218. spinlock_t work_lock;
  219. spinlock_t mac_lock;
  220. /* guards async operations */
  221. spinlock_t async_lock ____cacheline_aligned;
  222. u32 slow_intr_mask;
  223. int t1powersave;
  224. };
  225. enum { /* adapter flags */
  226. FULL_INIT_DONE = 1 << 0,
  227. };
  228. struct mdio_ops;
  229. struct gmac;
  230. struct gphy;
  231. struct board_info {
  232. unsigned char board;
  233. unsigned char port_number;
  234. unsigned long caps;
  235. unsigned char chip_term;
  236. unsigned char chip_mac;
  237. unsigned char chip_phy;
  238. unsigned int clock_core;
  239. unsigned int clock_mc3;
  240. unsigned int clock_mc4;
  241. unsigned int espi_nports;
  242. unsigned int clock_elmer0;
  243. unsigned char mdio_mdien;
  244. unsigned char mdio_mdiinv;
  245. unsigned char mdio_mdc;
  246. unsigned char mdio_phybaseaddr;
  247. const struct gmac *gmac;
  248. const struct gphy *gphy;
  249. const struct mdio_ops *mdio_ops;
  250. const char *desc;
  251. };
  252. static inline int t1_is_asic(const adapter_t *adapter)
  253. {
  254. return adapter->params.is_asic;
  255. }
  256. extern const struct pci_device_id t1_pci_tbl[];
  257. static inline int adapter_matches_type(const adapter_t *adapter,
  258. int version, int revision)
  259. {
  260. return adapter->params.chip_version == version &&
  261. adapter->params.chip_revision == revision;
  262. }
  263. #define t1_is_T1B(adap) adapter_matches_type(adap, CHBT_TERM_T1, TERM_T1B)
  264. #define is_T2(adap) adapter_matches_type(adap, CHBT_TERM_T2, TERM_T2)
  265. /* Returns true if an adapter supports VLAN acceleration and TSO */
  266. static inline int vlan_tso_capable(const adapter_t *adapter)
  267. {
  268. return !t1_is_T1B(adapter);
  269. }
  270. #define for_each_port(adapter, iter) \
  271. for (iter = 0; iter < (adapter)->params.nports; ++iter)
  272. #define board_info(adapter) ((adapter)->params.brd_info)
  273. #define is_10G(adapter) (board_info(adapter)->caps & SUPPORTED_10000baseT_Full)
  274. static inline unsigned int core_ticks_per_usec(const adapter_t *adap)
  275. {
  276. return board_info(adap)->clock_core / 1000000;
  277. }
  278. extern int __t1_tpi_read(adapter_t *adapter, u32 addr, u32 *valp);
  279. extern int __t1_tpi_write(adapter_t *adapter, u32 addr, u32 value);
  280. extern int t1_tpi_write(adapter_t *adapter, u32 addr, u32 value);
  281. extern int t1_tpi_read(adapter_t *adapter, u32 addr, u32 *value);
  282. extern void t1_interrupts_enable(adapter_t *adapter);
  283. extern void t1_interrupts_disable(adapter_t *adapter);
  284. extern void t1_interrupts_clear(adapter_t *adapter);
  285. extern int t1_elmer0_ext_intr_handler(adapter_t *adapter);
  286. extern void t1_elmer0_ext_intr(adapter_t *adapter);
  287. extern int t1_slow_intr_handler(adapter_t *adapter);
  288. extern int t1_link_start(struct cphy *phy, struct cmac *mac, struct link_config *lc);
  289. extern const struct board_info *t1_get_board_info(unsigned int board_id);
  290. extern const struct board_info *t1_get_board_info_from_ids(unsigned int devid,
  291. unsigned short ssid);
  292. extern int t1_seeprom_read(adapter_t *adapter, u32 addr, __le32 *data);
  293. extern int t1_get_board_rev(adapter_t *adapter, const struct board_info *bi,
  294. struct adapter_params *p);
  295. extern int t1_init_hw_modules(adapter_t *adapter);
  296. extern int t1_init_sw_modules(adapter_t *adapter, const struct board_info *bi);
  297. extern void t1_free_sw_modules(adapter_t *adapter);
  298. extern void t1_fatal_err(adapter_t *adapter);
  299. extern void t1_link_changed(adapter_t *adapter, int port_id);
  300. extern void t1_link_negotiated(adapter_t *adapter, int port_id, int link_stat,
  301. int speed, int duplex, int pause);
  302. #endif /* _CXGB_COMMON_H_ */