common.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. /*
  2. * Copyright (c) 2005-2008 Chelsio, Inc. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #ifndef __CHELSIO_COMMON_H
  33. #define __CHELSIO_COMMON_H
  34. #include <linux/kernel.h>
  35. #include <linux/types.h>
  36. #include <linux/ctype.h>
  37. #include <linux/delay.h>
  38. #include <linux/netdevice.h>
  39. #include <linux/ethtool.h>
  40. #include <linux/mdio.h>
  41. #include "version.h"
  42. #define CH_ERR(adap, fmt, ...) dev_err(&adap->pdev->dev, fmt, ##__VA_ARGS__)
  43. #define CH_WARN(adap, fmt, ...) dev_warn(&adap->pdev->dev, fmt, ##__VA_ARGS__)
  44. #define CH_ALERT(adap, fmt, ...) dev_alert(&adap->pdev->dev, fmt, ##__VA_ARGS__)
  45. /*
  46. * More powerful macro that selectively prints messages based on msg_enable.
  47. * For info and debugging messages.
  48. */
  49. #define CH_MSG(adapter, level, category, fmt, ...) do { \
  50. if ((adapter)->msg_enable & NETIF_MSG_##category) \
  51. dev_printk(KERN_##level, &adapter->pdev->dev, fmt, \
  52. ## __VA_ARGS__); \
  53. } while (0)
  54. #ifdef DEBUG
  55. # define CH_DBG(adapter, category, fmt, ...) \
  56. CH_MSG(adapter, DEBUG, category, fmt, ## __VA_ARGS__)
  57. #else
  58. # define CH_DBG(adapter, category, fmt, ...)
  59. #endif
  60. /* Additional NETIF_MSG_* categories */
  61. #define NETIF_MSG_MMIO 0x8000000
  62. enum {
  63. MAX_NPORTS = 2, /* max # of ports */
  64. MAX_FRAME_SIZE = 10240, /* max MAC frame size, including header + FCS */
  65. EEPROMSIZE = 8192, /* Serial EEPROM size */
  66. SERNUM_LEN = 16, /* Serial # length */
  67. RSS_TABLE_SIZE = 64, /* size of RSS lookup and mapping tables */
  68. TCB_SIZE = 128, /* TCB size */
  69. NMTUS = 16, /* size of MTU table */
  70. NCCTRL_WIN = 32, /* # of congestion control windows */
  71. PROTO_SRAM_LINES = 128, /* size of TP sram */
  72. };
  73. #define MAX_RX_COALESCING_LEN 12288U
  74. enum {
  75. PAUSE_RX = 1 << 0,
  76. PAUSE_TX = 1 << 1,
  77. PAUSE_AUTONEG = 1 << 2
  78. };
  79. enum {
  80. SUPPORTED_IRQ = 1 << 24
  81. };
  82. enum { /* adapter interrupt-maintained statistics */
  83. STAT_ULP_CH0_PBL_OOB,
  84. STAT_ULP_CH1_PBL_OOB,
  85. STAT_PCI_CORR_ECC,
  86. IRQ_NUM_STATS /* keep last */
  87. };
  88. #define TP_VERSION_MAJOR 1
  89. #define TP_VERSION_MINOR 1
  90. #define TP_VERSION_MICRO 0
  91. #define S_TP_VERSION_MAJOR 16
  92. #define M_TP_VERSION_MAJOR 0xFF
  93. #define V_TP_VERSION_MAJOR(x) ((x) << S_TP_VERSION_MAJOR)
  94. #define G_TP_VERSION_MAJOR(x) \
  95. (((x) >> S_TP_VERSION_MAJOR) & M_TP_VERSION_MAJOR)
  96. #define S_TP_VERSION_MINOR 8
  97. #define M_TP_VERSION_MINOR 0xFF
  98. #define V_TP_VERSION_MINOR(x) ((x) << S_TP_VERSION_MINOR)
  99. #define G_TP_VERSION_MINOR(x) \
  100. (((x) >> S_TP_VERSION_MINOR) & M_TP_VERSION_MINOR)
  101. #define S_TP_VERSION_MICRO 0
  102. #define M_TP_VERSION_MICRO 0xFF
  103. #define V_TP_VERSION_MICRO(x) ((x) << S_TP_VERSION_MICRO)
  104. #define G_TP_VERSION_MICRO(x) \
  105. (((x) >> S_TP_VERSION_MICRO) & M_TP_VERSION_MICRO)
  106. enum {
  107. SGE_QSETS = 8, /* # of SGE Tx/Rx/RspQ sets */
  108. SGE_RXQ_PER_SET = 2, /* # of Rx queues per set */
  109. SGE_TXQ_PER_SET = 3 /* # of Tx queues per set */
  110. };
  111. enum sge_context_type { /* SGE egress context types */
  112. SGE_CNTXT_RDMA = 0,
  113. SGE_CNTXT_ETH = 2,
  114. SGE_CNTXT_OFLD = 4,
  115. SGE_CNTXT_CTRL = 5
  116. };
  117. enum {
  118. AN_PKT_SIZE = 32, /* async notification packet size */
  119. IMMED_PKT_SIZE = 48 /* packet size for immediate data */
  120. };
  121. struct sg_ent { /* SGE scatter/gather entry */
  122. __be32 len[2];
  123. __be64 addr[2];
  124. };
  125. #ifndef SGE_NUM_GENBITS
  126. /* Must be 1 or 2 */
  127. # define SGE_NUM_GENBITS 2
  128. #endif
  129. #define TX_DESC_FLITS 16U
  130. #define WR_FLITS (TX_DESC_FLITS + 1 - SGE_NUM_GENBITS)
  131. struct cphy;
  132. struct adapter;
  133. struct mdio_ops {
  134. int (*read)(struct net_device *dev, int phy_addr, int mmd_addr,
  135. u16 reg_addr);
  136. int (*write)(struct net_device *dev, int phy_addr, int mmd_addr,
  137. u16 reg_addr, u16 val);
  138. unsigned mode_support;
  139. };
  140. struct adapter_info {
  141. unsigned char nports0; /* # of ports on channel 0 */
  142. unsigned char nports1; /* # of ports on channel 1 */
  143. unsigned char phy_base_addr; /* MDIO PHY base address */
  144. unsigned int gpio_out; /* GPIO output settings */
  145. unsigned char gpio_intr[MAX_NPORTS]; /* GPIO PHY IRQ pins */
  146. unsigned long caps; /* adapter capabilities */
  147. const struct mdio_ops *mdio_ops; /* MDIO operations */
  148. const char *desc; /* product description */
  149. };
  150. struct mc5_stats {
  151. unsigned long parity_err;
  152. unsigned long active_rgn_full;
  153. unsigned long nfa_srch_err;
  154. unsigned long unknown_cmd;
  155. unsigned long reqq_parity_err;
  156. unsigned long dispq_parity_err;
  157. unsigned long del_act_empty;
  158. };
  159. struct mc7_stats {
  160. unsigned long corr_err;
  161. unsigned long uncorr_err;
  162. unsigned long parity_err;
  163. unsigned long addr_err;
  164. };
  165. struct mac_stats {
  166. u64 tx_octets; /* total # of octets in good frames */
  167. u64 tx_octets_bad; /* total # of octets in error frames */
  168. u64 tx_frames; /* all good frames */
  169. u64 tx_mcast_frames; /* good multicast frames */
  170. u64 tx_bcast_frames; /* good broadcast frames */
  171. u64 tx_pause; /* # of transmitted pause frames */
  172. u64 tx_deferred; /* frames with deferred transmissions */
  173. u64 tx_late_collisions; /* # of late collisions */
  174. u64 tx_total_collisions; /* # of total collisions */
  175. u64 tx_excess_collisions; /* frame errors from excessive collissions */
  176. u64 tx_underrun; /* # of Tx FIFO underruns */
  177. u64 tx_len_errs; /* # of Tx length errors */
  178. u64 tx_mac_internal_errs; /* # of internal MAC errors on Tx */
  179. u64 tx_excess_deferral; /* # of frames with excessive deferral */
  180. u64 tx_fcs_errs; /* # of frames with bad FCS */
  181. u64 tx_frames_64; /* # of Tx frames in a particular range */
  182. u64 tx_frames_65_127;
  183. u64 tx_frames_128_255;
  184. u64 tx_frames_256_511;
  185. u64 tx_frames_512_1023;
  186. u64 tx_frames_1024_1518;
  187. u64 tx_frames_1519_max;
  188. u64 rx_octets; /* total # of octets in good frames */
  189. u64 rx_octets_bad; /* total # of octets in error frames */
  190. u64 rx_frames; /* all good frames */
  191. u64 rx_mcast_frames; /* good multicast frames */
  192. u64 rx_bcast_frames; /* good broadcast frames */
  193. u64 rx_pause; /* # of received pause frames */
  194. u64 rx_fcs_errs; /* # of received frames with bad FCS */
  195. u64 rx_align_errs; /* alignment errors */
  196. u64 rx_symbol_errs; /* symbol errors */
  197. u64 rx_data_errs; /* data errors */
  198. u64 rx_sequence_errs; /* sequence errors */
  199. u64 rx_runt; /* # of runt frames */
  200. u64 rx_jabber; /* # of jabber frames */
  201. u64 rx_short; /* # of short frames */
  202. u64 rx_too_long; /* # of oversized frames */
  203. u64 rx_mac_internal_errs; /* # of internal MAC errors on Rx */
  204. u64 rx_frames_64; /* # of Rx frames in a particular range */
  205. u64 rx_frames_65_127;
  206. u64 rx_frames_128_255;
  207. u64 rx_frames_256_511;
  208. u64 rx_frames_512_1023;
  209. u64 rx_frames_1024_1518;
  210. u64 rx_frames_1519_max;
  211. u64 rx_cong_drops; /* # of Rx drops due to SGE congestion */
  212. unsigned long tx_fifo_parity_err;
  213. unsigned long rx_fifo_parity_err;
  214. unsigned long tx_fifo_urun;
  215. unsigned long rx_fifo_ovfl;
  216. unsigned long serdes_signal_loss;
  217. unsigned long xaui_pcs_ctc_err;
  218. unsigned long xaui_pcs_align_change;
  219. unsigned long num_toggled; /* # times toggled TxEn due to stuck TX */
  220. unsigned long num_resets; /* # times reset due to stuck TX */
  221. unsigned long link_faults; /* # detected link faults */
  222. };
  223. struct tp_mib_stats {
  224. u32 ipInReceive_hi;
  225. u32 ipInReceive_lo;
  226. u32 ipInHdrErrors_hi;
  227. u32 ipInHdrErrors_lo;
  228. u32 ipInAddrErrors_hi;
  229. u32 ipInAddrErrors_lo;
  230. u32 ipInUnknownProtos_hi;
  231. u32 ipInUnknownProtos_lo;
  232. u32 ipInDiscards_hi;
  233. u32 ipInDiscards_lo;
  234. u32 ipInDelivers_hi;
  235. u32 ipInDelivers_lo;
  236. u32 ipOutRequests_hi;
  237. u32 ipOutRequests_lo;
  238. u32 ipOutDiscards_hi;
  239. u32 ipOutDiscards_lo;
  240. u32 ipOutNoRoutes_hi;
  241. u32 ipOutNoRoutes_lo;
  242. u32 ipReasmTimeout;
  243. u32 ipReasmReqds;
  244. u32 ipReasmOKs;
  245. u32 ipReasmFails;
  246. u32 reserved[8];
  247. u32 tcpActiveOpens;
  248. u32 tcpPassiveOpens;
  249. u32 tcpAttemptFails;
  250. u32 tcpEstabResets;
  251. u32 tcpOutRsts;
  252. u32 tcpCurrEstab;
  253. u32 tcpInSegs_hi;
  254. u32 tcpInSegs_lo;
  255. u32 tcpOutSegs_hi;
  256. u32 tcpOutSegs_lo;
  257. u32 tcpRetransSeg_hi;
  258. u32 tcpRetransSeg_lo;
  259. u32 tcpInErrs_hi;
  260. u32 tcpInErrs_lo;
  261. u32 tcpRtoMin;
  262. u32 tcpRtoMax;
  263. };
  264. struct tp_params {
  265. unsigned int nchan; /* # of channels */
  266. unsigned int pmrx_size; /* total PMRX capacity */
  267. unsigned int pmtx_size; /* total PMTX capacity */
  268. unsigned int cm_size; /* total CM capacity */
  269. unsigned int chan_rx_size; /* per channel Rx size */
  270. unsigned int chan_tx_size; /* per channel Tx size */
  271. unsigned int rx_pg_size; /* Rx page size */
  272. unsigned int tx_pg_size; /* Tx page size */
  273. unsigned int rx_num_pgs; /* # of Rx pages */
  274. unsigned int tx_num_pgs; /* # of Tx pages */
  275. unsigned int ntimer_qs; /* # of timer queues */
  276. };
  277. struct qset_params { /* SGE queue set parameters */
  278. unsigned int polling; /* polling/interrupt service for rspq */
  279. unsigned int coalesce_usecs; /* irq coalescing timer */
  280. unsigned int rspq_size; /* # of entries in response queue */
  281. unsigned int fl_size; /* # of entries in regular free list */
  282. unsigned int jumbo_size; /* # of entries in jumbo free list */
  283. unsigned int txq_size[SGE_TXQ_PER_SET]; /* Tx queue sizes */
  284. unsigned int cong_thres; /* FL congestion threshold */
  285. unsigned int vector; /* Interrupt (line or vector) number */
  286. };
  287. struct sge_params {
  288. unsigned int max_pkt_size; /* max offload pkt size */
  289. struct qset_params qset[SGE_QSETS];
  290. };
  291. struct mc5_params {
  292. unsigned int mode; /* selects MC5 width */
  293. unsigned int nservers; /* size of server region */
  294. unsigned int nfilters; /* size of filter region */
  295. unsigned int nroutes; /* size of routing region */
  296. };
  297. /* Default MC5 region sizes */
  298. enum {
  299. DEFAULT_NSERVERS = 512,
  300. DEFAULT_NFILTERS = 128
  301. };
  302. /* MC5 modes, these must be non-0 */
  303. enum {
  304. MC5_MODE_144_BIT = 1,
  305. MC5_MODE_72_BIT = 2
  306. };
  307. /* MC5 min active region size */
  308. enum { MC5_MIN_TIDS = 16 };
  309. struct vpd_params {
  310. unsigned int cclk;
  311. unsigned int mclk;
  312. unsigned int uclk;
  313. unsigned int mdc;
  314. unsigned int mem_timing;
  315. u8 sn[SERNUM_LEN + 1];
  316. u8 eth_base[6];
  317. u8 port_type[MAX_NPORTS];
  318. unsigned short xauicfg[2];
  319. };
  320. struct pci_params {
  321. unsigned int vpd_cap_addr;
  322. unsigned short speed;
  323. unsigned char width;
  324. unsigned char variant;
  325. };
  326. enum {
  327. PCI_VARIANT_PCI,
  328. PCI_VARIANT_PCIX_MODE1_PARITY,
  329. PCI_VARIANT_PCIX_MODE1_ECC,
  330. PCI_VARIANT_PCIX_266_MODE2,
  331. PCI_VARIANT_PCIE
  332. };
  333. struct adapter_params {
  334. struct sge_params sge;
  335. struct mc5_params mc5;
  336. struct tp_params tp;
  337. struct vpd_params vpd;
  338. struct pci_params pci;
  339. const struct adapter_info *info;
  340. unsigned short mtus[NMTUS];
  341. unsigned short a_wnd[NCCTRL_WIN];
  342. unsigned short b_wnd[NCCTRL_WIN];
  343. unsigned int nports; /* # of ethernet ports */
  344. unsigned int chan_map; /* bitmap of in-use Tx channels */
  345. unsigned int stats_update_period; /* MAC stats accumulation period */
  346. unsigned int linkpoll_period; /* link poll period in 0.1s */
  347. unsigned int rev; /* chip revision */
  348. unsigned int offload;
  349. };
  350. enum { /* chip revisions */
  351. T3_REV_A = 0,
  352. T3_REV_B = 2,
  353. T3_REV_B2 = 3,
  354. T3_REV_C = 4,
  355. };
  356. struct trace_params {
  357. u32 sip;
  358. u32 sip_mask;
  359. u32 dip;
  360. u32 dip_mask;
  361. u16 sport;
  362. u16 sport_mask;
  363. u16 dport;
  364. u16 dport_mask;
  365. u32 vlan:12;
  366. u32 vlan_mask:12;
  367. u32 intf:4;
  368. u32 intf_mask:4;
  369. u8 proto;
  370. u8 proto_mask;
  371. };
  372. struct link_config {
  373. unsigned int supported; /* link capabilities */
  374. unsigned int advertising; /* advertised capabilities */
  375. unsigned short requested_speed; /* speed user has requested */
  376. unsigned short speed; /* actual link speed */
  377. unsigned char requested_duplex; /* duplex user has requested */
  378. unsigned char duplex; /* actual link duplex */
  379. unsigned char requested_fc; /* flow control user has requested */
  380. unsigned char fc; /* actual link flow control */
  381. unsigned char autoneg; /* autonegotiating? */
  382. unsigned int link_ok; /* link up? */
  383. };
  384. #define SPEED_INVALID 0xffff
  385. #define DUPLEX_INVALID 0xff
  386. struct mc5 {
  387. struct adapter *adapter;
  388. unsigned int tcam_size;
  389. unsigned char part_type;
  390. unsigned char parity_enabled;
  391. unsigned char mode;
  392. struct mc5_stats stats;
  393. };
  394. static inline unsigned int t3_mc5_size(const struct mc5 *p)
  395. {
  396. return p->tcam_size;
  397. }
  398. struct mc7 {
  399. struct adapter *adapter; /* backpointer to adapter */
  400. unsigned int size; /* memory size in bytes */
  401. unsigned int width; /* MC7 interface width */
  402. unsigned int offset; /* register address offset for MC7 instance */
  403. const char *name; /* name of MC7 instance */
  404. struct mc7_stats stats; /* MC7 statistics */
  405. };
  406. static inline unsigned int t3_mc7_size(const struct mc7 *p)
  407. {
  408. return p->size;
  409. }
  410. struct cmac {
  411. struct adapter *adapter;
  412. unsigned int offset;
  413. unsigned int nucast; /* # of address filters for unicast MACs */
  414. unsigned int tx_tcnt;
  415. unsigned int tx_xcnt;
  416. u64 tx_mcnt;
  417. unsigned int rx_xcnt;
  418. unsigned int rx_ocnt;
  419. u64 rx_mcnt;
  420. unsigned int toggle_cnt;
  421. unsigned int txen;
  422. u64 rx_pause;
  423. struct mac_stats stats;
  424. };
  425. enum {
  426. MAC_DIRECTION_RX = 1,
  427. MAC_DIRECTION_TX = 2,
  428. MAC_RXFIFO_SIZE = 32768
  429. };
  430. /* PHY loopback direction */
  431. enum {
  432. PHY_LOOPBACK_TX = 1,
  433. PHY_LOOPBACK_RX = 2
  434. };
  435. /* PHY interrupt types */
  436. enum {
  437. cphy_cause_link_change = 1,
  438. cphy_cause_fifo_error = 2,
  439. cphy_cause_module_change = 4,
  440. };
  441. /* PHY module types */
  442. enum {
  443. phy_modtype_none,
  444. phy_modtype_sr,
  445. phy_modtype_lr,
  446. phy_modtype_lrm,
  447. phy_modtype_twinax,
  448. phy_modtype_twinax_long,
  449. phy_modtype_unknown
  450. };
  451. /* PHY operations */
  452. struct cphy_ops {
  453. int (*reset)(struct cphy *phy, int wait);
  454. int (*intr_enable)(struct cphy *phy);
  455. int (*intr_disable)(struct cphy *phy);
  456. int (*intr_clear)(struct cphy *phy);
  457. int (*intr_handler)(struct cphy *phy);
  458. int (*autoneg_enable)(struct cphy *phy);
  459. int (*autoneg_restart)(struct cphy *phy);
  460. int (*advertise)(struct cphy *phy, unsigned int advertise_map);
  461. int (*set_loopback)(struct cphy *phy, int mmd, int dir, int enable);
  462. int (*set_speed_duplex)(struct cphy *phy, int speed, int duplex);
  463. int (*get_link_status)(struct cphy *phy, int *link_ok, int *speed,
  464. int *duplex, int *fc);
  465. int (*power_down)(struct cphy *phy, int enable);
  466. u32 mmds;
  467. };
  468. enum {
  469. EDC_OPT_AEL2005 = 0,
  470. EDC_OPT_AEL2005_SIZE = 1084,
  471. EDC_TWX_AEL2005 = 1,
  472. EDC_TWX_AEL2005_SIZE = 1464,
  473. EDC_TWX_AEL2020 = 2,
  474. EDC_TWX_AEL2020_SIZE = 1628,
  475. EDC_MAX_SIZE = EDC_TWX_AEL2020_SIZE, /* Max cache size */
  476. };
  477. /* A PHY instance */
  478. struct cphy {
  479. u8 modtype; /* PHY module type */
  480. short priv; /* scratch pad */
  481. unsigned int caps; /* PHY capabilities */
  482. struct adapter *adapter; /* associated adapter */
  483. const char *desc; /* PHY description */
  484. unsigned long fifo_errors; /* FIFO over/under-flows */
  485. const struct cphy_ops *ops; /* PHY operations */
  486. struct mdio_if_info mdio;
  487. u16 phy_cache[EDC_MAX_SIZE]; /* EDC cache */
  488. };
  489. /* Convenience MDIO read/write wrappers */
  490. static inline int t3_mdio_read(struct cphy *phy, int mmd, int reg,
  491. unsigned int *valp)
  492. {
  493. int rc = phy->mdio.mdio_read(phy->mdio.dev, phy->mdio.prtad, mmd, reg);
  494. *valp = (rc >= 0) ? rc : -1;
  495. return (rc >= 0) ? 0 : rc;
  496. }
  497. static inline int t3_mdio_write(struct cphy *phy, int mmd, int reg,
  498. unsigned int val)
  499. {
  500. return phy->mdio.mdio_write(phy->mdio.dev, phy->mdio.prtad, mmd,
  501. reg, val);
  502. }
  503. /* Convenience initializer */
  504. static inline void cphy_init(struct cphy *phy, struct adapter *adapter,
  505. int phy_addr, const struct cphy_ops *phy_ops,
  506. const struct mdio_ops *mdio_ops,
  507. unsigned int caps, const char *desc)
  508. {
  509. phy->caps = caps;
  510. phy->adapter = adapter;
  511. phy->desc = desc;
  512. phy->ops = phy_ops;
  513. if (mdio_ops) {
  514. phy->mdio.prtad = phy_addr;
  515. phy->mdio.mmds = phy_ops->mmds;
  516. phy->mdio.mode_support = mdio_ops->mode_support;
  517. phy->mdio.mdio_read = mdio_ops->read;
  518. phy->mdio.mdio_write = mdio_ops->write;
  519. }
  520. }
  521. /* Accumulate MAC statistics every 180 seconds. For 1G we multiply by 10. */
  522. #define MAC_STATS_ACCUM_SECS 180
  523. #define XGM_REG(reg_addr, idx) \
  524. ((reg_addr) + (idx) * (XGMAC0_1_BASE_ADDR - XGMAC0_0_BASE_ADDR))
  525. struct addr_val_pair {
  526. unsigned int reg_addr;
  527. unsigned int val;
  528. };
  529. #include "adapter.h"
  530. #ifndef PCI_VENDOR_ID_CHELSIO
  531. # define PCI_VENDOR_ID_CHELSIO 0x1425
  532. #endif
  533. #define for_each_port(adapter, iter) \
  534. for (iter = 0; iter < (adapter)->params.nports; ++iter)
  535. #define adapter_info(adap) ((adap)->params.info)
  536. static inline int uses_xaui(const struct adapter *adap)
  537. {
  538. return adapter_info(adap)->caps & SUPPORTED_AUI;
  539. }
  540. static inline int is_10G(const struct adapter *adap)
  541. {
  542. return adapter_info(adap)->caps & SUPPORTED_10000baseT_Full;
  543. }
  544. static inline int is_offload(const struct adapter *adap)
  545. {
  546. return adap->params.offload;
  547. }
  548. static inline unsigned int core_ticks_per_usec(const struct adapter *adap)
  549. {
  550. return adap->params.vpd.cclk / 1000;
  551. }
  552. static inline unsigned int is_pcie(const struct adapter *adap)
  553. {
  554. return adap->params.pci.variant == PCI_VARIANT_PCIE;
  555. }
  556. void t3_set_reg_field(struct adapter *adap, unsigned int addr, u32 mask,
  557. u32 val);
  558. void t3_write_regs(struct adapter *adapter, const struct addr_val_pair *p,
  559. int n, unsigned int offset);
  560. int t3_wait_op_done_val(struct adapter *adapter, int reg, u32 mask,
  561. int polarity, int attempts, int delay, u32 *valp);
  562. static inline int t3_wait_op_done(struct adapter *adapter, int reg, u32 mask,
  563. int polarity, int attempts, int delay)
  564. {
  565. return t3_wait_op_done_val(adapter, reg, mask, polarity, attempts,
  566. delay, NULL);
  567. }
  568. int t3_mdio_change_bits(struct cphy *phy, int mmd, int reg, unsigned int clear,
  569. unsigned int set);
  570. int t3_phy_reset(struct cphy *phy, int mmd, int wait);
  571. int t3_phy_advertise(struct cphy *phy, unsigned int advert);
  572. int t3_phy_advertise_fiber(struct cphy *phy, unsigned int advert);
  573. int t3_set_phy_speed_duplex(struct cphy *phy, int speed, int duplex);
  574. int t3_phy_lasi_intr_enable(struct cphy *phy);
  575. int t3_phy_lasi_intr_disable(struct cphy *phy);
  576. int t3_phy_lasi_intr_clear(struct cphy *phy);
  577. int t3_phy_lasi_intr_handler(struct cphy *phy);
  578. void t3_intr_enable(struct adapter *adapter);
  579. void t3_intr_disable(struct adapter *adapter);
  580. void t3_intr_clear(struct adapter *adapter);
  581. void t3_xgm_intr_enable(struct adapter *adapter, int idx);
  582. void t3_xgm_intr_disable(struct adapter *adapter, int idx);
  583. void t3_port_intr_enable(struct adapter *adapter, int idx);
  584. void t3_port_intr_disable(struct adapter *adapter, int idx);
  585. int t3_slow_intr_handler(struct adapter *adapter);
  586. int t3_phy_intr_handler(struct adapter *adapter);
  587. void t3_link_changed(struct adapter *adapter, int port_id);
  588. void t3_link_fault(struct adapter *adapter, int port_id);
  589. int t3_link_start(struct cphy *phy, struct cmac *mac, struct link_config *lc);
  590. const struct adapter_info *t3_get_adapter_info(unsigned int board_id);
  591. int t3_seeprom_read(struct adapter *adapter, u32 addr, __le32 *data);
  592. int t3_seeprom_write(struct adapter *adapter, u32 addr, __le32 data);
  593. int t3_seeprom_wp(struct adapter *adapter, int enable);
  594. int t3_get_tp_version(struct adapter *adapter, u32 *vers);
  595. int t3_check_tpsram_version(struct adapter *adapter);
  596. int t3_check_tpsram(struct adapter *adapter, const u8 *tp_ram,
  597. unsigned int size);
  598. int t3_set_proto_sram(struct adapter *adap, const u8 *data);
  599. int t3_load_fw(struct adapter *adapter, const u8 * fw_data, unsigned int size);
  600. int t3_get_fw_version(struct adapter *adapter, u32 *vers);
  601. int t3_check_fw_version(struct adapter *adapter);
  602. int t3_init_hw(struct adapter *adapter, u32 fw_params);
  603. int t3_reset_adapter(struct adapter *adapter);
  604. int t3_prep_adapter(struct adapter *adapter, const struct adapter_info *ai,
  605. int reset);
  606. int t3_replay_prep_adapter(struct adapter *adapter);
  607. void t3_led_ready(struct adapter *adapter);
  608. void t3_fatal_err(struct adapter *adapter);
  609. void t3_set_vlan_accel(struct adapter *adapter, unsigned int ports, int on);
  610. void t3_config_rss(struct adapter *adapter, unsigned int rss_config,
  611. const u8 * cpus, const u16 *rspq);
  612. int t3_cim_ctl_blk_read(struct adapter *adap, unsigned int addr,
  613. unsigned int n, unsigned int *valp);
  614. int t3_mc7_bd_read(struct mc7 *mc7, unsigned int start, unsigned int n,
  615. u64 *buf);
  616. int t3_mac_reset(struct cmac *mac);
  617. void t3b_pcs_reset(struct cmac *mac);
  618. void t3_mac_disable_exact_filters(struct cmac *mac);
  619. void t3_mac_enable_exact_filters(struct cmac *mac);
  620. int t3_mac_enable(struct cmac *mac, int which);
  621. int t3_mac_disable(struct cmac *mac, int which);
  622. int t3_mac_set_mtu(struct cmac *mac, unsigned int mtu);
  623. int t3_mac_set_rx_mode(struct cmac *mac, struct net_device *dev);
  624. int t3_mac_set_address(struct cmac *mac, unsigned int idx, u8 addr[6]);
  625. int t3_mac_set_num_ucast(struct cmac *mac, int n);
  626. const struct mac_stats *t3_mac_update_stats(struct cmac *mac);
  627. int t3_mac_set_speed_duplex_fc(struct cmac *mac, int speed, int duplex, int fc);
  628. int t3b2_mac_watchdog_task(struct cmac *mac);
  629. void t3_mc5_prep(struct adapter *adapter, struct mc5 *mc5, int mode);
  630. int t3_mc5_init(struct mc5 *mc5, unsigned int nservers, unsigned int nfilters,
  631. unsigned int nroutes);
  632. void t3_mc5_intr_handler(struct mc5 *mc5);
  633. void t3_tp_set_offload_mode(struct adapter *adap, int enable);
  634. void t3_tp_get_mib_stats(struct adapter *adap, struct tp_mib_stats *tps);
  635. void t3_load_mtus(struct adapter *adap, unsigned short mtus[NMTUS],
  636. unsigned short alpha[NCCTRL_WIN],
  637. unsigned short beta[NCCTRL_WIN], unsigned short mtu_cap);
  638. void t3_config_trace_filter(struct adapter *adapter,
  639. const struct trace_params *tp, int filter_index,
  640. int invert, int enable);
  641. int t3_config_sched(struct adapter *adap, unsigned int kbps, int sched);
  642. void t3_sge_prep(struct adapter *adap, struct sge_params *p);
  643. void t3_sge_init(struct adapter *adap, struct sge_params *p);
  644. int t3_sge_init_ecntxt(struct adapter *adapter, unsigned int id, int gts_enable,
  645. enum sge_context_type type, int respq, u64 base_addr,
  646. unsigned int size, unsigned int token, int gen,
  647. unsigned int cidx);
  648. int t3_sge_init_flcntxt(struct adapter *adapter, unsigned int id,
  649. int gts_enable, u64 base_addr, unsigned int size,
  650. unsigned int esize, unsigned int cong_thres, int gen,
  651. unsigned int cidx);
  652. int t3_sge_init_rspcntxt(struct adapter *adapter, unsigned int id,
  653. int irq_vec_idx, u64 base_addr, unsigned int size,
  654. unsigned int fl_thres, int gen, unsigned int cidx);
  655. int t3_sge_init_cqcntxt(struct adapter *adapter, unsigned int id, u64 base_addr,
  656. unsigned int size, int rspq, int ovfl_mode,
  657. unsigned int credits, unsigned int credit_thres);
  658. int t3_sge_enable_ecntxt(struct adapter *adapter, unsigned int id, int enable);
  659. int t3_sge_disable_fl(struct adapter *adapter, unsigned int id);
  660. int t3_sge_disable_rspcntxt(struct adapter *adapter, unsigned int id);
  661. int t3_sge_disable_cqcntxt(struct adapter *adapter, unsigned int id);
  662. int t3_sge_cqcntxt_op(struct adapter *adapter, unsigned int id, unsigned int op,
  663. unsigned int credits);
  664. int t3_vsc8211_phy_prep(struct cphy *phy, struct adapter *adapter,
  665. int phy_addr, const struct mdio_ops *mdio_ops);
  666. int t3_ael1002_phy_prep(struct cphy *phy, struct adapter *adapter,
  667. int phy_addr, const struct mdio_ops *mdio_ops);
  668. int t3_ael1006_phy_prep(struct cphy *phy, struct adapter *adapter,
  669. int phy_addr, const struct mdio_ops *mdio_ops);
  670. int t3_ael2005_phy_prep(struct cphy *phy, struct adapter *adapter,
  671. int phy_addr, const struct mdio_ops *mdio_ops);
  672. int t3_ael2020_phy_prep(struct cphy *phy, struct adapter *adapter,
  673. int phy_addr, const struct mdio_ops *mdio_ops);
  674. int t3_qt2045_phy_prep(struct cphy *phy, struct adapter *adapter, int phy_addr,
  675. const struct mdio_ops *mdio_ops);
  676. int t3_xaui_direct_phy_prep(struct cphy *phy, struct adapter *adapter,
  677. int phy_addr, const struct mdio_ops *mdio_ops);
  678. int t3_aq100x_phy_prep(struct cphy *phy, struct adapter *adapter,
  679. int phy_addr, const struct mdio_ops *mdio_ops);
  680. #endif /* __CHELSIO_COMMON_H */