common.h 11 KB

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