cxgb4.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995
  1. /*
  2. * This file is part of the Chelsio T4 Ethernet driver for Linux.
  3. *
  4. * Copyright (c) 2003-2010 Chelsio Communications, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #ifndef __CXGB4_H__
  35. #define __CXGB4_H__
  36. #include "t4_hw.h"
  37. #include <linux/bitops.h>
  38. #include <linux/cache.h>
  39. #include <linux/interrupt.h>
  40. #include <linux/list.h>
  41. #include <linux/netdevice.h>
  42. #include <linux/pci.h>
  43. #include <linux/spinlock.h>
  44. #include <linux/timer.h>
  45. #include <linux/vmalloc.h>
  46. #include <asm/io.h>
  47. #include "cxgb4_uld.h"
  48. #include "t4_hw.h"
  49. #define FW_VERSION_MAJOR 1
  50. #define FW_VERSION_MINOR 4
  51. #define FW_VERSION_MICRO 0
  52. #define FW_VERSION_MAJOR_T5 0
  53. #define FW_VERSION_MINOR_T5 0
  54. #define FW_VERSION_MICRO_T5 0
  55. #define CH_WARN(adap, fmt, ...) dev_warn(adap->pdev_dev, fmt, ## __VA_ARGS__)
  56. enum {
  57. MAX_NPORTS = 4, /* max # of ports */
  58. SERNUM_LEN = 24, /* Serial # length */
  59. EC_LEN = 16, /* E/C length */
  60. ID_LEN = 16, /* ID length */
  61. };
  62. enum {
  63. MEM_EDC0,
  64. MEM_EDC1,
  65. MEM_MC,
  66. MEM_MC0 = MEM_MC,
  67. MEM_MC1
  68. };
  69. enum {
  70. MEMWIN0_APERTURE = 2048,
  71. MEMWIN0_BASE = 0x1b800,
  72. MEMWIN1_APERTURE = 32768,
  73. MEMWIN1_BASE = 0x28000,
  74. MEMWIN1_BASE_T5 = 0x52000,
  75. MEMWIN2_APERTURE = 65536,
  76. MEMWIN2_BASE = 0x30000,
  77. MEMWIN2_BASE_T5 = 0x54000,
  78. };
  79. enum dev_master {
  80. MASTER_CANT,
  81. MASTER_MAY,
  82. MASTER_MUST
  83. };
  84. enum dev_state {
  85. DEV_STATE_UNINIT,
  86. DEV_STATE_INIT,
  87. DEV_STATE_ERR
  88. };
  89. enum {
  90. PAUSE_RX = 1 << 0,
  91. PAUSE_TX = 1 << 1,
  92. PAUSE_AUTONEG = 1 << 2
  93. };
  94. struct port_stats {
  95. u64 tx_octets; /* total # of octets in good frames */
  96. u64 tx_frames; /* all good frames */
  97. u64 tx_bcast_frames; /* all broadcast frames */
  98. u64 tx_mcast_frames; /* all multicast frames */
  99. u64 tx_ucast_frames; /* all unicast frames */
  100. u64 tx_error_frames; /* all error frames */
  101. u64 tx_frames_64; /* # of Tx frames in a particular range */
  102. u64 tx_frames_65_127;
  103. u64 tx_frames_128_255;
  104. u64 tx_frames_256_511;
  105. u64 tx_frames_512_1023;
  106. u64 tx_frames_1024_1518;
  107. u64 tx_frames_1519_max;
  108. u64 tx_drop; /* # of dropped Tx frames */
  109. u64 tx_pause; /* # of transmitted pause frames */
  110. u64 tx_ppp0; /* # of transmitted PPP prio 0 frames */
  111. u64 tx_ppp1; /* # of transmitted PPP prio 1 frames */
  112. u64 tx_ppp2; /* # of transmitted PPP prio 2 frames */
  113. u64 tx_ppp3; /* # of transmitted PPP prio 3 frames */
  114. u64 tx_ppp4; /* # of transmitted PPP prio 4 frames */
  115. u64 tx_ppp5; /* # of transmitted PPP prio 5 frames */
  116. u64 tx_ppp6; /* # of transmitted PPP prio 6 frames */
  117. u64 tx_ppp7; /* # of transmitted PPP prio 7 frames */
  118. u64 rx_octets; /* total # of octets in good frames */
  119. u64 rx_frames; /* all good frames */
  120. u64 rx_bcast_frames; /* all broadcast frames */
  121. u64 rx_mcast_frames; /* all multicast frames */
  122. u64 rx_ucast_frames; /* all unicast frames */
  123. u64 rx_too_long; /* # of frames exceeding MTU */
  124. u64 rx_jabber; /* # of jabber frames */
  125. u64 rx_fcs_err; /* # of received frames with bad FCS */
  126. u64 rx_len_err; /* # of received frames with length error */
  127. u64 rx_symbol_err; /* symbol errors */
  128. u64 rx_runt; /* # of short frames */
  129. u64 rx_frames_64; /* # of Rx frames in a particular range */
  130. u64 rx_frames_65_127;
  131. u64 rx_frames_128_255;
  132. u64 rx_frames_256_511;
  133. u64 rx_frames_512_1023;
  134. u64 rx_frames_1024_1518;
  135. u64 rx_frames_1519_max;
  136. u64 rx_pause; /* # of received pause frames */
  137. u64 rx_ppp0; /* # of received PPP prio 0 frames */
  138. u64 rx_ppp1; /* # of received PPP prio 1 frames */
  139. u64 rx_ppp2; /* # of received PPP prio 2 frames */
  140. u64 rx_ppp3; /* # of received PPP prio 3 frames */
  141. u64 rx_ppp4; /* # of received PPP prio 4 frames */
  142. u64 rx_ppp5; /* # of received PPP prio 5 frames */
  143. u64 rx_ppp6; /* # of received PPP prio 6 frames */
  144. u64 rx_ppp7; /* # of received PPP prio 7 frames */
  145. u64 rx_ovflow0; /* drops due to buffer-group 0 overflows */
  146. u64 rx_ovflow1; /* drops due to buffer-group 1 overflows */
  147. u64 rx_ovflow2; /* drops due to buffer-group 2 overflows */
  148. u64 rx_ovflow3; /* drops due to buffer-group 3 overflows */
  149. u64 rx_trunc0; /* buffer-group 0 truncated packets */
  150. u64 rx_trunc1; /* buffer-group 1 truncated packets */
  151. u64 rx_trunc2; /* buffer-group 2 truncated packets */
  152. u64 rx_trunc3; /* buffer-group 3 truncated packets */
  153. };
  154. struct lb_port_stats {
  155. u64 octets;
  156. u64 frames;
  157. u64 bcast_frames;
  158. u64 mcast_frames;
  159. u64 ucast_frames;
  160. u64 error_frames;
  161. u64 frames_64;
  162. u64 frames_65_127;
  163. u64 frames_128_255;
  164. u64 frames_256_511;
  165. u64 frames_512_1023;
  166. u64 frames_1024_1518;
  167. u64 frames_1519_max;
  168. u64 drop;
  169. u64 ovflow0;
  170. u64 ovflow1;
  171. u64 ovflow2;
  172. u64 ovflow3;
  173. u64 trunc0;
  174. u64 trunc1;
  175. u64 trunc2;
  176. u64 trunc3;
  177. };
  178. struct tp_tcp_stats {
  179. u32 tcpOutRsts;
  180. u64 tcpInSegs;
  181. u64 tcpOutSegs;
  182. u64 tcpRetransSegs;
  183. };
  184. struct tp_err_stats {
  185. u32 macInErrs[4];
  186. u32 hdrInErrs[4];
  187. u32 tcpInErrs[4];
  188. u32 tnlCongDrops[4];
  189. u32 ofldChanDrops[4];
  190. u32 tnlTxDrops[4];
  191. u32 ofldVlanDrops[4];
  192. u32 tcp6InErrs[4];
  193. u32 ofldNoNeigh;
  194. u32 ofldCongDefer;
  195. };
  196. struct tp_params {
  197. unsigned int ntxchan; /* # of Tx channels */
  198. unsigned int tre; /* log2 of core clocks per TP tick */
  199. unsigned short tx_modq_map; /* TX modulation scheduler queue to */
  200. /* channel map */
  201. uint32_t dack_re; /* DACK timer resolution */
  202. unsigned short tx_modq[NCHAN]; /* channel to modulation queue map */
  203. };
  204. struct vpd_params {
  205. unsigned int cclk;
  206. u8 ec[EC_LEN + 1];
  207. u8 sn[SERNUM_LEN + 1];
  208. u8 id[ID_LEN + 1];
  209. };
  210. struct pci_params {
  211. unsigned char speed;
  212. unsigned char width;
  213. };
  214. struct adapter_params {
  215. struct tp_params tp;
  216. struct vpd_params vpd;
  217. struct pci_params pci;
  218. unsigned int sf_size; /* serial flash size in bytes */
  219. unsigned int sf_nsec; /* # of flash sectors */
  220. unsigned int sf_fw_start; /* start of FW image in flash */
  221. unsigned int fw_vers;
  222. unsigned int tp_vers;
  223. u8 api_vers[7];
  224. unsigned short mtus[NMTUS];
  225. unsigned short a_wnd[NCCTRL_WIN];
  226. unsigned short b_wnd[NCCTRL_WIN];
  227. unsigned char nports; /* # of ethernet ports */
  228. unsigned char portvec;
  229. unsigned char rev; /* chip revision */
  230. unsigned char offload;
  231. unsigned char bypass;
  232. unsigned int ofldq_wr_cred;
  233. };
  234. struct trace_params {
  235. u32 data[TRACE_LEN / 4];
  236. u32 mask[TRACE_LEN / 4];
  237. unsigned short snap_len;
  238. unsigned short min_len;
  239. unsigned char skip_ofst;
  240. unsigned char skip_len;
  241. unsigned char invert;
  242. unsigned char port;
  243. };
  244. struct link_config {
  245. unsigned short supported; /* link capabilities */
  246. unsigned short advertising; /* advertised capabilities */
  247. unsigned short requested_speed; /* speed user has requested */
  248. unsigned short speed; /* actual link speed */
  249. unsigned char requested_fc; /* flow control user has requested */
  250. unsigned char fc; /* actual link flow control */
  251. unsigned char autoneg; /* autonegotiating? */
  252. unsigned char link_ok; /* link up? */
  253. };
  254. #define FW_LEN16(fw_struct) FW_CMD_LEN16(sizeof(fw_struct) / 16)
  255. enum {
  256. MAX_ETH_QSETS = 32, /* # of Ethernet Tx/Rx queue sets */
  257. MAX_OFLD_QSETS = 16, /* # of offload Tx/Rx queue sets */
  258. MAX_CTRL_QUEUES = NCHAN, /* # of control Tx queues */
  259. MAX_RDMA_QUEUES = NCHAN, /* # of streaming RDMA Rx queues */
  260. };
  261. enum {
  262. MAX_EGRQ = 128, /* max # of egress queues, including FLs */
  263. MAX_INGQ = 64 /* max # of interrupt-capable ingress queues */
  264. };
  265. struct adapter;
  266. struct sge_rspq;
  267. struct port_info {
  268. struct adapter *adapter;
  269. u16 viid;
  270. s16 xact_addr_filt; /* index of exact MAC address filter */
  271. u16 rss_size; /* size of VI's RSS table slice */
  272. s8 mdio_addr;
  273. u8 port_type;
  274. u8 mod_type;
  275. u8 port_id;
  276. u8 tx_chan;
  277. u8 lport; /* associated offload logical port */
  278. u8 nqsets; /* # of qsets */
  279. u8 first_qset; /* index of first qset */
  280. u8 rss_mode;
  281. struct link_config link_cfg;
  282. u16 *rss;
  283. };
  284. struct dentry;
  285. struct work_struct;
  286. enum { /* adapter flags */
  287. FULL_INIT_DONE = (1 << 0),
  288. USING_MSI = (1 << 1),
  289. USING_MSIX = (1 << 2),
  290. FW_OK = (1 << 4),
  291. RSS_TNLALLLOOKUP = (1 << 5),
  292. USING_SOFT_PARAMS = (1 << 6),
  293. MASTER_PF = (1 << 7),
  294. FW_OFLD_CONN = (1 << 9),
  295. };
  296. struct rx_sw_desc;
  297. struct sge_fl { /* SGE free-buffer queue state */
  298. unsigned int avail; /* # of available Rx buffers */
  299. unsigned int pend_cred; /* new buffers since last FL DB ring */
  300. unsigned int cidx; /* consumer index */
  301. unsigned int pidx; /* producer index */
  302. unsigned long alloc_failed; /* # of times buffer allocation failed */
  303. unsigned long large_alloc_failed;
  304. unsigned long starving;
  305. /* RO fields */
  306. unsigned int cntxt_id; /* SGE context id for the free list */
  307. unsigned int size; /* capacity of free list */
  308. struct rx_sw_desc *sdesc; /* address of SW Rx descriptor ring */
  309. __be64 *desc; /* address of HW Rx descriptor ring */
  310. dma_addr_t addr; /* bus address of HW ring start */
  311. };
  312. /* A packet gather list */
  313. struct pkt_gl {
  314. struct page_frag frags[MAX_SKB_FRAGS];
  315. void *va; /* virtual address of first byte */
  316. unsigned int nfrags; /* # of fragments */
  317. unsigned int tot_len; /* total length of fragments */
  318. };
  319. typedef int (*rspq_handler_t)(struct sge_rspq *q, const __be64 *rsp,
  320. const struct pkt_gl *gl);
  321. struct sge_rspq { /* state for an SGE response queue */
  322. struct napi_struct napi;
  323. const __be64 *cur_desc; /* current descriptor in queue */
  324. unsigned int cidx; /* consumer index */
  325. u8 gen; /* current generation bit */
  326. u8 intr_params; /* interrupt holdoff parameters */
  327. u8 next_intr_params; /* holdoff params for next interrupt */
  328. u8 pktcnt_idx; /* interrupt packet threshold */
  329. u8 uld; /* ULD handling this queue */
  330. u8 idx; /* queue index within its group */
  331. int offset; /* offset into current Rx buffer */
  332. u16 cntxt_id; /* SGE context id for the response q */
  333. u16 abs_id; /* absolute SGE id for the response q */
  334. __be64 *desc; /* address of HW response ring */
  335. dma_addr_t phys_addr; /* physical address of the ring */
  336. unsigned int iqe_len; /* entry size */
  337. unsigned int size; /* capacity of response queue */
  338. struct adapter *adap;
  339. struct net_device *netdev; /* associated net device */
  340. rspq_handler_t handler;
  341. };
  342. struct sge_eth_stats { /* Ethernet queue statistics */
  343. unsigned long pkts; /* # of ethernet packets */
  344. unsigned long lro_pkts; /* # of LRO super packets */
  345. unsigned long lro_merged; /* # of wire packets merged by LRO */
  346. unsigned long rx_cso; /* # of Rx checksum offloads */
  347. unsigned long vlan_ex; /* # of Rx VLAN extractions */
  348. unsigned long rx_drops; /* # of packets dropped due to no mem */
  349. };
  350. struct sge_eth_rxq { /* SW Ethernet Rx queue */
  351. struct sge_rspq rspq;
  352. struct sge_fl fl;
  353. struct sge_eth_stats stats;
  354. } ____cacheline_aligned_in_smp;
  355. struct sge_ofld_stats { /* offload queue statistics */
  356. unsigned long pkts; /* # of packets */
  357. unsigned long imm; /* # of immediate-data packets */
  358. unsigned long an; /* # of asynchronous notifications */
  359. unsigned long nomem; /* # of responses deferred due to no mem */
  360. };
  361. struct sge_ofld_rxq { /* SW offload Rx queue */
  362. struct sge_rspq rspq;
  363. struct sge_fl fl;
  364. struct sge_ofld_stats stats;
  365. } ____cacheline_aligned_in_smp;
  366. struct tx_desc {
  367. __be64 flit[8];
  368. };
  369. struct tx_sw_desc;
  370. struct sge_txq {
  371. unsigned int in_use; /* # of in-use Tx descriptors */
  372. unsigned int size; /* # of descriptors */
  373. unsigned int cidx; /* SW consumer index */
  374. unsigned int pidx; /* producer index */
  375. unsigned long stops; /* # of times q has been stopped */
  376. unsigned long restarts; /* # of queue restarts */
  377. unsigned int cntxt_id; /* SGE context id for the Tx q */
  378. struct tx_desc *desc; /* address of HW Tx descriptor ring */
  379. struct tx_sw_desc *sdesc; /* address of SW Tx descriptor ring */
  380. struct sge_qstat *stat; /* queue status entry */
  381. dma_addr_t phys_addr; /* physical address of the ring */
  382. spinlock_t db_lock;
  383. int db_disabled;
  384. unsigned short db_pidx;
  385. u64 udb;
  386. };
  387. struct sge_eth_txq { /* state for an SGE Ethernet Tx queue */
  388. struct sge_txq q;
  389. struct netdev_queue *txq; /* associated netdev TX queue */
  390. unsigned long tso; /* # of TSO requests */
  391. unsigned long tx_cso; /* # of Tx checksum offloads */
  392. unsigned long vlan_ins; /* # of Tx VLAN insertions */
  393. unsigned long mapping_err; /* # of I/O MMU packet mapping errors */
  394. } ____cacheline_aligned_in_smp;
  395. struct sge_ofld_txq { /* state for an SGE offload Tx queue */
  396. struct sge_txq q;
  397. struct adapter *adap;
  398. struct sk_buff_head sendq; /* list of backpressured packets */
  399. struct tasklet_struct qresume_tsk; /* restarts the queue */
  400. u8 full; /* the Tx ring is full */
  401. unsigned long mapping_err; /* # of I/O MMU packet mapping errors */
  402. } ____cacheline_aligned_in_smp;
  403. struct sge_ctrl_txq { /* state for an SGE control Tx queue */
  404. struct sge_txq q;
  405. struct adapter *adap;
  406. struct sk_buff_head sendq; /* list of backpressured packets */
  407. struct tasklet_struct qresume_tsk; /* restarts the queue */
  408. u8 full; /* the Tx ring is full */
  409. } ____cacheline_aligned_in_smp;
  410. struct sge {
  411. struct sge_eth_txq ethtxq[MAX_ETH_QSETS];
  412. struct sge_ofld_txq ofldtxq[MAX_OFLD_QSETS];
  413. struct sge_ctrl_txq ctrlq[MAX_CTRL_QUEUES];
  414. struct sge_eth_rxq ethrxq[MAX_ETH_QSETS];
  415. struct sge_ofld_rxq ofldrxq[MAX_OFLD_QSETS];
  416. struct sge_ofld_rxq rdmarxq[MAX_RDMA_QUEUES];
  417. struct sge_rspq fw_evtq ____cacheline_aligned_in_smp;
  418. struct sge_rspq intrq ____cacheline_aligned_in_smp;
  419. spinlock_t intrq_lock;
  420. u16 max_ethqsets; /* # of available Ethernet queue sets */
  421. u16 ethqsets; /* # of active Ethernet queue sets */
  422. u16 ethtxq_rover; /* Tx queue to clean up next */
  423. u16 ofldqsets; /* # of active offload queue sets */
  424. u16 rdmaqs; /* # of available RDMA Rx queues */
  425. u16 ofld_rxq[MAX_OFLD_QSETS];
  426. u16 rdma_rxq[NCHAN];
  427. u16 timer_val[SGE_NTIMERS];
  428. u8 counter_val[SGE_NCOUNTERS];
  429. u32 fl_pg_order; /* large page allocation size */
  430. u32 stat_len; /* length of status page at ring end */
  431. u32 pktshift; /* padding between CPL & packet data */
  432. u32 fl_align; /* response queue message alignment */
  433. u32 fl_starve_thres; /* Free List starvation threshold */
  434. unsigned int starve_thres;
  435. u8 idma_state[2];
  436. unsigned int egr_start;
  437. unsigned int ingr_start;
  438. void *egr_map[MAX_EGRQ]; /* qid->queue egress queue map */
  439. struct sge_rspq *ingr_map[MAX_INGQ]; /* qid->queue ingress queue map */
  440. DECLARE_BITMAP(starving_fl, MAX_EGRQ);
  441. DECLARE_BITMAP(txq_maperr, MAX_EGRQ);
  442. struct timer_list rx_timer; /* refills starving FLs */
  443. struct timer_list tx_timer; /* checks Tx queues */
  444. };
  445. #define for_each_ethrxq(sge, i) for (i = 0; i < (sge)->ethqsets; i++)
  446. #define for_each_ofldrxq(sge, i) for (i = 0; i < (sge)->ofldqsets; i++)
  447. #define for_each_rdmarxq(sge, i) for (i = 0; i < (sge)->rdmaqs; i++)
  448. struct l2t_data;
  449. #define CHELSIO_CHIP_CODE(version, revision) (((version) << 4) | (revision))
  450. #define CHELSIO_CHIP_VERSION(code) ((code) >> 4)
  451. #define CHELSIO_CHIP_RELEASE(code) ((code) & 0xf)
  452. #define CHELSIO_T4 0x4
  453. #define CHELSIO_T5 0x5
  454. enum chip_type {
  455. T4_A1 = CHELSIO_CHIP_CODE(CHELSIO_T4, 0),
  456. T4_A2 = CHELSIO_CHIP_CODE(CHELSIO_T4, 1),
  457. T4_A3 = CHELSIO_CHIP_CODE(CHELSIO_T4, 2),
  458. T4_FIRST_REV = T4_A1,
  459. T4_LAST_REV = T4_A3,
  460. T5_A1 = CHELSIO_CHIP_CODE(CHELSIO_T5, 0),
  461. T5_FIRST_REV = T5_A1,
  462. T5_LAST_REV = T5_A1,
  463. };
  464. #ifdef CONFIG_PCI_IOV
  465. /* T4 supports SRIOV on PF0-3 and T5 on PF0-7. However, the Serial
  466. * Configuration initialization for T5 only has SR-IOV functionality enabled
  467. * on PF0-3 in order to simplify everything.
  468. */
  469. #define NUM_OF_PF_WITH_SRIOV 4
  470. #endif
  471. struct adapter {
  472. void __iomem *regs;
  473. void __iomem *bar2;
  474. struct pci_dev *pdev;
  475. struct device *pdev_dev;
  476. unsigned int mbox;
  477. unsigned int fn;
  478. unsigned int flags;
  479. enum chip_type chip;
  480. int msg_enable;
  481. struct adapter_params params;
  482. struct cxgb4_virt_res vres;
  483. unsigned int swintr;
  484. unsigned int wol;
  485. struct {
  486. unsigned short vec;
  487. char desc[IFNAMSIZ + 10];
  488. } msix_info[MAX_INGQ + 1];
  489. struct sge sge;
  490. struct net_device *port[MAX_NPORTS];
  491. u8 chan_map[NCHAN]; /* channel -> port map */
  492. u32 filter_mode;
  493. unsigned int l2t_start;
  494. unsigned int l2t_end;
  495. struct l2t_data *l2t;
  496. void *uld_handle[CXGB4_ULD_MAX];
  497. struct list_head list_node;
  498. struct list_head rcu_node;
  499. struct tid_info tids;
  500. void **tid_release_head;
  501. spinlock_t tid_release_lock;
  502. struct work_struct tid_release_task;
  503. struct work_struct db_full_task;
  504. struct work_struct db_drop_task;
  505. bool tid_release_task_busy;
  506. struct dentry *debugfs_root;
  507. spinlock_t stats_lock;
  508. };
  509. /* Defined bit width of user definable filter tuples
  510. */
  511. #define ETHTYPE_BITWIDTH 16
  512. #define FRAG_BITWIDTH 1
  513. #define MACIDX_BITWIDTH 9
  514. #define FCOE_BITWIDTH 1
  515. #define IPORT_BITWIDTH 3
  516. #define MATCHTYPE_BITWIDTH 3
  517. #define PROTO_BITWIDTH 8
  518. #define TOS_BITWIDTH 8
  519. #define PF_BITWIDTH 8
  520. #define VF_BITWIDTH 8
  521. #define IVLAN_BITWIDTH 16
  522. #define OVLAN_BITWIDTH 16
  523. /* Filter matching rules. These consist of a set of ingress packet field
  524. * (value, mask) tuples. The associated ingress packet field matches the
  525. * tuple when ((field & mask) == value). (Thus a wildcard "don't care" field
  526. * rule can be constructed by specifying a tuple of (0, 0).) A filter rule
  527. * matches an ingress packet when all of the individual individual field
  528. * matching rules are true.
  529. *
  530. * Partial field masks are always valid, however, while it may be easy to
  531. * understand their meanings for some fields (e.g. IP address to match a
  532. * subnet), for others making sensible partial masks is less intuitive (e.g.
  533. * MPS match type) ...
  534. *
  535. * Most of the following data structures are modeled on T4 capabilities.
  536. * Drivers for earlier chips use the subsets which make sense for those chips.
  537. * We really need to come up with a hardware-independent mechanism to
  538. * represent hardware filter capabilities ...
  539. */
  540. struct ch_filter_tuple {
  541. /* Compressed header matching field rules. The TP_VLAN_PRI_MAP
  542. * register selects which of these fields will participate in the
  543. * filter match rules -- up to a maximum of 36 bits. Because
  544. * TP_VLAN_PRI_MAP is a global register, all filters must use the same
  545. * set of fields.
  546. */
  547. uint32_t ethtype:ETHTYPE_BITWIDTH; /* Ethernet type */
  548. uint32_t frag:FRAG_BITWIDTH; /* IP fragmentation header */
  549. uint32_t ivlan_vld:1; /* inner VLAN valid */
  550. uint32_t ovlan_vld:1; /* outer VLAN valid */
  551. uint32_t pfvf_vld:1; /* PF/VF valid */
  552. uint32_t macidx:MACIDX_BITWIDTH; /* exact match MAC index */
  553. uint32_t fcoe:FCOE_BITWIDTH; /* FCoE packet */
  554. uint32_t iport:IPORT_BITWIDTH; /* ingress port */
  555. uint32_t matchtype:MATCHTYPE_BITWIDTH; /* MPS match type */
  556. uint32_t proto:PROTO_BITWIDTH; /* protocol type */
  557. uint32_t tos:TOS_BITWIDTH; /* TOS/Traffic Type */
  558. uint32_t pf:PF_BITWIDTH; /* PCI-E PF ID */
  559. uint32_t vf:VF_BITWIDTH; /* PCI-E VF ID */
  560. uint32_t ivlan:IVLAN_BITWIDTH; /* inner VLAN */
  561. uint32_t ovlan:OVLAN_BITWIDTH; /* outer VLAN */
  562. /* Uncompressed header matching field rules. These are always
  563. * available for field rules.
  564. */
  565. uint8_t lip[16]; /* local IP address (IPv4 in [3:0]) */
  566. uint8_t fip[16]; /* foreign IP address (IPv4 in [3:0]) */
  567. uint16_t lport; /* local port */
  568. uint16_t fport; /* foreign port */
  569. };
  570. /* A filter ioctl command.
  571. */
  572. struct ch_filter_specification {
  573. /* Administrative fields for filter.
  574. */
  575. uint32_t hitcnts:1; /* count filter hits in TCB */
  576. uint32_t prio:1; /* filter has priority over active/server */
  577. /* Fundamental filter typing. This is the one element of filter
  578. * matching that doesn't exist as a (value, mask) tuple.
  579. */
  580. uint32_t type:1; /* 0 => IPv4, 1 => IPv6 */
  581. /* Packet dispatch information. Ingress packets which match the
  582. * filter rules will be dropped, passed to the host or switched back
  583. * out as egress packets.
  584. */
  585. uint32_t action:2; /* drop, pass, switch */
  586. uint32_t rpttid:1; /* report TID in RSS hash field */
  587. uint32_t dirsteer:1; /* 0 => RSS, 1 => steer to iq */
  588. uint32_t iq:10; /* ingress queue */
  589. uint32_t maskhash:1; /* dirsteer=0: store RSS hash in TCB */
  590. uint32_t dirsteerhash:1;/* dirsteer=1: 0 => TCB contains RSS hash */
  591. /* 1 => TCB contains IQ ID */
  592. /* Switch proxy/rewrite fields. An ingress packet which matches a
  593. * filter with "switch" set will be looped back out as an egress
  594. * packet -- potentially with some Ethernet header rewriting.
  595. */
  596. uint32_t eport:2; /* egress port to switch packet out */
  597. uint32_t newdmac:1; /* rewrite destination MAC address */
  598. uint32_t newsmac:1; /* rewrite source MAC address */
  599. uint32_t newvlan:2; /* rewrite VLAN Tag */
  600. uint8_t dmac[ETH_ALEN]; /* new destination MAC address */
  601. uint8_t smac[ETH_ALEN]; /* new source MAC address */
  602. uint16_t vlan; /* VLAN Tag to insert */
  603. /* Filter rule value/mask pairs.
  604. */
  605. struct ch_filter_tuple val;
  606. struct ch_filter_tuple mask;
  607. };
  608. enum {
  609. FILTER_PASS = 0, /* default */
  610. FILTER_DROP,
  611. FILTER_SWITCH
  612. };
  613. enum {
  614. VLAN_NOCHANGE = 0, /* default */
  615. VLAN_REMOVE,
  616. VLAN_INSERT,
  617. VLAN_REWRITE
  618. };
  619. static inline int is_t5(enum chip_type chip)
  620. {
  621. return (chip >= T5_FIRST_REV && chip <= T5_LAST_REV);
  622. }
  623. static inline int is_t4(enum chip_type chip)
  624. {
  625. return (chip >= T4_FIRST_REV && chip <= T4_LAST_REV);
  626. }
  627. static inline u32 t4_read_reg(struct adapter *adap, u32 reg_addr)
  628. {
  629. return readl(adap->regs + reg_addr);
  630. }
  631. static inline void t4_write_reg(struct adapter *adap, u32 reg_addr, u32 val)
  632. {
  633. writel(val, adap->regs + reg_addr);
  634. }
  635. #ifndef readq
  636. static inline u64 readq(const volatile void __iomem *addr)
  637. {
  638. return readl(addr) + ((u64)readl(addr + 4) << 32);
  639. }
  640. static inline void writeq(u64 val, volatile void __iomem *addr)
  641. {
  642. writel(val, addr);
  643. writel(val >> 32, addr + 4);
  644. }
  645. #endif
  646. static inline u64 t4_read_reg64(struct adapter *adap, u32 reg_addr)
  647. {
  648. return readq(adap->regs + reg_addr);
  649. }
  650. static inline void t4_write_reg64(struct adapter *adap, u32 reg_addr, u64 val)
  651. {
  652. writeq(val, adap->regs + reg_addr);
  653. }
  654. /**
  655. * netdev2pinfo - return the port_info structure associated with a net_device
  656. * @dev: the netdev
  657. *
  658. * Return the struct port_info associated with a net_device
  659. */
  660. static inline struct port_info *netdev2pinfo(const struct net_device *dev)
  661. {
  662. return netdev_priv(dev);
  663. }
  664. /**
  665. * adap2pinfo - return the port_info of a port
  666. * @adap: the adapter
  667. * @idx: the port index
  668. *
  669. * Return the port_info structure for the port of the given index.
  670. */
  671. static inline struct port_info *adap2pinfo(struct adapter *adap, int idx)
  672. {
  673. return netdev_priv(adap->port[idx]);
  674. }
  675. /**
  676. * netdev2adap - return the adapter structure associated with a net_device
  677. * @dev: the netdev
  678. *
  679. * Return the struct adapter associated with a net_device
  680. */
  681. static inline struct adapter *netdev2adap(const struct net_device *dev)
  682. {
  683. return netdev2pinfo(dev)->adapter;
  684. }
  685. void t4_os_portmod_changed(const struct adapter *adap, int port_id);
  686. void t4_os_link_changed(struct adapter *adap, int port_id, int link_stat);
  687. void *t4_alloc_mem(size_t size);
  688. void t4_free_sge_resources(struct adapter *adap);
  689. irq_handler_t t4_intr_handler(struct adapter *adap);
  690. netdev_tx_t t4_eth_xmit(struct sk_buff *skb, struct net_device *dev);
  691. int t4_ethrx_handler(struct sge_rspq *q, const __be64 *rsp,
  692. const struct pkt_gl *gl);
  693. int t4_mgmt_tx(struct adapter *adap, struct sk_buff *skb);
  694. int t4_ofld_send(struct adapter *adap, struct sk_buff *skb);
  695. int t4_sge_alloc_rxq(struct adapter *adap, struct sge_rspq *iq, bool fwevtq,
  696. struct net_device *dev, int intr_idx,
  697. struct sge_fl *fl, rspq_handler_t hnd);
  698. int t4_sge_alloc_eth_txq(struct adapter *adap, struct sge_eth_txq *txq,
  699. struct net_device *dev, struct netdev_queue *netdevq,
  700. unsigned int iqid);
  701. int t4_sge_alloc_ctrl_txq(struct adapter *adap, struct sge_ctrl_txq *txq,
  702. struct net_device *dev, unsigned int iqid,
  703. unsigned int cmplqid);
  704. int t4_sge_alloc_ofld_txq(struct adapter *adap, struct sge_ofld_txq *txq,
  705. struct net_device *dev, unsigned int iqid);
  706. irqreturn_t t4_sge_intr_msix(int irq, void *cookie);
  707. int t4_sge_init(struct adapter *adap);
  708. void t4_sge_start(struct adapter *adap);
  709. void t4_sge_stop(struct adapter *adap);
  710. extern int dbfifo_int_thresh;
  711. #define for_each_port(adapter, iter) \
  712. for (iter = 0; iter < (adapter)->params.nports; ++iter)
  713. static inline int is_bypass(struct adapter *adap)
  714. {
  715. return adap->params.bypass;
  716. }
  717. static inline int is_bypass_device(int device)
  718. {
  719. /* this should be set based upon device capabilities */
  720. switch (device) {
  721. case 0x440b:
  722. case 0x440c:
  723. return 1;
  724. default:
  725. return 0;
  726. }
  727. }
  728. static inline unsigned int core_ticks_per_usec(const struct adapter *adap)
  729. {
  730. return adap->params.vpd.cclk / 1000;
  731. }
  732. static inline unsigned int us_to_core_ticks(const struct adapter *adap,
  733. unsigned int us)
  734. {
  735. return (us * adap->params.vpd.cclk) / 1000;
  736. }
  737. static inline unsigned int core_ticks_to_us(const struct adapter *adapter,
  738. unsigned int ticks)
  739. {
  740. /* add Core Clock / 2 to round ticks to nearest uS */
  741. return ((ticks * 1000 + adapter->params.vpd.cclk/2) /
  742. adapter->params.vpd.cclk);
  743. }
  744. void t4_set_reg_field(struct adapter *adap, unsigned int addr, u32 mask,
  745. u32 val);
  746. int t4_wr_mbox_meat(struct adapter *adap, int mbox, const void *cmd, int size,
  747. void *rpl, bool sleep_ok);
  748. static inline int t4_wr_mbox(struct adapter *adap, int mbox, const void *cmd,
  749. int size, void *rpl)
  750. {
  751. return t4_wr_mbox_meat(adap, mbox, cmd, size, rpl, true);
  752. }
  753. static inline int t4_wr_mbox_ns(struct adapter *adap, int mbox, const void *cmd,
  754. int size, void *rpl)
  755. {
  756. return t4_wr_mbox_meat(adap, mbox, cmd, size, rpl, false);
  757. }
  758. void t4_write_indirect(struct adapter *adap, unsigned int addr_reg,
  759. unsigned int data_reg, const u32 *vals,
  760. unsigned int nregs, unsigned int start_idx);
  761. void t4_read_indirect(struct adapter *adap, unsigned int addr_reg,
  762. unsigned int data_reg, u32 *vals, unsigned int nregs,
  763. unsigned int start_idx);
  764. struct fw_filter_wr;
  765. void t4_intr_enable(struct adapter *adapter);
  766. void t4_intr_disable(struct adapter *adapter);
  767. int t4_slow_intr_handler(struct adapter *adapter);
  768. int t4_wait_dev_ready(struct adapter *adap);
  769. int t4_link_start(struct adapter *adap, unsigned int mbox, unsigned int port,
  770. struct link_config *lc);
  771. int t4_restart_aneg(struct adapter *adap, unsigned int mbox, unsigned int port);
  772. int t4_memory_write(struct adapter *adap, int mtype, u32 addr, u32 len,
  773. __be32 *buf);
  774. int t4_seeprom_wp(struct adapter *adapter, bool enable);
  775. int get_vpd_params(struct adapter *adapter, struct vpd_params *p);
  776. int t4_load_fw(struct adapter *adapter, const u8 *fw_data, unsigned int size);
  777. unsigned int t4_flash_cfg_addr(struct adapter *adapter);
  778. int t4_load_cfg(struct adapter *adapter, const u8 *cfg_data, unsigned int size);
  779. int t4_check_fw_version(struct adapter *adapter);
  780. int t4_prep_adapter(struct adapter *adapter);
  781. int t4_port_init(struct adapter *adap, int mbox, int pf, int vf);
  782. void t4_fatal_err(struct adapter *adapter);
  783. int t4_config_rss_range(struct adapter *adapter, int mbox, unsigned int viid,
  784. int start, int n, const u16 *rspq, unsigned int nrspq);
  785. int t4_config_glbl_rss(struct adapter *adapter, int mbox, unsigned int mode,
  786. unsigned int flags);
  787. int t4_mc_read(struct adapter *adap, int idx, u32 addr, __be32 *data,
  788. u64 *parity);
  789. int t4_edc_read(struct adapter *adap, int idx, u32 addr, __be32 *data,
  790. u64 *parity);
  791. void t4_get_port_stats(struct adapter *adap, int idx, struct port_stats *p);
  792. void t4_read_mtu_tbl(struct adapter *adap, u16 *mtus, u8 *mtu_log);
  793. void t4_tp_wr_bits_indirect(struct adapter *adap, unsigned int addr,
  794. unsigned int mask, unsigned int val);
  795. void t4_tp_get_tcp_stats(struct adapter *adap, struct tp_tcp_stats *v4,
  796. struct tp_tcp_stats *v6);
  797. void t4_load_mtus(struct adapter *adap, const unsigned short *mtus,
  798. const unsigned short *alpha, const unsigned short *beta);
  799. void t4_mk_filtdelwr(unsigned int ftid, struct fw_filter_wr *wr, int qid);
  800. void t4_wol_magic_enable(struct adapter *adap, unsigned int port,
  801. const u8 *addr);
  802. int t4_wol_pat_enable(struct adapter *adap, unsigned int port, unsigned int map,
  803. u64 mask0, u64 mask1, unsigned int crc, bool enable);
  804. int t4_fw_hello(struct adapter *adap, unsigned int mbox, unsigned int evt_mbox,
  805. enum dev_master master, enum dev_state *state);
  806. int t4_fw_bye(struct adapter *adap, unsigned int mbox);
  807. int t4_early_init(struct adapter *adap, unsigned int mbox);
  808. int t4_fw_reset(struct adapter *adap, unsigned int mbox, int reset);
  809. int t4_fw_halt(struct adapter *adap, unsigned int mbox, int force);
  810. int t4_fw_restart(struct adapter *adap, unsigned int mbox, int reset);
  811. int t4_fw_upgrade(struct adapter *adap, unsigned int mbox,
  812. const u8 *fw_data, unsigned int size, int force);
  813. int t4_fw_config_file(struct adapter *adap, unsigned int mbox,
  814. unsigned int mtype, unsigned int maddr,
  815. u32 *finiver, u32 *finicsum, u32 *cfcsum);
  816. int t4_fixup_host_params(struct adapter *adap, unsigned int page_size,
  817. unsigned int cache_line_size);
  818. int t4_fw_initialize(struct adapter *adap, unsigned int mbox);
  819. int t4_query_params(struct adapter *adap, unsigned int mbox, unsigned int pf,
  820. unsigned int vf, unsigned int nparams, const u32 *params,
  821. u32 *val);
  822. int t4_set_params(struct adapter *adap, unsigned int mbox, unsigned int pf,
  823. unsigned int vf, unsigned int nparams, const u32 *params,
  824. const u32 *val);
  825. int t4_cfg_pfvf(struct adapter *adap, unsigned int mbox, unsigned int pf,
  826. unsigned int vf, unsigned int txq, unsigned int txq_eth_ctrl,
  827. unsigned int rxqi, unsigned int rxq, unsigned int tc,
  828. unsigned int vi, unsigned int cmask, unsigned int pmask,
  829. unsigned int nexact, unsigned int rcaps, unsigned int wxcaps);
  830. int t4_alloc_vi(struct adapter *adap, unsigned int mbox, unsigned int port,
  831. unsigned int pf, unsigned int vf, unsigned int nmac, u8 *mac,
  832. unsigned int *rss_size);
  833. int t4_set_rxmode(struct adapter *adap, unsigned int mbox, unsigned int viid,
  834. int mtu, int promisc, int all_multi, int bcast, int vlanex,
  835. bool sleep_ok);
  836. int t4_alloc_mac_filt(struct adapter *adap, unsigned int mbox,
  837. unsigned int viid, bool free, unsigned int naddr,
  838. const u8 **addr, u16 *idx, u64 *hash, bool sleep_ok);
  839. int t4_change_mac(struct adapter *adap, unsigned int mbox, unsigned int viid,
  840. int idx, const u8 *addr, bool persist, bool add_smt);
  841. int t4_set_addr_hash(struct adapter *adap, unsigned int mbox, unsigned int viid,
  842. bool ucast, u64 vec, bool sleep_ok);
  843. int t4_enable_vi(struct adapter *adap, unsigned int mbox, unsigned int viid,
  844. bool rx_en, bool tx_en);
  845. int t4_identify_port(struct adapter *adap, unsigned int mbox, unsigned int viid,
  846. unsigned int nblinks);
  847. int t4_mdio_rd(struct adapter *adap, unsigned int mbox, unsigned int phy_addr,
  848. unsigned int mmd, unsigned int reg, u16 *valp);
  849. int t4_mdio_wr(struct adapter *adap, unsigned int mbox, unsigned int phy_addr,
  850. unsigned int mmd, unsigned int reg, u16 val);
  851. int t4_iq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
  852. unsigned int vf, unsigned int iqtype, unsigned int iqid,
  853. unsigned int fl0id, unsigned int fl1id);
  854. int t4_eth_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
  855. unsigned int vf, unsigned int eqid);
  856. int t4_ctrl_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
  857. unsigned int vf, unsigned int eqid);
  858. int t4_ofld_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
  859. unsigned int vf, unsigned int eqid);
  860. int t4_handle_fw_rpl(struct adapter *adap, const __be64 *rpl);
  861. void t4_db_full(struct adapter *adapter);
  862. void t4_db_dropped(struct adapter *adapter);
  863. int t4_mem_win_read_len(struct adapter *adap, u32 addr, __be32 *data, int len);
  864. int t4_fwaddrspace_write(struct adapter *adap, unsigned int mbox,
  865. u32 addr, u32 val);
  866. #endif /* __CXGB4_H__ */