fs_enet.h 7.0 KB

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