fs_enet.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. #ifndef FS_ENET_H
  2. #define FS_ENET_H
  3. #include <linux/mii.h>
  4. #include <linux/netdevice.h>
  5. #include <linux/types.h>
  6. #include <linux/list.h>
  7. #include <linux/phy.h>
  8. #include <linux/dma-mapping.h>
  9. #include <linux/fs_enet_pd.h>
  10. #ifdef CONFIG_CPM1
  11. #include <asm/commproc.h>
  12. struct fec_info {
  13. fec_t* fecp;
  14. u32 mii_speed;
  15. };
  16. #endif
  17. #ifdef CONFIG_CPM2
  18. #include <asm/cpm2.h>
  19. #endif
  20. /* This is used to operate with pins.
  21. Note that the actual port size may
  22. be different; cpm(s) handle it OK */
  23. struct bb_info {
  24. u8 mdio_dat_msk;
  25. u8 mdio_dir_msk;
  26. u8 *mdio_dir;
  27. u8 *mdio_dat;
  28. u8 mdc_msk;
  29. u8 *mdc_dat;
  30. int delay;
  31. };
  32. /* hw driver ops */
  33. struct fs_ops {
  34. int (*setup_data)(struct net_device *dev);
  35. int (*allocate_bd)(struct net_device *dev);
  36. void (*free_bd)(struct net_device *dev);
  37. void (*cleanup_data)(struct net_device *dev);
  38. void (*set_multicast_list)(struct net_device *dev);
  39. void (*adjust_link)(struct net_device *dev);
  40. void (*restart)(struct net_device *dev);
  41. void (*stop)(struct net_device *dev);
  42. void (*pre_request_irq)(struct net_device *dev, int irq);
  43. void (*post_free_irq)(struct net_device *dev, int irq);
  44. void (*napi_clear_rx_event)(struct net_device *dev);
  45. void (*napi_enable_rx)(struct net_device *dev);
  46. void (*napi_disable_rx)(struct net_device *dev);
  47. void (*rx_bd_done)(struct net_device *dev);
  48. void (*tx_kickstart)(struct net_device *dev);
  49. u32 (*get_int_events)(struct net_device *dev);
  50. void (*clear_int_events)(struct net_device *dev, u32 int_events);
  51. void (*ev_error)(struct net_device *dev, u32 int_events);
  52. int (*get_regs)(struct net_device *dev, void *p, int *sizep);
  53. int (*get_regs_len)(struct net_device *dev);
  54. void (*tx_restart)(struct net_device *dev);
  55. };
  56. struct phy_info {
  57. unsigned int id;
  58. const char *name;
  59. void (*startup) (struct net_device * dev);
  60. void (*shutdown) (struct net_device * dev);
  61. void (*ack_int) (struct net_device * dev);
  62. };
  63. /* The FEC stores dest/src/type, data, and checksum for receive packets.
  64. */
  65. #define MAX_MTU 1508 /* Allow fullsized pppoe packets over VLAN */
  66. #define MIN_MTU 46 /* this is data size */
  67. #define CRC_LEN 4
  68. #define PKT_MAXBUF_SIZE (MAX_MTU+ETH_HLEN+CRC_LEN)
  69. #define PKT_MINBUF_SIZE (MIN_MTU+ETH_HLEN+CRC_LEN)
  70. /* Must be a multiple of 32 (to cover both FEC & FCC) */
  71. #define PKT_MAXBLR_SIZE ((PKT_MAXBUF_SIZE + 31) & ~31)
  72. /* This is needed so that invalidate_xxx wont invalidate too much */
  73. #define ENET_RX_FRSIZE L1_CACHE_ALIGN(PKT_MAXBUF_SIZE)
  74. struct fs_enet_mii_bus {
  75. struct list_head list;
  76. spinlock_t mii_lock;
  77. const struct fs_mii_bus_info *bus_info;
  78. int refs;
  79. u32 usage_map;
  80. int (*mii_read)(struct fs_enet_mii_bus *bus,
  81. int phy_id, int location);
  82. void (*mii_write)(struct fs_enet_mii_bus *bus,
  83. int phy_id, int location, int value);
  84. union {
  85. struct {
  86. unsigned int mii_speed;
  87. void *fecp;
  88. } fec;
  89. struct {
  90. /* note that the actual port size may */
  91. /* be different; cpm(s) handle it OK */
  92. u8 mdio_msk;
  93. u8 *mdio_dir;
  94. u8 *mdio_dat;
  95. u8 mdc_msk;
  96. u8 *mdc_dir;
  97. u8 *mdc_dat;
  98. } bitbang;
  99. struct {
  100. u16 lpa;
  101. } fixed;
  102. };
  103. };
  104. struct fs_enet_private {
  105. struct device *dev; /* pointer back to the device (must be initialized first) */
  106. spinlock_t lock; /* during all ops except TX pckt processing */
  107. spinlock_t tx_lock; /* during fs_start_xmit and fs_tx */
  108. const struct fs_platform_info *fpi;
  109. const struct fs_ops *ops;
  110. int rx_ring, tx_ring;
  111. dma_addr_t ring_mem_addr;
  112. void *ring_base;
  113. struct sk_buff **rx_skbuff;
  114. struct sk_buff **tx_skbuff;
  115. cbd_t *rx_bd_base; /* Address of Rx and Tx buffers. */
  116. cbd_t *tx_bd_base;
  117. cbd_t *dirty_tx; /* ring entries to be free()ed. */
  118. cbd_t *cur_rx;
  119. cbd_t *cur_tx;
  120. int tx_free;
  121. struct net_device_stats stats;
  122. struct timer_list phy_timer_list;
  123. const struct phy_info *phy;
  124. u32 msg_enable;
  125. struct mii_if_info mii_if;
  126. unsigned int last_mii_status;
  127. struct fs_enet_mii_bus *mii_bus;
  128. int interrupt;
  129. struct phy_device *phydev;
  130. int oldduplex, oldspeed, oldlink; /* current settings */
  131. /* event masks */
  132. u32 ev_napi_rx; /* mask of NAPI rx events */
  133. u32 ev_rx; /* rx event mask */
  134. u32 ev_tx; /* tx event mask */
  135. u32 ev_err; /* error event mask */
  136. u16 bd_rx_empty; /* mask of BD rx empty */
  137. u16 bd_rx_err; /* mask of BD rx errors */
  138. union {
  139. struct {
  140. int idx; /* FEC1 = 0, FEC2 = 1 */
  141. void *fecp; /* hw registers */
  142. u32 hthi, htlo; /* state for multicast */
  143. } fec;
  144. struct {
  145. int idx; /* FCC1-3 = 0-2 */
  146. void *fccp; /* hw registers */
  147. void *ep; /* parameter ram */
  148. void *fcccp; /* hw registers cont. */
  149. void *mem; /* FCC DPRAM */
  150. u32 gaddrh, gaddrl; /* group address */
  151. } fcc;
  152. struct {
  153. int idx; /* FEC1 = 0, FEC2 = 1 */
  154. void *sccp; /* hw registers */
  155. void *ep; /* parameter ram */
  156. u32 hthi, htlo; /* state for multicast */
  157. } scc;
  158. };
  159. };
  160. /***************************************************************************/
  161. int fs_enet_mdio_bb_init(void);
  162. int fs_mii_fixed_init(struct fs_enet_mii_bus *bus);
  163. int fs_enet_mdio_fec_init(void);
  164. void fs_init_bds(struct net_device *dev);
  165. void fs_cleanup_bds(struct net_device *dev);
  166. /***************************************************************************/
  167. #define DRV_MODULE_NAME "fs_enet"
  168. #define PFX DRV_MODULE_NAME ": "
  169. #define DRV_MODULE_VERSION "1.0"
  170. #define DRV_MODULE_RELDATE "Aug 8, 2005"
  171. /***************************************************************************/
  172. int fs_enet_platform_init(void);
  173. void fs_enet_platform_cleanup(void);
  174. /***************************************************************************/
  175. /* buffer descriptor access macros */
  176. /* access macros */
  177. #if defined(CONFIG_CPM1)
  178. /* for a a CPM1 __raw_xxx's are sufficient */
  179. #define __cbd_out32(addr, x) __raw_writel(x, addr)
  180. #define __cbd_out16(addr, x) __raw_writew(x, addr)
  181. #define __cbd_in32(addr) __raw_readl(addr)
  182. #define __cbd_in16(addr) __raw_readw(addr)
  183. #else
  184. /* for others play it safe */
  185. #define __cbd_out32(addr, x) out_be32(addr, x)
  186. #define __cbd_out16(addr, x) out_be16(addr, x)
  187. #define __cbd_in32(addr) in_be32(addr)
  188. #define __cbd_in16(addr) in_be16(addr)
  189. #endif
  190. /* write */
  191. #define CBDW_SC(_cbd, _sc) __cbd_out16(&(_cbd)->cbd_sc, (_sc))
  192. #define CBDW_DATLEN(_cbd, _datlen) __cbd_out16(&(_cbd)->cbd_datlen, (_datlen))
  193. #define CBDW_BUFADDR(_cbd, _bufaddr) __cbd_out32(&(_cbd)->cbd_bufaddr, (_bufaddr))
  194. /* read */
  195. #define CBDR_SC(_cbd) __cbd_in16(&(_cbd)->cbd_sc)
  196. #define CBDR_DATLEN(_cbd) __cbd_in16(&(_cbd)->cbd_datlen)
  197. #define CBDR_BUFADDR(_cbd) __cbd_in32(&(_cbd)->cbd_bufaddr)
  198. /* set bits */
  199. #define CBDS_SC(_cbd, _sc) CBDW_SC(_cbd, CBDR_SC(_cbd) | (_sc))
  200. /* clear bits */
  201. #define CBDC_SC(_cbd, _sc) CBDW_SC(_cbd, CBDR_SC(_cbd) & ~(_sc))
  202. /*******************************************************************/
  203. extern const struct fs_ops fs_fec_ops;
  204. extern const struct fs_ops fs_fcc_ops;
  205. extern const struct fs_ops fs_scc_ops;
  206. /*******************************************************************/
  207. /* handy pointer to the immap */
  208. extern void *fs_enet_immap;
  209. /*******************************************************************/
  210. #endif