adapter.h 8.4 KB

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