cxgb4.h 35 KB

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