adapter.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*
  2. * This file is part of the Chelsio T3 Ethernet driver for Linux.
  3. *
  4. * Copyright (C) 2003-2006 Chelsio Communications. All rights reserved.
  5. *
  6. * This program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  8. * FITNESS FOR A PARTICULAR PURPOSE. See the LICENSE file included in this
  9. * release for licensing terms and conditions.
  10. */
  11. /* This file should not be included directly. Include common.h instead. */
  12. #ifndef __T3_ADAPTER_H__
  13. #define __T3_ADAPTER_H__
  14. #include <linux/pci.h>
  15. #include <linux/spinlock.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/timer.h>
  18. #include <linux/cache.h>
  19. #include "t3cdev.h"
  20. #include <asm/semaphore.h>
  21. #include <asm/bitops.h>
  22. #include <asm/io.h>
  23. typedef irqreturn_t(*intr_handler_t) (int, void *);
  24. struct vlan_group;
  25. struct port_info {
  26. struct vlan_group *vlan_grp;
  27. const struct port_type_info *port_type;
  28. u8 port_id;
  29. u8 rx_csum_offload;
  30. u8 nqsets;
  31. u8 first_qset;
  32. struct cphy phy;
  33. struct cmac mac;
  34. struct link_config link_config;
  35. struct net_device_stats netstats;
  36. int activity;
  37. };
  38. enum { /* adapter flags */
  39. FULL_INIT_DONE = (1 << 0),
  40. USING_MSI = (1 << 1),
  41. USING_MSIX = (1 << 2),
  42. };
  43. struct rx_desc;
  44. struct rx_sw_desc;
  45. struct sge_fl { /* SGE per free-buffer list state */
  46. unsigned int buf_size; /* size of each Rx buffer */
  47. unsigned int credits; /* # of available Rx buffers */
  48. unsigned int size; /* capacity of free list */
  49. unsigned int cidx; /* consumer index */
  50. unsigned int pidx; /* producer index */
  51. unsigned int gen; /* free list generation */
  52. struct rx_desc *desc; /* address of HW Rx descriptor ring */
  53. struct rx_sw_desc *sdesc; /* address of SW Rx descriptor ring */
  54. dma_addr_t phys_addr; /* physical address of HW ring start */
  55. unsigned int cntxt_id; /* SGE context id for the free list */
  56. unsigned long empty; /* # of times queue ran out of buffers */
  57. };
  58. /*
  59. * Bundle size for grouping offload RX packets for delivery to the stack.
  60. * Don't make this too big as we do prefetch on each packet in a bundle.
  61. */
  62. # define RX_BUNDLE_SIZE 8
  63. struct rsp_desc;
  64. struct sge_rspq { /* state for an SGE response queue */
  65. unsigned int credits; /* # of pending response credits */
  66. unsigned int size; /* capacity of response queue */
  67. unsigned int cidx; /* consumer index */
  68. unsigned int gen; /* current generation bit */
  69. unsigned int polling; /* is the queue serviced through NAPI? */
  70. unsigned int holdoff_tmr; /* interrupt holdoff timer in 100ns */
  71. unsigned int next_holdoff; /* holdoff time for next interrupt */
  72. struct rsp_desc *desc; /* address of HW response ring */
  73. dma_addr_t phys_addr; /* physical address of the ring */
  74. unsigned int cntxt_id; /* SGE context id for the response q */
  75. spinlock_t lock; /* guards response processing */
  76. struct sk_buff *rx_head; /* offload packet receive queue head */
  77. struct sk_buff *rx_tail; /* offload packet receive queue tail */
  78. unsigned long offload_pkts;
  79. unsigned long offload_bundles;
  80. unsigned long eth_pkts; /* # of ethernet packets */
  81. unsigned long pure_rsps; /* # of pure (non-data) responses */
  82. unsigned long imm_data; /* responses with immediate data */
  83. unsigned long rx_drops; /* # of packets dropped due to no mem */
  84. unsigned long async_notif; /* # of asynchronous notification events */
  85. unsigned long empty; /* # of times queue ran out of credits */
  86. unsigned long nomem; /* # of responses deferred due to no mem */
  87. unsigned long unhandled_irqs; /* # of spurious intrs */
  88. };
  89. struct tx_desc;
  90. struct tx_sw_desc;
  91. struct sge_txq { /* state for an SGE Tx queue */
  92. unsigned long flags; /* HW DMA fetch status */
  93. unsigned int in_use; /* # of in-use Tx descriptors */
  94. unsigned int size; /* # of descriptors */
  95. unsigned int processed; /* total # of descs HW has processed */
  96. unsigned int cleaned; /* total # of descs SW has reclaimed */
  97. unsigned int stop_thres; /* SW TX queue suspend threshold */
  98. unsigned int cidx; /* consumer index */
  99. unsigned int pidx; /* producer index */
  100. unsigned int gen; /* current value of generation bit */
  101. unsigned int unacked; /* Tx descriptors used since last COMPL */
  102. struct tx_desc *desc; /* address of HW Tx descriptor ring */
  103. struct tx_sw_desc *sdesc; /* address of SW Tx descriptor ring */
  104. spinlock_t lock; /* guards enqueueing of new packets */
  105. unsigned int token; /* WR token */
  106. dma_addr_t phys_addr; /* physical address of the ring */
  107. struct sk_buff_head sendq; /* List of backpressured offload packets */
  108. struct tasklet_struct qresume_tsk; /* restarts the queue */
  109. unsigned int cntxt_id; /* SGE context id for the Tx q */
  110. unsigned long stops; /* # of times q has been stopped */
  111. unsigned long restarts; /* # of queue restarts */
  112. };
  113. enum { /* per port SGE statistics */
  114. SGE_PSTAT_TSO, /* # of TSO requests */
  115. SGE_PSTAT_RX_CSUM_GOOD, /* # of successful RX csum offloads */
  116. SGE_PSTAT_TX_CSUM, /* # of TX checksum offloads */
  117. SGE_PSTAT_VLANEX, /* # of VLAN tag extractions */
  118. SGE_PSTAT_VLANINS, /* # of VLAN tag insertions */
  119. SGE_PSTAT_MAX /* must be last */
  120. };
  121. struct sge_qset { /* an SGE queue set */
  122. struct sge_rspq rspq;
  123. struct sge_fl fl[SGE_RXQ_PER_SET];
  124. struct sge_txq txq[SGE_TXQ_PER_SET];
  125. struct net_device *netdev; /* associated net device */
  126. unsigned long txq_stopped; /* which Tx queues are stopped */
  127. struct timer_list tx_reclaim_timer; /* reclaims TX buffers */
  128. unsigned long port_stats[SGE_PSTAT_MAX];
  129. } ____cacheline_aligned;
  130. struct sge {
  131. struct sge_qset qs[SGE_QSETS];
  132. spinlock_t reg_lock; /* guards non-atomic SGE registers (eg context) */
  133. };
  134. struct adapter {
  135. struct t3cdev tdev;
  136. struct list_head adapter_list;
  137. void __iomem *regs;
  138. struct pci_dev *pdev;
  139. unsigned long registered_device_map;
  140. unsigned long open_device_map;
  141. unsigned long flags;
  142. const char *name;
  143. int msg_enable;
  144. unsigned int mmio_len;
  145. struct adapter_params params;
  146. unsigned int slow_intr_mask;
  147. unsigned long irq_stats[IRQ_NUM_STATS];
  148. struct {
  149. unsigned short vec;
  150. char desc[22];
  151. } msix_info[SGE_QSETS + 1];
  152. /* T3 modules */
  153. struct sge sge;
  154. struct mc7 pmrx;
  155. struct mc7 pmtx;
  156. struct mc7 cm;
  157. struct mc5 mc5;
  158. struct net_device *port[MAX_NPORTS];
  159. unsigned int check_task_cnt;
  160. struct delayed_work adap_check_task;
  161. struct work_struct ext_intr_handler_task;
  162. /*
  163. * Dummy netdevices are needed when using multiple receive queues with
  164. * NAPI as each netdevice can service only one queue.
  165. */
  166. struct net_device *dummy_netdev[SGE_QSETS - 1];
  167. struct dentry *debugfs_root;
  168. struct mutex mdio_lock;
  169. spinlock_t stats_lock;
  170. spinlock_t work_lock;
  171. };
  172. static inline u32 t3_read_reg(struct adapter *adapter, u32 reg_addr)
  173. {
  174. u32 val = readl(adapter->regs + reg_addr);
  175. CH_DBG(adapter, MMIO, "read register 0x%x value 0x%x\n", reg_addr, val);
  176. return val;
  177. }
  178. static inline void t3_write_reg(struct adapter *adapter, u32 reg_addr, u32 val)
  179. {
  180. CH_DBG(adapter, MMIO, "setting register 0x%x to 0x%x\n", reg_addr, val);
  181. writel(val, adapter->regs + reg_addr);
  182. }
  183. static inline struct port_info *adap2pinfo(struct adapter *adap, int idx)
  184. {
  185. return netdev_priv(adap->port[idx]);
  186. }
  187. /*
  188. * We use the spare atalk_ptr to map a net device to its SGE queue set.
  189. * This is a macro so it can be used as l-value.
  190. */
  191. #define dev2qset(netdev) ((netdev)->atalk_ptr)
  192. #define OFFLOAD_DEVMAP_BIT 15
  193. #define tdev2adap(d) container_of(d, struct adapter, tdev)
  194. static inline int offload_running(struct adapter *adapter)
  195. {
  196. return test_bit(OFFLOAD_DEVMAP_BIT, &adapter->open_device_map);
  197. }
  198. int t3_offload_tx(struct t3cdev *tdev, struct sk_buff *skb);
  199. void t3_os_ext_intr_handler(struct adapter *adapter);
  200. void t3_os_link_changed(struct adapter *adapter, int port_id, int link_status,
  201. int speed, int duplex, int fc);
  202. void t3_sge_start(struct adapter *adap);
  203. void t3_sge_stop(struct adapter *adap);
  204. void t3_free_sge_resources(struct adapter *adap);
  205. void t3_sge_err_intr_handler(struct adapter *adapter);
  206. intr_handler_t t3_intr_handler(struct adapter *adap, int polling);
  207. int t3_eth_xmit(struct sk_buff *skb, struct net_device *dev);
  208. void t3_update_qset_coalesce(struct sge_qset *qs, const struct qset_params *p);
  209. int t3_sge_alloc_qset(struct adapter *adapter, unsigned int id, int nports,
  210. int irq_vec_idx, const struct qset_params *p,
  211. int ntxq, struct net_device *netdev);
  212. int t3_get_desc(const struct sge_qset *qs, unsigned int qnum, unsigned int idx,
  213. unsigned char *data);
  214. irqreturn_t t3_sge_intr_msix(int irq, void *cookie);
  215. #endif /* __T3_ADAPTER_H__ */