ps3_gelic_net.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. /*
  2. * PS3 Platfom gelic network driver.
  3. *
  4. * Copyright (C) 2007 Sony Computer Entertainment Inc.
  5. * Copyright 2006, 2007 Sony Corporation.
  6. *
  7. * This file is based on: spider_net.h
  8. *
  9. * (C) Copyright IBM Corp. 2005
  10. *
  11. * Authors : Utz Bacher <utz.bacher@de.ibm.com>
  12. * Jens Osterkamp <Jens.Osterkamp@de.ibm.com>
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2, or (at your option)
  17. * any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  27. */
  28. #ifndef _GELIC_NET_H
  29. #define _GELIC_NET_H
  30. /* descriptors */
  31. #define GELIC_NET_RX_DESCRIPTORS 128 /* num of descriptors */
  32. #define GELIC_NET_TX_DESCRIPTORS 128 /* num of descriptors */
  33. #define GELIC_NET_MAX_MTU VLAN_ETH_FRAME_LEN
  34. #define GELIC_NET_MIN_MTU VLAN_ETH_ZLEN
  35. #define GELIC_NET_RXBUF_ALIGN 128
  36. #define GELIC_CARD_RX_CSUM_DEFAULT 1 /* hw chksum */
  37. #define GELIC_NET_WATCHDOG_TIMEOUT 5*HZ
  38. #define GELIC_NET_NAPI_WEIGHT (GELIC_NET_RX_DESCRIPTORS)
  39. #define GELIC_NET_BROADCAST_ADDR 0xffffffffffffL
  40. #define GELIC_NET_MC_COUNT_MAX 32 /* multicast address list */
  41. /* virtual interrupt status register bits */
  42. /* INT1 */
  43. #define GELIC_CARD_TX_RAM_FULL_ERR 0x0000000000000001L
  44. #define GELIC_CARD_RX_RAM_FULL_ERR 0x0000000000000002L
  45. #define GELIC_CARD_TX_SHORT_FRAME_ERR 0x0000000000000004L
  46. #define GELIC_CARD_TX_INVALID_DESCR_ERR 0x0000000000000008L
  47. #define GELIC_CARD_RX_FIFO_FULL_ERR 0x0000000000002000L
  48. #define GELIC_CARD_RX_DESCR_CHAIN_END 0x0000000000004000L
  49. #define GELIC_CARD_RX_INVALID_DESCR_ERR 0x0000000000008000L
  50. #define GELIC_CARD_TX_RESPONCE_ERR 0x0000000000010000L
  51. #define GELIC_CARD_RX_RESPONCE_ERR 0x0000000000100000L
  52. #define GELIC_CARD_TX_PROTECTION_ERR 0x0000000000400000L
  53. #define GELIC_CARD_RX_PROTECTION_ERR 0x0000000004000000L
  54. #define GELIC_CARD_TX_TCP_UDP_CHECKSUM_ERR 0x0000000008000000L
  55. #define GELIC_CARD_PORT_STATUS_CHANGED 0x0000000020000000L
  56. #define GELIC_CARD_WLAN_EVENT_RECEIVED 0x0000000040000000L
  57. #define GELIC_CARD_WLAN_COMMAND_COMPLETED 0x0000000080000000L
  58. /* INT 0 */
  59. #define GELIC_CARD_TX_FLAGGED_DESCR 0x0004000000000000L
  60. #define GELIC_CARD_RX_FLAGGED_DESCR 0x0040000000000000L
  61. #define GELIC_CARD_TX_TRANSFER_END 0x0080000000000000L
  62. #define GELIC_CARD_TX_DESCR_CHAIN_END 0x0100000000000000L
  63. #define GELIC_CARD_NUMBER_OF_RX_FRAME 0x1000000000000000L
  64. #define GELIC_CARD_ONE_TIME_COUNT_TIMER 0x4000000000000000L
  65. #define GELIC_CARD_FREE_RUN_COUNT_TIMER 0x8000000000000000L
  66. /* initial interrupt mask */
  67. #define GELIC_CARD_TXINT GELIC_CARD_TX_DESCR_CHAIN_END
  68. #define GELIC_CARD_RXINT (GELIC_CARD_RX_DESCR_CHAIN_END | \
  69. GELIC_CARD_NUMBER_OF_RX_FRAME)
  70. /* RX descriptor data_status bits */
  71. enum gelic_descr_rx_status {
  72. GELIC_DESCR_RXDMADU = 0x80000000, /* destination MAC addr unknown */
  73. GELIC_DESCR_RXLSTFBF = 0x40000000, /* last frame buffer */
  74. GELIC_DESCR_RXIPCHK = 0x20000000, /* IP checksum performed */
  75. GELIC_DESCR_RXTCPCHK = 0x10000000, /* TCP/UDP checksup performed */
  76. GELIC_DESCR_RXWTPKT = 0x00C00000, /*
  77. * wakeup trigger packet
  78. * 01: Magic Packet (TM)
  79. * 10: ARP packet
  80. * 11: Multicast MAC addr
  81. */
  82. GELIC_DESCR_RXVLNPKT = 0x00200000, /* VLAN packet */
  83. /* bit 20..16 reserved */
  84. GELIC_DESCR_RXRRECNUM = 0x0000ff00, /* reception receipt number */
  85. /* bit 7..0 reserved */
  86. };
  87. #define GELIC_DESCR_DATA_STATUS_CHK_MASK \
  88. (GELIC_DESCR_RXIPCHK | GELIC_DESCR_RXTCPCHK)
  89. /* TX descriptor data_status bits */
  90. enum gelic_descr_tx_status {
  91. GELIC_DESCR_TX_TAIL = 0x00000001, /* gelic treated this
  92. * descriptor was end of
  93. * a tx frame
  94. */
  95. };
  96. /* RX descriptor data error bits */
  97. enum gelic_descr_rx_error {
  98. /* bit 31 reserved */
  99. GELIC_DESCR_RXALNERR = 0x40000000, /* alignement error 10/100M */
  100. GELIC_DESCR_RXOVERERR = 0x20000000, /* oversize error */
  101. GELIC_DESCR_RXRNTERR = 0x10000000, /* Runt error */
  102. GELIC_DESCR_RXIPCHKERR = 0x08000000, /* IP checksum error */
  103. GELIC_DESCR_RXTCPCHKERR = 0x04000000, /* TCP/UDP checksum error */
  104. GELIC_DESCR_RXDRPPKT = 0x00100000, /* drop packet */
  105. GELIC_DESCR_RXIPFMTERR = 0x00080000, /* IP packet format error */
  106. /* bit 18 reserved */
  107. GELIC_DESCR_RXDATAERR = 0x00020000, /* IP packet format error */
  108. GELIC_DESCR_RXCALERR = 0x00010000, /* cariier extension length
  109. * error */
  110. GELIC_DESCR_RXCREXERR = 0x00008000, /* carrier extension error */
  111. GELIC_DESCR_RXMLTCST = 0x00004000, /* multicast address frame */
  112. /* bit 13..0 reserved */
  113. };
  114. #define GELIC_DESCR_DATA_ERROR_CHK_MASK \
  115. (GELIC_DESCR_RXIPCHKERR | GELIC_DESCR_RXTCPCHKERR)
  116. /* DMA command and status (RX and TX)*/
  117. enum gelic_descr_dma_status {
  118. GELIC_DESCR_DMA_COMPLETE = 0x00000000, /* used in tx */
  119. GELIC_DESCR_DMA_BUFFER_FULL = 0x00000000, /* used in rx */
  120. GELIC_DESCR_DMA_RESPONSE_ERROR = 0x10000000, /* used in rx, tx */
  121. GELIC_DESCR_DMA_PROTECTION_ERROR = 0x20000000, /* used in rx, tx */
  122. GELIC_DESCR_DMA_FRAME_END = 0x40000000, /* used in rx */
  123. GELIC_DESCR_DMA_FORCE_END = 0x50000000, /* used in rx, tx */
  124. GELIC_DESCR_DMA_CARDOWNED = 0xa0000000, /* used in rx, tx */
  125. GELIC_DESCR_DMA_NOT_IN_USE = 0xb0000000, /* any other value */
  126. };
  127. #define GELIC_DESCR_DMA_STAT_MASK (0xf0000000)
  128. /* tx descriptor command and status */
  129. enum gelic_descr_tx_dma_status {
  130. /* [19] */
  131. GELIC_DESCR_TX_DMA_IKE = 0x00080000, /* IPSEC off */
  132. /* [18] */
  133. GELIC_DESCR_TX_DMA_FRAME_TAIL = 0x00040000, /* last descriptor of
  134. * the packet
  135. */
  136. /* [17..16] */
  137. GELIC_DESCR_TX_DMA_TCP_CHKSUM = 0x00020000, /* TCP packet */
  138. GELIC_DESCR_TX_DMA_UDP_CHKSUM = 0x00030000, /* UDP packet */
  139. GELIC_DESCR_TX_DMA_NO_CHKSUM = 0x00000000, /* no checksum */
  140. /* [1] */
  141. GELIC_DESCR_TX_DMA_CHAIN_END = 0x00000002, /* DMA terminated
  142. * due to chain end
  143. */
  144. };
  145. #define GELIC_DESCR_DMA_CMD_NO_CHKSUM \
  146. (GELIC_DESCR_DMA_CARDOWNED | GELIC_DESCR_TX_DMA_IKE | \
  147. GELIC_DESCR_TX_DMA_NO_CHKSUM)
  148. #define GELIC_DESCR_DMA_CMD_TCP_CHKSUM \
  149. (GELIC_DESCR_DMA_CARDOWNED | GELIC_DESCR_TX_DMA_IKE | \
  150. GELIC_DESCR_TX_DMA_TCP_CHKSUM)
  151. #define GELIC_DESCR_DMA_CMD_UDP_CHKSUM \
  152. (GELIC_DESCR_DMA_CARDOWNED | GELIC_DESCR_TX_DMA_IKE | \
  153. GELIC_DESCR_TX_DMA_UDP_CHKSUM)
  154. enum gelic_descr_rx_dma_status {
  155. /* [ 1 ] */
  156. GELIC_DESCR_RX_DMA_CHAIN_END = 0x00000002, /* DMA terminated
  157. * due to chain end
  158. */
  159. };
  160. /* for lv1_net_control */
  161. enum gelic_lv1_net_control_code {
  162. GELIC_LV1_GET_MAC_ADDRESS = 1,
  163. GELIC_LV1_GET_ETH_PORT_STATUS = 2,
  164. GELIC_LV1_SET_NEGOTIATION_MODE = 3,
  165. GELIC_LV1_GET_VLAN_ID = 4,
  166. GELIC_LV1_SET_WOL = 5,
  167. GELIC_LV1_GET_CHANNEL = 6,
  168. GELIC_LV1_POST_WLAN_CMD = 9,
  169. GELIC_LV1_GET_WLAN_CMD_RESULT = 10,
  170. GELIC_LV1_GET_WLAN_EVENT = 11,
  171. };
  172. /* for GELIC_LV1_SET_WOL */
  173. enum gelic_lv1_wol_command {
  174. GELIC_LV1_WOL_MAGIC_PACKET = 1,
  175. GELIC_LV1_WOL_ADD_MATCH_ADDR = 6,
  176. GELIC_LV1_WOL_DELETE_MATCH_ADDR = 7,
  177. };
  178. /* for GELIC_LV1_WOL_MAGIC_PACKET */
  179. enum gelic_lv1_wol_mp_arg {
  180. GELIC_LV1_WOL_MP_DISABLE = 0,
  181. GELIC_LV1_WOL_MP_ENABLE = 1,
  182. };
  183. /* for GELIC_LV1_WOL_{ADD,DELETE}_MATCH_ADDR */
  184. enum gelic_lv1_wol_match_arg {
  185. GELIC_LV1_WOL_MATCH_INDIVIDUAL = 0,
  186. GELIC_LV1_WOL_MATCH_ALL = 1,
  187. };
  188. /* status returened from GET_ETH_PORT_STATUS */
  189. enum gelic_lv1_ether_port_status {
  190. GELIC_LV1_ETHER_LINK_UP = 0x0000000000000001L,
  191. GELIC_LV1_ETHER_FULL_DUPLEX = 0x0000000000000002L,
  192. GELIC_LV1_ETHER_AUTO_NEG = 0x0000000000000004L,
  193. GELIC_LV1_ETHER_SPEED_10 = 0x0000000000000010L,
  194. GELIC_LV1_ETHER_SPEED_100 = 0x0000000000000020L,
  195. GELIC_LV1_ETHER_SPEED_1000 = 0x0000000000000040L,
  196. GELIC_LV1_ETHER_SPEED_MASK = 0x0000000000000070L,
  197. };
  198. enum gelic_lv1_vlan_index {
  199. /* for outgoing packets */
  200. GELIC_LV1_VLAN_TX_ETHERNET_0 = 0x0000000000000002L,
  201. GELIC_LV1_VLAN_TX_WIRELESS = 0x0000000000000003L,
  202. /* for incoming packets */
  203. GELIC_LV1_VLAN_RX_ETHERNET_0 = 0x0000000000000012L,
  204. GELIC_LV1_VLAN_RX_WIRELESS = 0x0000000000000013L,
  205. };
  206. enum gelic_lv1_phy {
  207. GELIC_LV1_PHY_ETHERNET_0 = 0x0000000000000002L,
  208. };
  209. /* size of hardware part of gelic descriptor */
  210. #define GELIC_DESCR_SIZE (32)
  211. enum gelic_port_type {
  212. GELIC_PORT_ETHERNET_0 = 0,
  213. GELIC_PORT_WIRELESS = 1,
  214. GELIC_PORT_MAX
  215. };
  216. struct gelic_descr {
  217. /* as defined by the hardware */
  218. __be32 buf_addr;
  219. __be32 buf_size;
  220. __be32 next_descr_addr;
  221. __be32 dmac_cmd_status;
  222. __be32 result_size;
  223. __be32 valid_size; /* all zeroes for tx */
  224. __be32 data_status;
  225. __be32 data_error; /* all zeroes for tx */
  226. /* used in the driver */
  227. struct sk_buff *skb;
  228. dma_addr_t bus_addr;
  229. struct gelic_descr *next;
  230. struct gelic_descr *prev;
  231. } __attribute__((aligned(32)));
  232. struct gelic_descr_chain {
  233. /* we walk from tail to head */
  234. struct gelic_descr *head;
  235. struct gelic_descr *tail;
  236. };
  237. struct gelic_vlan_id {
  238. u16 tx;
  239. u16 rx;
  240. };
  241. struct gelic_card {
  242. struct napi_struct napi;
  243. struct net_device *netdev[GELIC_PORT_MAX];
  244. /*
  245. * hypervisor requires irq_status should be
  246. * 8 bytes aligned, but u64 member is
  247. * always disposed in that manner
  248. */
  249. u64 irq_status;
  250. u64 irq_mask;
  251. struct ps3_system_bus_device *dev;
  252. struct gelic_vlan_id vlan[GELIC_PORT_MAX];
  253. int vlan_required;
  254. struct gelic_descr_chain tx_chain;
  255. struct gelic_descr_chain rx_chain;
  256. int rx_dma_restart_required;
  257. /*
  258. * tx_lock guards tx descriptor list and
  259. * tx_dma_progress.
  260. */
  261. spinlock_t tx_lock;
  262. int tx_dma_progress;
  263. struct work_struct tx_timeout_task;
  264. atomic_t tx_timeout_task_counter;
  265. wait_queue_head_t waitq;
  266. /* only first user should up the card */
  267. struct mutex updown_lock;
  268. atomic_t users;
  269. u64 ether_port_status;
  270. int link_mode;
  271. /* original address returned by kzalloc */
  272. void *unalign;
  273. /*
  274. * each netdevice has copy of irq
  275. */
  276. unsigned int irq;
  277. struct gelic_descr *tx_top, *rx_top;
  278. struct gelic_descr descr[0]; /* must be the last */
  279. };
  280. struct gelic_port {
  281. struct gelic_card *card;
  282. struct net_device *netdev;
  283. enum gelic_port_type type;
  284. long priv[0]; /* long for alignment */
  285. };
  286. static inline struct gelic_card *port_to_card(struct gelic_port *p)
  287. {
  288. return p->card;
  289. }
  290. static inline struct net_device *port_to_netdev(struct gelic_port *p)
  291. {
  292. return p->netdev;
  293. }
  294. static inline struct gelic_card *netdev_card(struct net_device *d)
  295. {
  296. return ((struct gelic_port *)netdev_priv(d))->card;
  297. }
  298. static inline struct gelic_port *netdev_port(struct net_device *d)
  299. {
  300. return (struct gelic_port *)netdev_priv(d);
  301. }
  302. static inline struct device *ctodev(struct gelic_card *card)
  303. {
  304. return &card->dev->core;
  305. }
  306. static inline u64 bus_id(struct gelic_card *card)
  307. {
  308. return card->dev->bus_id;
  309. }
  310. static inline u64 dev_id(struct gelic_card *card)
  311. {
  312. return card->dev->dev_id;
  313. }
  314. static inline void *port_priv(struct gelic_port *port)
  315. {
  316. return port->priv;
  317. }
  318. extern int gelic_card_set_irq_mask(struct gelic_card *card, u64 mask);
  319. /* shared netdev ops */
  320. extern void gelic_card_up(struct gelic_card *card);
  321. extern void gelic_card_down(struct gelic_card *card);
  322. extern int gelic_net_open(struct net_device *netdev);
  323. extern int gelic_net_stop(struct net_device *netdev);
  324. extern int gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev);
  325. extern void gelic_net_set_multi(struct net_device *netdev);
  326. extern void gelic_net_tx_timeout(struct net_device *netdev);
  327. extern int gelic_net_change_mtu(struct net_device *netdev, int new_mtu);
  328. extern int gelic_net_setup_netdev(struct net_device *netdev,
  329. struct gelic_card *card);
  330. /* shared ethtool ops */
  331. extern void gelic_net_get_drvinfo(struct net_device *netdev,
  332. struct ethtool_drvinfo *info);
  333. extern void gelic_net_poll_controller(struct net_device *netdev);
  334. #endif /* _GELIC_NET_H */