netxen_nic_hw.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. /*
  2. * Copyright (C) 2003 - 2009 NetXen, Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  18. * MA 02111-1307, USA.
  19. *
  20. * The full GNU General Public License is included in this distribution
  21. * in the file called LICENSE.
  22. *
  23. * Contact Information:
  24. * info@netxen.com
  25. * NetXen Inc,
  26. * 18922 Forge Drive
  27. * Cupertino, CA 95014-0701
  28. *
  29. */
  30. #ifndef __NETXEN_NIC_HW_H_
  31. #define __NETXEN_NIC_HW_H_
  32. #include "netxen_nic_hdr.h"
  33. /* Hardware memory size of 128 meg */
  34. #define NETXEN_MEMADDR_MAX (128 * 1024 * 1024)
  35. #ifndef readq
  36. static inline u64 readq(void __iomem * addr)
  37. {
  38. return readl(addr) | (((u64) readl(addr + 4)) << 32LL);
  39. }
  40. #endif
  41. #ifndef writeq
  42. static inline void writeq(u64 val, void __iomem * addr)
  43. {
  44. writel(((u32) (val)), (addr));
  45. writel(((u32) (val >> 32)), (addr + 4));
  46. }
  47. #endif
  48. struct netxen_adapter;
  49. #define NETXEN_PCI_MAPSIZE_BYTES (NETXEN_PCI_MAPSIZE << 20)
  50. struct netxen_port;
  51. void netxen_nic_set_link_parameters(struct netxen_adapter *adapter);
  52. typedef u8 netxen_ethernet_macaddr_t[6];
  53. /* Nibble or Byte mode for phy interface (GbE mode only) */
  54. typedef enum {
  55. NETXEN_NIU_10_100_MB = 0,
  56. NETXEN_NIU_1000_MB
  57. } netxen_niu_gbe_ifmode_t;
  58. #define _netxen_crb_get_bit(var, bit) ((var >> bit) & 0x1)
  59. /*
  60. * NIU GB MAC Config Register 0 (applies to GB0, GB1, GB2, GB3)
  61. *
  62. * Bit 0 : enable_tx => 1:enable frame xmit, 0:disable
  63. * Bit 1 : tx_synced => R/O: xmit enable synched to xmit stream
  64. * Bit 2 : enable_rx => 1:enable frame recv, 0:disable
  65. * Bit 3 : rx_synced => R/O: recv enable synched to recv stream
  66. * Bit 4 : tx_flowctl => 1:enable pause frame generation, 0:disable
  67. * Bit 5 : rx_flowctl => 1:act on recv'd pause frames, 0:ignore
  68. * Bit 8 : loopback => 1:loop MAC xmits to MAC recvs, 0:normal
  69. * Bit 16: tx_reset_pb => 1:reset frame xmit protocol blk, 0:no-op
  70. * Bit 17: rx_reset_pb => 1:reset frame recv protocol blk, 0:no-op
  71. * Bit 18: tx_reset_mac => 1:reset data/ctl multiplexer blk, 0:no-op
  72. * Bit 19: rx_reset_mac => 1:reset ctl frames & timers blk, 0:no-op
  73. * Bit 31: soft_reset => 1:reset the MAC and the SERDES, 0:no-op
  74. */
  75. #define netxen_gb_enable_tx(config_word) \
  76. ((config_word) |= 1 << 0)
  77. #define netxen_gb_enable_rx(config_word) \
  78. ((config_word) |= 1 << 2)
  79. #define netxen_gb_tx_flowctl(config_word) \
  80. ((config_word) |= 1 << 4)
  81. #define netxen_gb_rx_flowctl(config_word) \
  82. ((config_word) |= 1 << 5)
  83. #define netxen_gb_tx_reset_pb(config_word) \
  84. ((config_word) |= 1 << 16)
  85. #define netxen_gb_rx_reset_pb(config_word) \
  86. ((config_word) |= 1 << 17)
  87. #define netxen_gb_tx_reset_mac(config_word) \
  88. ((config_word) |= 1 << 18)
  89. #define netxen_gb_rx_reset_mac(config_word) \
  90. ((config_word) |= 1 << 19)
  91. #define netxen_gb_soft_reset(config_word) \
  92. ((config_word) |= 1 << 31)
  93. #define netxen_gb_unset_tx_flowctl(config_word) \
  94. ((config_word) &= ~(1 << 4))
  95. #define netxen_gb_unset_rx_flowctl(config_word) \
  96. ((config_word) &= ~(1 << 5))
  97. #define netxen_gb_get_tx_synced(config_word) \
  98. _netxen_crb_get_bit((config_word), 1)
  99. #define netxen_gb_get_rx_synced(config_word) \
  100. _netxen_crb_get_bit((config_word), 3)
  101. #define netxen_gb_get_tx_flowctl(config_word) \
  102. _netxen_crb_get_bit((config_word), 4)
  103. #define netxen_gb_get_rx_flowctl(config_word) \
  104. _netxen_crb_get_bit((config_word), 5)
  105. #define netxen_gb_get_soft_reset(config_word) \
  106. _netxen_crb_get_bit((config_word), 31)
  107. #define netxen_gb_get_stationaddress_low(config_word) ((config_word) >> 16)
  108. #define netxen_gb_set_mii_mgmt_clockselect(config_word, val) \
  109. ((config_word) |= ((val) & 0x07))
  110. #define netxen_gb_mii_mgmt_reset(config_word) \
  111. ((config_word) |= 1 << 31)
  112. #define netxen_gb_mii_mgmt_unset(config_word) \
  113. ((config_word) &= ~(1 << 31))
  114. /*
  115. * NIU GB MII Mgmt Command Register (applies to GB0, GB1, GB2, GB3)
  116. * Bit 0 : read_cycle => 1:perform single read cycle, 0:no-op
  117. * Bit 1 : scan_cycle => 1:perform continuous read cycles, 0:no-op
  118. */
  119. #define netxen_gb_mii_mgmt_set_read_cycle(config_word) \
  120. ((config_word) |= 1 << 0)
  121. #define netxen_gb_mii_mgmt_reg_addr(config_word, val) \
  122. ((config_word) |= ((val) & 0x1F))
  123. #define netxen_gb_mii_mgmt_phy_addr(config_word, val) \
  124. ((config_word) |= (((val) & 0x1F) << 8))
  125. /*
  126. * NIU GB MII Mgmt Indicators Register (applies to GB0, GB1, GB2, GB3)
  127. * Read-only register.
  128. * Bit 0 : busy => 1:performing an MII mgmt cycle, 0:idle
  129. * Bit 1 : scanning => 1:scan operation in progress, 0:idle
  130. * Bit 2 : notvalid => :mgmt result data not yet valid, 0:idle
  131. */
  132. #define netxen_get_gb_mii_mgmt_busy(config_word) \
  133. _netxen_crb_get_bit(config_word, 0)
  134. #define netxen_get_gb_mii_mgmt_scanning(config_word) \
  135. _netxen_crb_get_bit(config_word, 1)
  136. #define netxen_get_gb_mii_mgmt_notvalid(config_word) \
  137. _netxen_crb_get_bit(config_word, 2)
  138. /*
  139. * NIU XG Pause Ctl Register
  140. *
  141. * Bit 0 : xg0_mask => 1:disable tx pause frames
  142. * Bit 1 : xg0_request => 1:request single pause frame
  143. * Bit 2 : xg0_on_off => 1:request is pause on, 0:off
  144. * Bit 3 : xg1_mask => 1:disable tx pause frames
  145. * Bit 4 : xg1_request => 1:request single pause frame
  146. * Bit 5 : xg1_on_off => 1:request is pause on, 0:off
  147. */
  148. #define netxen_xg_set_xg0_mask(config_word) \
  149. ((config_word) |= 1 << 0)
  150. #define netxen_xg_set_xg1_mask(config_word) \
  151. ((config_word) |= 1 << 3)
  152. #define netxen_xg_get_xg0_mask(config_word) \
  153. _netxen_crb_get_bit((config_word), 0)
  154. #define netxen_xg_get_xg1_mask(config_word) \
  155. _netxen_crb_get_bit((config_word), 3)
  156. #define netxen_xg_unset_xg0_mask(config_word) \
  157. ((config_word) &= ~(1 << 0))
  158. #define netxen_xg_unset_xg1_mask(config_word) \
  159. ((config_word) &= ~(1 << 3))
  160. /*
  161. * NIU XG Pause Ctl Register
  162. *
  163. * Bit 0 : xg0_mask => 1:disable tx pause frames
  164. * Bit 1 : xg0_request => 1:request single pause frame
  165. * Bit 2 : xg0_on_off => 1:request is pause on, 0:off
  166. * Bit 3 : xg1_mask => 1:disable tx pause frames
  167. * Bit 4 : xg1_request => 1:request single pause frame
  168. * Bit 5 : xg1_on_off => 1:request is pause on, 0:off
  169. */
  170. #define netxen_gb_set_gb0_mask(config_word) \
  171. ((config_word) |= 1 << 0)
  172. #define netxen_gb_set_gb1_mask(config_word) \
  173. ((config_word) |= 1 << 2)
  174. #define netxen_gb_set_gb2_mask(config_word) \
  175. ((config_word) |= 1 << 4)
  176. #define netxen_gb_set_gb3_mask(config_word) \
  177. ((config_word) |= 1 << 6)
  178. #define netxen_gb_get_gb0_mask(config_word) \
  179. _netxen_crb_get_bit((config_word), 0)
  180. #define netxen_gb_get_gb1_mask(config_word) \
  181. _netxen_crb_get_bit((config_word), 2)
  182. #define netxen_gb_get_gb2_mask(config_word) \
  183. _netxen_crb_get_bit((config_word), 4)
  184. #define netxen_gb_get_gb3_mask(config_word) \
  185. _netxen_crb_get_bit((config_word), 6)
  186. #define netxen_gb_unset_gb0_mask(config_word) \
  187. ((config_word) &= ~(1 << 0))
  188. #define netxen_gb_unset_gb1_mask(config_word) \
  189. ((config_word) &= ~(1 << 2))
  190. #define netxen_gb_unset_gb2_mask(config_word) \
  191. ((config_word) &= ~(1 << 4))
  192. #define netxen_gb_unset_gb3_mask(config_word) \
  193. ((config_word) &= ~(1 << 6))
  194. /*
  195. * PHY-Specific MII control/status registers.
  196. */
  197. typedef enum {
  198. NETXEN_NIU_GB_MII_MGMT_ADDR_CONTROL = 0,
  199. NETXEN_NIU_GB_MII_MGMT_ADDR_STATUS = 1,
  200. NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_ID_0 = 2,
  201. NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_ID_1 = 3,
  202. NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG = 4,
  203. NETXEN_NIU_GB_MII_MGMT_ADDR_LNKPART = 5,
  204. NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG_MORE = 6,
  205. NETXEN_NIU_GB_MII_MGMT_ADDR_NEXTPAGE_XMIT = 7,
  206. NETXEN_NIU_GB_MII_MGMT_ADDR_LNKPART_NEXTPAGE = 8,
  207. NETXEN_NIU_GB_MII_MGMT_ADDR_1000BT_CONTROL = 9,
  208. NETXEN_NIU_GB_MII_MGMT_ADDR_1000BT_STATUS = 10,
  209. NETXEN_NIU_GB_MII_MGMT_ADDR_EXTENDED_STATUS = 15,
  210. NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_CONTROL = 16,
  211. NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS = 17,
  212. NETXEN_NIU_GB_MII_MGMT_ADDR_INT_ENABLE = 18,
  213. NETXEN_NIU_GB_MII_MGMT_ADDR_INT_STATUS = 19,
  214. NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_CONTROL_MORE = 20,
  215. NETXEN_NIU_GB_MII_MGMT_ADDR_RECV_ERROR_COUNT = 21,
  216. NETXEN_NIU_GB_MII_MGMT_ADDR_LED_CONTROL = 24,
  217. NETXEN_NIU_GB_MII_MGMT_ADDR_LED_OVERRIDE = 25,
  218. NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_CONTROL_MORE_YET = 26,
  219. NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS_MORE = 27
  220. } netxen_niu_phy_register_t;
  221. /*
  222. * PHY-Specific Status Register (reg 17).
  223. *
  224. * Bit 0 : jabber => 1:jabber detected, 0:not
  225. * Bit 1 : polarity => 1:polarity reversed, 0:normal
  226. * Bit 2 : recvpause => 1:receive pause enabled, 0:disabled
  227. * Bit 3 : xmitpause => 1:transmit pause enabled, 0:disabled
  228. * Bit 4 : energydetect => 1:sleep, 0:active
  229. * Bit 5 : downshift => 1:downshift, 0:no downshift
  230. * Bit 6 : crossover => 1:MDIX (crossover), 0:MDI (no crossover)
  231. * Bits 7-9 : cablelen => not valid in 10Mb/s mode
  232. * 0:<50m, 1:50-80m, 2:80-110m, 3:110-140m, 4:>140m
  233. * Bit 10 : link => 1:link up, 0:link down
  234. * Bit 11 : resolved => 1:speed and duplex resolved, 0:not yet
  235. * Bit 12 : pagercvd => 1:page received, 0:page not received
  236. * Bit 13 : duplex => 1:full duplex, 0:half duplex
  237. * Bits 14-15 : speed => 0:10Mb/s, 1:100Mb/s, 2:1000Mb/s, 3:rsvd
  238. */
  239. #define netxen_get_phy_cablelen(config_word) (((config_word) >> 7) & 0x07)
  240. #define netxen_get_phy_speed(config_word) (((config_word) >> 14) & 0x03)
  241. #define netxen_set_phy_speed(config_word, val) \
  242. ((config_word) |= ((val & 0x03) << 14))
  243. #define netxen_set_phy_duplex(config_word) \
  244. ((config_word) |= 1 << 13)
  245. #define netxen_clear_phy_duplex(config_word) \
  246. ((config_word) &= ~(1 << 13))
  247. #define netxen_get_phy_jabber(config_word) \
  248. _netxen_crb_get_bit(config_word, 0)
  249. #define netxen_get_phy_polarity(config_word) \
  250. _netxen_crb_get_bit(config_word, 1)
  251. #define netxen_get_phy_recvpause(config_word) \
  252. _netxen_crb_get_bit(config_word, 2)
  253. #define netxen_get_phy_xmitpause(config_word) \
  254. _netxen_crb_get_bit(config_word, 3)
  255. #define netxen_get_phy_energydetect(config_word) \
  256. _netxen_crb_get_bit(config_word, 4)
  257. #define netxen_get_phy_downshift(config_word) \
  258. _netxen_crb_get_bit(config_word, 5)
  259. #define netxen_get_phy_crossover(config_word) \
  260. _netxen_crb_get_bit(config_word, 6)
  261. #define netxen_get_phy_link(config_word) \
  262. _netxen_crb_get_bit(config_word, 10)
  263. #define netxen_get_phy_resolved(config_word) \
  264. _netxen_crb_get_bit(config_word, 11)
  265. #define netxen_get_phy_pagercvd(config_word) \
  266. _netxen_crb_get_bit(config_word, 12)
  267. #define netxen_get_phy_duplex(config_word) \
  268. _netxen_crb_get_bit(config_word, 13)
  269. /*
  270. * Interrupt Register definition
  271. * This definition applies to registers 18 and 19 (int enable and int status).
  272. * Bit 0 : jabber
  273. * Bit 1 : polarity_changed
  274. * Bit 4 : energy_detect
  275. * Bit 5 : downshift
  276. * Bit 6 : mdi_xover_changed
  277. * Bit 7 : fifo_over_underflow
  278. * Bit 8 : false_carrier
  279. * Bit 9 : symbol_error
  280. * Bit 10: link_status_changed
  281. * Bit 11: autoneg_completed
  282. * Bit 12: page_received
  283. * Bit 13: duplex_changed
  284. * Bit 14: speed_changed
  285. * Bit 15: autoneg_error
  286. */
  287. #define netxen_get_phy_int_jabber(config_word) \
  288. _netxen_crb_get_bit(config_word, 0)
  289. #define netxen_get_phy_int_polarity_changed(config_word) \
  290. _netxen_crb_get_bit(config_word, 1)
  291. #define netxen_get_phy_int_energy_detect(config_word) \
  292. _netxen_crb_get_bit(config_word, 4)
  293. #define netxen_get_phy_int_downshift(config_word) \
  294. _netxen_crb_get_bit(config_word, 5)
  295. #define netxen_get_phy_int_mdi_xover_changed(config_word) \
  296. _netxen_crb_get_bit(config_word, 6)
  297. #define netxen_get_phy_int_fifo_over_underflow(config_word) \
  298. _netxen_crb_get_bit(config_word, 7)
  299. #define netxen_get_phy_int_false_carrier(config_word) \
  300. _netxen_crb_get_bit(config_word, 8)
  301. #define netxen_get_phy_int_symbol_error(config_word) \
  302. _netxen_crb_get_bit(config_word, 9)
  303. #define netxen_get_phy_int_link_status_changed(config_word) \
  304. _netxen_crb_get_bit(config_word, 10)
  305. #define netxen_get_phy_int_autoneg_completed(config_word) \
  306. _netxen_crb_get_bit(config_word, 11)
  307. #define netxen_get_phy_int_page_received(config_word) \
  308. _netxen_crb_get_bit(config_word, 12)
  309. #define netxen_get_phy_int_duplex_changed(config_word) \
  310. _netxen_crb_get_bit(config_word, 13)
  311. #define netxen_get_phy_int_speed_changed(config_word) \
  312. _netxen_crb_get_bit(config_word, 14)
  313. #define netxen_get_phy_int_autoneg_error(config_word) \
  314. _netxen_crb_get_bit(config_word, 15)
  315. #define netxen_set_phy_int_link_status_changed(config_word) \
  316. ((config_word) |= 1 << 10)
  317. #define netxen_set_phy_int_autoneg_completed(config_word) \
  318. ((config_word) |= 1 << 11)
  319. #define netxen_set_phy_int_speed_changed(config_word) \
  320. ((config_word) |= 1 << 14)
  321. /*
  322. * NIU Mode Register.
  323. * Bit 0 : enable FibreChannel
  324. * Bit 1 : enable 10/100/1000 Ethernet
  325. * Bit 2 : enable 10Gb Ethernet
  326. */
  327. #define netxen_get_niu_enable_ge(config_word) \
  328. _netxen_crb_get_bit(config_word, 1)
  329. #define NETXEN_NIU_NON_PROMISC_MODE 0
  330. #define NETXEN_NIU_PROMISC_MODE 1
  331. #define NETXEN_NIU_ALLMULTI_MODE 2
  332. /*
  333. * NIU GB Drop CRC Register
  334. *
  335. * Bit 0 : drop_gb0 => 1:drop pkts with bad CRCs, 0:pass them on
  336. * Bit 1 : drop_gb1 => 1:drop pkts with bad CRCs, 0:pass them on
  337. * Bit 2 : drop_gb2 => 1:drop pkts with bad CRCs, 0:pass them on
  338. * Bit 3 : drop_gb3 => 1:drop pkts with bad CRCs, 0:pass them on
  339. */
  340. #define netxen_set_gb_drop_gb0(config_word) \
  341. ((config_word) |= 1 << 0)
  342. #define netxen_set_gb_drop_gb1(config_word) \
  343. ((config_word) |= 1 << 1)
  344. #define netxen_set_gb_drop_gb2(config_word) \
  345. ((config_word) |= 1 << 2)
  346. #define netxen_set_gb_drop_gb3(config_word) \
  347. ((config_word) |= 1 << 3)
  348. #define netxen_clear_gb_drop_gb0(config_word) \
  349. ((config_word) &= ~(1 << 0))
  350. #define netxen_clear_gb_drop_gb1(config_word) \
  351. ((config_word) &= ~(1 << 1))
  352. #define netxen_clear_gb_drop_gb2(config_word) \
  353. ((config_word) &= ~(1 << 2))
  354. #define netxen_clear_gb_drop_gb3(config_word) \
  355. ((config_word) &= ~(1 << 3))
  356. /*
  357. * NIU XG MAC Config Register
  358. *
  359. * Bit 0 : tx_enable => 1:enable frame xmit, 0:disable
  360. * Bit 2 : rx_enable => 1:enable frame recv, 0:disable
  361. * Bit 4 : soft_reset => 1:reset the MAC , 0:no-op
  362. * Bit 27: xaui_framer_reset
  363. * Bit 28: xaui_rx_reset
  364. * Bit 29: xaui_tx_reset
  365. * Bit 30: xg_ingress_afifo_reset
  366. * Bit 31: xg_egress_afifo_reset
  367. */
  368. #define netxen_xg_soft_reset(config_word) \
  369. ((config_word) |= 1 << 4)
  370. /* Set promiscuous mode for a GbE interface */
  371. int netxen_niu_set_promiscuous_mode(struct netxen_adapter *adapter,
  372. u32 mode);
  373. int netxen_niu_xg_set_promiscuous_mode(struct netxen_adapter *adapter,
  374. u32 mode);
  375. /* set the MAC address for a given MAC */
  376. int netxen_niu_macaddr_set(struct netxen_adapter *adapter,
  377. netxen_ethernet_macaddr_t addr);
  378. /* XG version */
  379. int netxen_niu_xg_macaddr_set(struct netxen_adapter *adapter,
  380. netxen_ethernet_macaddr_t addr);
  381. /* Generic enable for GbE ports. Will detect the speed of the link. */
  382. int netxen_niu_gbe_init_port(struct netxen_adapter *adapter, int port);
  383. int netxen_niu_xg_init_port(struct netxen_adapter *adapter, int port);
  384. /* Disable a GbE interface */
  385. int netxen_niu_disable_gbe_port(struct netxen_adapter *adapter);
  386. int netxen_niu_disable_xg_port(struct netxen_adapter *adapter);
  387. typedef struct {
  388. unsigned valid;
  389. unsigned start_128M;
  390. unsigned end_128M;
  391. unsigned start_2M;
  392. } crb_128M_2M_sub_block_map_t;
  393. typedef struct {
  394. crb_128M_2M_sub_block_map_t sub_block[16];
  395. } crb_128M_2M_block_map_t;
  396. #endif /* __NETXEN_NIC_HW_H_ */