qfec.txt 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. Driver name: Qualcomm FSM9xxx Ethernet Driver
  2. Supported hardware: FSM9xxx Ethernet Controller
  3. Maintainer(s):
  4. Author(s):
  5. Introduction:
  6. =============
  7. The FSM9xxx Ethernet controller is register based with separate TX and RX DMA
  8. engines supporting scatter/gather and support 1EEE-1588 timestamping.
  9. MII, RevMII and RgMII interfaces are support. RgMII support 1G.
  10. The driver supports gather but not scatter, uses the controller DMA engines,
  11. and timestamping.
  12. Hardware description:
  13. =====================
  14. The Ethernet Controller is a memory mapped register device with two
  15. internal DMA engines for TX and RX path processing using separate
  16. buffer-descriptors (BD) allocated from non-cached main memory for the TX
  17. and RX paths. These BDs support scatter-gather but are only used to
  18. transfer single max sized Ethernet frames. The BDs are sequentially
  19. accessed as a ring, with an end-of-ring bit set in the last BD. Ownership
  20. bits control access by hardware and software to individual BDs.
  21. An additional 4 words of space can be configured and is allocated between
  22. each BD to store additional information about the sk_buff associated with it.
  23. The driver software uses 2 ring structures and local functions to manage
  24. them to keep in sync with the hardware the BDs . The number of BDs is
  25. determined from the space allocated for them (PAGE_SIZE). The ratio of RX
  26. to TX BD is set by a #define.
  27. Interrupts are used to service and replenish pre-allocated sk_buff for each
  28. RX BD. TX frames are allocated to a TX BD and transmitted frames are
  29. freed within the xmit() invoked to send the frame. No TX interrupts are
  30. processed since sk_buffs are freed in the xmit().
  31. Three PHY interfaces are supported: MII, RevMII and RgMII. The selected
  32. interface is determined from the resource structure (to be completed) and
  33. programmed into a register prior to resetting the Ethernet controller.
  34. Separate PLLs are managed to provide MAC/PHY clocks in RevMii and RgMii
  35. modes, and a 25mHz clock timestamping.
  36. Software description
  37. ====================
  38. Structures
  39. struct qfec_buf_desc {
  40. uint32_t status;
  41. uint32_t ctl;
  42. void *p_buf;
  43. void *next;
  44. };
  45. struct buf_desc {
  46. struct qfec_buf_desc desc; /* must be first */
  47. struct sk_buff *skb;
  48. void *buf_virt_addr;
  49. void *buf_phys_addr;
  50. uint32_t last_bd_flag;
  51. };
  52. struct ring {
  53. int head;
  54. int tail;
  55. int n_free;
  56. int len;
  57. };
  58. struct qfec_priv {
  59. struct net_device *net_dev;
  60. struct net_device_stats stats; /* req statistics */
  61. struct device dev;
  62. spinlock_t hw_lock;
  63. unsigned int state; /* driver state */
  64. void *bd_base; /* addr buf-desc */
  65. dma_addr_t tbd_dma; /* dma/phy-addr buf-desc */
  66. dma_addr_t rbd_dma; /* dma/phy-addr buf-desc */
  67. struct resource *mac_res;
  68. void *mac_base; /* mac (virt) base address */
  69. struct resource *clk_res;
  70. void *clk_base; /* clk (virt) base address */
  71. unsigned int n_tbd; /* # of TX buf-desc */
  72. struct ring ring_tbd; /* TX ring */
  73. struct buf_desc *p_tbd; /* # TX buf-desc */
  74. unsigned int n_rbd; /* # of RX buf-desc */
  75. struct ring ring_rbd; /* RX ring */
  76. struct buf_desc *p_rbd; /* # RX buf-desc */
  77. unsigned long cntr[cntr_last]; /* activity counters */
  78. struct mii_if_info mii;
  79. int mdio_clk; /* phy mdio clock rate */
  80. int phy_id; /* default PHY addr (0) */
  81. struct timer_list phy_tmr; /* monitor PHY state */
  82. };
  83. Initialization is divided between probe() and open() such that the
  84. net_device is allocated, the address space is mapped for register access,
  85. and procfs files created in probe(). BD memory is allocated and
  86. initialized along with interrupts and timers in open(). BD is not
  87. de-allocated in close() allowing it to be debugged after the interface is
  88. ifconfig down'd. This approach is intended to aid with debugging by
  89. allowing configuring the interface down and up may clear some early usage
  90. problems
  91. Phy link state changes are monitored using a timer using some existing
  92. functions from the mii library, but also with local functions intended to
  93. support RGMII in the future.
  94. A variety of information is accessible through procFs. Counters are used
  95. to track various driver events, these include abnormal and error
  96. interrupts. Hardware counters of various frame statistics (e.g. types and
  97. sizes of TX and RX frames) are available. Hardware registers and up to the
  98. 50 TX and RX BDs can be can be displayed. A table of procfs filenames and
  99. functions are used to create and delete the procfs entries as needed.
  100. Probe()
  101. Allocate and initialize the net_device structure with resource information
  102. specifying the Ethernet controller, clock control and MAC address memory
  103. regions. Set netdev_ops to a statically defined sub-structure supporting
  104. the device.
  105. Open()
  106. Use qfec_mem_alloc() to allocate space for the buffer-descriptors (BD).
  107. TX BDs are initialized by clearing the ownership bit of each. Each RX BD
  108. is initialized using qfec_rbd_init(). Qfec_rbd_init() pre-allocates an
  109. sk_buff, saving the addresses of both the sk_buff and its data buffer in the
  110. additional BD space, setting the BD buf pointer to the physical address of
  111. the sk_buff data, and finally setting the ownership bit.
  112. Once the BDs are initialized, interface selected register is set to the
  113. appropriate PHY interface configuration, and the Ethernet controller is
  114. reset and its registers initialized, including the starting addresses of
  115. the TX and RX BDs.
  116. The PHY monitor state is initialized and the timer initialized and started.
  117. Finally, the interrupt for the Ethernet controller is initialized.
  118. Note - Interrupts from both from the external PHY and internal RevMii
  119. PHY, are available, but neither is used in preference to the
  120. timer.
  121. Interrupt Processing
  122. Besides recognizing abnormal error interrupts, RX, TX and GMAC interrupts
  123. are recognized, although TX and GMAC interrupts are ignored but cleared and
  124. counted. (The gmac interrupt can be ignored but must be disabled).
  125. RX interrupts invoke a handler to process the received frame, send it
  126. to the stack and re-allocate a replacement sk_bufff for the buffer-
  127. descriptor.
  128. Receive Processing
  129. The RX buffer descriptors are initialized by _open() using qfec_rbd_init()
  130. which pre-allocated an sk_buff, saving its address and the physical address
  131. of its data in the additional BD space, as well as writing the physical
  132. address to the BD pbuf entry read by HW. The size of the buffer and
  133. other control information are written to the BD, as well as setting the
  134. ownership bit.
  135. A received frame generates an interrupt invoking qfec_rx_int(). It
  136. repeatedly checks the ownership the next available BD, and passing the
  137. sk_buff containing the received frame to the stack via netif_rx().
  138. Once all received frames are processed, it repeatedly calls qfec_rbd_init()
  139. to allocate a new sk_buff with each available BD.
  140. Transmit Processing
  141. Frames are transmitted through the start_xmit callback function.
  142. qfec_tx_replenish() is immediately called to free sk_buffs from BD
  143. that have been transmitted, before checking is a BD is available.
  144. The sk_buff address is stored in the additional BD space and the
  145. physical address of its data is store in the pbuf BD entry used
  146. by the HW. The TX poll-demand register is accessed, causing the
  147. HW to recheck the current BD and process it.
  148. While the TX interrupt could be processed to free sk_buffs as BD
  149. are processed, they are ignored since the sk_buffs will be freed
  150. with each call to _xmit().
  151. procfs
  152. debug files are available to display the controller registers,
  153. frame counters from the controller, driver activity counters, and
  154. the first 50 entries of the RX and TX buffer descriptors.
  155. Callbacks
  156. In addition to the functions described above, the following functions
  157. are used to support their correspondingly named device operations:
  158. qfec_stop
  159. qfec_do_ioctl
  160. qfec_tx_timeout
  161. qfec_set_mac_address
  162. qfec_get_stats
  163. qfec_set_config
  164. eth_change_mtu
  165. eth_validate_addr
  166. Power Management
  167. ================
  168. None
  169. Interface:
  170. ==========
  171. - Module-init/exit
  172. - standard network interface functions
  173. Module parameters:
  174. ==================
  175. static struct resource qfec_resources [] = {
  176. [0] = {
  177. .start = QFEC_MAC_BASE,
  178. .end = QFEC_MAC_BASE + QFEC_MAC_SIZE,
  179. .flags = IORESOURCE_MEM,
  180. },
  181. [1] = {
  182. .start = QFEC_MAC_IRQ,
  183. .end = QFEC_MAC_IRQ,
  184. .flags = IORESOURCE_IRQ,
  185. },
  186. [2] = {
  187. .start = QFEC_CLK_BASE,
  188. .end = QFEC_CLK_BASE + QFEC_CLK_SIZE,
  189. .flags = IORESOURCE_IO,
  190. },
  191. [3] = {
  192. .start = QFEC_MAC_FUSE_BASE,
  193. .end = QFEC_MAC_FUSE_BASE + QFEC_MAC_FUSE_SIZE,
  194. .flags = IORESOURCE_DMA,
  195. },
  196. };
  197. static struct platform_device qfec_device = {
  198. .name = "qfec",
  199. .id = 0,
  200. .num_resources = ARRAY_SIZE(qfec_resources),
  201. .resource = qfec_resources,
  202. };
  203. Resource entries exist for three address regions and one interrupt. The
  204. interrupt is identified as IORESOURCE_IRQ, the controller registers as
  205. OPRESOURCE_MEM, the clock control registers as IORESOURCE_IO, and the
  206. MAC address fuses as IORESOURCE_DMA.
  207. Dependencies:
  208. =============
  209. None
  210. User space utilities:
  211. =====================
  212. See procfs descriptions
  213. Known issues:
  214. =============
  215. - replace procfs w/ debugfs
  216. To do:
  217. ======
  218. - specify interface (MII/RevMII/RgMii) in resource structure
  219. - RevMii support untested
  220. - RgMii (10/100/1000)
  221. - generic timestamp support