cxgb4.h 35 KB

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