common.h 23 KB

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