common.h 11 KB

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