ehea.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. /*
  2. * linux/drivers/net/ethernet/ibm/ehea/ehea.h
  3. *
  4. * eHEA ethernet device driver for IBM eServer System p
  5. *
  6. * (C) Copyright IBM Corp. 2006
  7. *
  8. * Authors:
  9. * Christoph Raisch <raisch@de.ibm.com>
  10. * Jan-Bernd Themann <themann@de.ibm.com>
  11. * Thomas Klein <tklein@de.ibm.com>
  12. *
  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 __EHEA_H__
  29. #define __EHEA_H__
  30. #include <linux/module.h>
  31. #include <linux/ethtool.h>
  32. #include <linux/vmalloc.h>
  33. #include <linux/if_vlan.h>
  34. #include <asm/ibmebus.h>
  35. #include <asm/abs_addr.h>
  36. #include <asm/io.h>
  37. #define DRV_NAME "ehea"
  38. #define DRV_VERSION "EHEA_0107"
  39. /* eHEA capability flags */
  40. #define DLPAR_PORT_ADD_REM 1
  41. #define DLPAR_MEM_ADD 2
  42. #define DLPAR_MEM_REM 4
  43. #define EHEA_CAPABILITIES (DLPAR_PORT_ADD_REM | DLPAR_MEM_ADD | DLPAR_MEM_REM)
  44. #define EHEA_MSG_DEFAULT (NETIF_MSG_LINK | NETIF_MSG_TIMER \
  45. | NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR)
  46. #define EHEA_MAX_ENTRIES_RQ1 32767
  47. #define EHEA_MAX_ENTRIES_RQ2 16383
  48. #define EHEA_MAX_ENTRIES_RQ3 16383
  49. #define EHEA_MAX_ENTRIES_SQ 32767
  50. #define EHEA_MIN_ENTRIES_QP 127
  51. #define EHEA_SMALL_QUEUES
  52. #ifdef EHEA_SMALL_QUEUES
  53. #define EHEA_MAX_CQE_COUNT 1023
  54. #define EHEA_DEF_ENTRIES_SQ 1023
  55. #define EHEA_DEF_ENTRIES_RQ1 1023
  56. #define EHEA_DEF_ENTRIES_RQ2 1023
  57. #define EHEA_DEF_ENTRIES_RQ3 511
  58. #else
  59. #define EHEA_MAX_CQE_COUNT 4080
  60. #define EHEA_DEF_ENTRIES_SQ 4080
  61. #define EHEA_DEF_ENTRIES_RQ1 8160
  62. #define EHEA_DEF_ENTRIES_RQ2 2040
  63. #define EHEA_DEF_ENTRIES_RQ3 2040
  64. #endif
  65. #define EHEA_MAX_ENTRIES_EQ 20
  66. #define EHEA_SG_SQ 2
  67. #define EHEA_SG_RQ1 1
  68. #define EHEA_SG_RQ2 0
  69. #define EHEA_SG_RQ3 0
  70. #define EHEA_MAX_PACKET_SIZE 9022 /* for jumbo frames */
  71. #define EHEA_RQ2_PKT_SIZE 2048
  72. #define EHEA_L_PKT_SIZE 256 /* low latency */
  73. /* Send completion signaling */
  74. /* Protection Domain Identifier */
  75. #define EHEA_PD_ID 0xaabcdeff
  76. #define EHEA_RQ2_THRESHOLD 1
  77. #define EHEA_RQ3_THRESHOLD 4 /* use RQ3 threshold of 2048 bytes */
  78. #define EHEA_SPEED_10G 10000
  79. #define EHEA_SPEED_1G 1000
  80. #define EHEA_SPEED_100M 100
  81. #define EHEA_SPEED_10M 10
  82. #define EHEA_SPEED_AUTONEG 0
  83. /* Broadcast/Multicast registration types */
  84. #define EHEA_BCMC_SCOPE_ALL 0x08
  85. #define EHEA_BCMC_SCOPE_SINGLE 0x00
  86. #define EHEA_BCMC_MULTICAST 0x04
  87. #define EHEA_BCMC_BROADCAST 0x00
  88. #define EHEA_BCMC_UNTAGGED 0x02
  89. #define EHEA_BCMC_TAGGED 0x00
  90. #define EHEA_BCMC_VLANID_ALL 0x01
  91. #define EHEA_BCMC_VLANID_SINGLE 0x00
  92. #define EHEA_CACHE_LINE 128
  93. /* Memory Regions */
  94. #define EHEA_MR_ACC_CTRL 0x00800000
  95. #define EHEA_BUSMAP_START 0x8000000000000000ULL
  96. #define EHEA_INVAL_ADDR 0xFFFFFFFFFFFFFFFFULL
  97. #define EHEA_DIR_INDEX_SHIFT 13 /* 8k Entries in 64k block */
  98. #define EHEA_TOP_INDEX_SHIFT (EHEA_DIR_INDEX_SHIFT * 2)
  99. #define EHEA_MAP_ENTRIES (1 << EHEA_DIR_INDEX_SHIFT)
  100. #define EHEA_MAP_SIZE (0x10000) /* currently fixed map size */
  101. #define EHEA_INDEX_MASK (EHEA_MAP_ENTRIES - 1)
  102. #define EHEA_WATCH_DOG_TIMEOUT 10*HZ
  103. /* utility functions */
  104. void ehea_dump(void *adr, int len, char *msg);
  105. #define EHEA_BMASK(pos, length) (((pos) << 16) + (length))
  106. #define EHEA_BMASK_IBM(from, to) (((63 - to) << 16) + ((to) - (from) + 1))
  107. #define EHEA_BMASK_SHIFTPOS(mask) (((mask) >> 16) & 0xffff)
  108. #define EHEA_BMASK_MASK(mask) \
  109. (0xffffffffffffffffULL >> ((64 - (mask)) & 0xffff))
  110. #define EHEA_BMASK_SET(mask, value) \
  111. ((EHEA_BMASK_MASK(mask) & ((u64)(value))) << EHEA_BMASK_SHIFTPOS(mask))
  112. #define EHEA_BMASK_GET(mask, value) \
  113. (EHEA_BMASK_MASK(mask) & (((u64)(value)) >> EHEA_BMASK_SHIFTPOS(mask)))
  114. /*
  115. * Generic ehea page
  116. */
  117. struct ehea_page {
  118. u8 entries[PAGE_SIZE];
  119. };
  120. /*
  121. * Generic queue in linux kernel virtual memory
  122. */
  123. struct hw_queue {
  124. u64 current_q_offset; /* current queue entry */
  125. struct ehea_page **queue_pages; /* array of pages belonging to queue */
  126. u32 qe_size; /* queue entry size */
  127. u32 queue_length; /* queue length allocated in bytes */
  128. u32 pagesize;
  129. u32 toggle_state; /* toggle flag - per page */
  130. u32 reserved; /* 64 bit alignment */
  131. };
  132. /*
  133. * For pSeries this is a 64bit memory address where
  134. * I/O memory is mapped into CPU address space
  135. */
  136. struct h_epa {
  137. void __iomem *addr;
  138. };
  139. struct h_epa_user {
  140. u64 addr;
  141. };
  142. struct h_epas {
  143. struct h_epa kernel; /* kernel space accessible resource,
  144. set to 0 if unused */
  145. struct h_epa_user user; /* user space accessible resource
  146. set to 0 if unused */
  147. };
  148. /*
  149. * Memory map data structures
  150. */
  151. struct ehea_dir_bmap
  152. {
  153. u64 ent[EHEA_MAP_ENTRIES];
  154. };
  155. struct ehea_top_bmap
  156. {
  157. struct ehea_dir_bmap *dir[EHEA_MAP_ENTRIES];
  158. };
  159. struct ehea_bmap
  160. {
  161. struct ehea_top_bmap *top[EHEA_MAP_ENTRIES];
  162. };
  163. struct ehea_qp;
  164. struct ehea_cq;
  165. struct ehea_eq;
  166. struct ehea_port;
  167. struct ehea_av;
  168. /*
  169. * Queue attributes passed to ehea_create_qp()
  170. */
  171. struct ehea_qp_init_attr {
  172. /* input parameter */
  173. u32 qp_token; /* queue token */
  174. u8 low_lat_rq1;
  175. u8 signalingtype; /* cqe generation flag */
  176. u8 rq_count; /* num of receive queues */
  177. u8 eqe_gen; /* eqe generation flag */
  178. u16 max_nr_send_wqes; /* max number of send wqes */
  179. u16 max_nr_rwqes_rq1; /* max number of receive wqes */
  180. u16 max_nr_rwqes_rq2;
  181. u16 max_nr_rwqes_rq3;
  182. u8 wqe_size_enc_sq;
  183. u8 wqe_size_enc_rq1;
  184. u8 wqe_size_enc_rq2;
  185. u8 wqe_size_enc_rq3;
  186. u8 swqe_imm_data_len; /* immediate data length for swqes */
  187. u16 port_nr;
  188. u16 rq2_threshold;
  189. u16 rq3_threshold;
  190. u64 send_cq_handle;
  191. u64 recv_cq_handle;
  192. u64 aff_eq_handle;
  193. /* output parameter */
  194. u32 qp_nr;
  195. u16 act_nr_send_wqes;
  196. u16 act_nr_rwqes_rq1;
  197. u16 act_nr_rwqes_rq2;
  198. u16 act_nr_rwqes_rq3;
  199. u8 act_wqe_size_enc_sq;
  200. u8 act_wqe_size_enc_rq1;
  201. u8 act_wqe_size_enc_rq2;
  202. u8 act_wqe_size_enc_rq3;
  203. u32 nr_sq_pages;
  204. u32 nr_rq1_pages;
  205. u32 nr_rq2_pages;
  206. u32 nr_rq3_pages;
  207. u32 liobn_sq;
  208. u32 liobn_rq1;
  209. u32 liobn_rq2;
  210. u32 liobn_rq3;
  211. };
  212. /*
  213. * Event Queue attributes, passed as parameter
  214. */
  215. struct ehea_eq_attr {
  216. u32 type;
  217. u32 max_nr_of_eqes;
  218. u8 eqe_gen; /* generate eqe flag */
  219. u64 eq_handle;
  220. u32 act_nr_of_eqes;
  221. u32 nr_pages;
  222. u32 ist1; /* Interrupt service token */
  223. u32 ist2;
  224. u32 ist3;
  225. u32 ist4;
  226. };
  227. /*
  228. * Event Queue
  229. */
  230. struct ehea_eq {
  231. struct ehea_adapter *adapter;
  232. struct hw_queue hw_queue;
  233. u64 fw_handle;
  234. struct h_epas epas;
  235. spinlock_t spinlock;
  236. struct ehea_eq_attr attr;
  237. };
  238. /*
  239. * HEA Queues
  240. */
  241. struct ehea_qp {
  242. struct ehea_adapter *adapter;
  243. u64 fw_handle; /* QP handle for firmware calls */
  244. struct hw_queue hw_squeue;
  245. struct hw_queue hw_rqueue1;
  246. struct hw_queue hw_rqueue2;
  247. struct hw_queue hw_rqueue3;
  248. struct h_epas epas;
  249. struct ehea_qp_init_attr init_attr;
  250. };
  251. /*
  252. * Completion Queue attributes
  253. */
  254. struct ehea_cq_attr {
  255. /* input parameter */
  256. u32 max_nr_of_cqes;
  257. u32 cq_token;
  258. u64 eq_handle;
  259. /* output parameter */
  260. u32 act_nr_of_cqes;
  261. u32 nr_pages;
  262. };
  263. /*
  264. * Completion Queue
  265. */
  266. struct ehea_cq {
  267. struct ehea_adapter *adapter;
  268. u64 fw_handle;
  269. struct hw_queue hw_queue;
  270. struct h_epas epas;
  271. struct ehea_cq_attr attr;
  272. };
  273. /*
  274. * Memory Region
  275. */
  276. struct ehea_mr {
  277. struct ehea_adapter *adapter;
  278. u64 handle;
  279. u64 vaddr;
  280. u32 lkey;
  281. };
  282. /*
  283. * Port state information
  284. */
  285. struct port_stats {
  286. int poll_receive_errors;
  287. int queue_stopped;
  288. int err_tcp_cksum;
  289. int err_ip_cksum;
  290. int err_frame_crc;
  291. };
  292. #define EHEA_IRQ_NAME_SIZE 20
  293. /*
  294. * Queue SKB Array
  295. */
  296. struct ehea_q_skb_arr {
  297. struct sk_buff **arr; /* skb array for queue */
  298. int len; /* array length */
  299. int index; /* array index */
  300. int os_skbs; /* rq2/rq3 only: outstanding skbs */
  301. };
  302. /*
  303. * Port resources
  304. */
  305. struct ehea_port_res {
  306. struct napi_struct napi;
  307. struct port_stats p_stats;
  308. struct ehea_mr send_mr; /* send memory region */
  309. struct ehea_mr recv_mr; /* receive memory region */
  310. struct ehea_port *port;
  311. char int_recv_name[EHEA_IRQ_NAME_SIZE];
  312. char int_send_name[EHEA_IRQ_NAME_SIZE];
  313. struct ehea_qp *qp;
  314. struct ehea_cq *send_cq;
  315. struct ehea_cq *recv_cq;
  316. struct ehea_eq *eq;
  317. struct ehea_q_skb_arr rq1_skba;
  318. struct ehea_q_skb_arr rq2_skba;
  319. struct ehea_q_skb_arr rq3_skba;
  320. struct ehea_q_skb_arr sq_skba;
  321. int sq_skba_size;
  322. int swqe_refill_th;
  323. atomic_t swqe_avail;
  324. int swqe_ll_count;
  325. u32 swqe_id_counter;
  326. u64 tx_packets;
  327. u64 tx_bytes;
  328. u64 rx_packets;
  329. u64 rx_bytes;
  330. int sq_restart_flag;
  331. };
  332. #define EHEA_MAX_PORTS 16
  333. #define EHEA_NUM_PORTRES_FW_HANDLES 6 /* QP handle, SendCQ handle,
  334. RecvCQ handle, EQ handle,
  335. SendMR handle, RecvMR handle */
  336. #define EHEA_NUM_PORT_FW_HANDLES 1 /* EQ handle */
  337. #define EHEA_NUM_ADAPTER_FW_HANDLES 2 /* MR handle, NEQ handle */
  338. struct ehea_adapter {
  339. u64 handle;
  340. struct platform_device *ofdev;
  341. struct ehea_port *port[EHEA_MAX_PORTS];
  342. struct ehea_eq *neq; /* notification event queue */
  343. struct tasklet_struct neq_tasklet;
  344. struct ehea_mr mr;
  345. u32 pd; /* protection domain */
  346. u64 max_mc_mac; /* max number of multicast mac addresses */
  347. int active_ports;
  348. struct list_head list;
  349. };
  350. struct ehea_mc_list {
  351. struct list_head list;
  352. u64 macaddr;
  353. };
  354. /* kdump support */
  355. struct ehea_fw_handle_entry {
  356. u64 adh; /* Adapter Handle */
  357. u64 fwh; /* Firmware Handle */
  358. };
  359. struct ehea_fw_handle_array {
  360. struct ehea_fw_handle_entry *arr;
  361. int num_entries;
  362. struct mutex lock;
  363. };
  364. struct ehea_bcmc_reg_entry {
  365. u64 adh; /* Adapter Handle */
  366. u32 port_id; /* Logical Port Id */
  367. u8 reg_type; /* Registration Type */
  368. u64 macaddr;
  369. };
  370. struct ehea_bcmc_reg_array {
  371. struct ehea_bcmc_reg_entry *arr;
  372. int num_entries;
  373. spinlock_t lock;
  374. };
  375. #define EHEA_PORT_UP 1
  376. #define EHEA_PORT_DOWN 0
  377. #define EHEA_PHY_LINK_UP 1
  378. #define EHEA_PHY_LINK_DOWN 0
  379. #define EHEA_MAX_PORT_RES 16
  380. struct ehea_port {
  381. struct ehea_adapter *adapter; /* adapter that owns this port */
  382. struct net_device *netdev;
  383. struct rtnl_link_stats64 stats;
  384. struct ehea_port_res port_res[EHEA_MAX_PORT_RES];
  385. struct platform_device ofdev; /* Open Firmware Device */
  386. struct ehea_mc_list *mc_list; /* Multicast MAC addresses */
  387. struct ehea_eq *qp_eq;
  388. struct work_struct reset_task;
  389. struct delayed_work stats_work;
  390. struct mutex port_lock;
  391. char int_aff_name[EHEA_IRQ_NAME_SIZE];
  392. int allmulti; /* Indicates IFF_ALLMULTI state */
  393. int promisc; /* Indicates IFF_PROMISC state */
  394. int num_mcs;
  395. int resets;
  396. unsigned long flags;
  397. u64 mac_addr;
  398. u32 logical_port_id;
  399. u32 port_speed;
  400. u32 msg_enable;
  401. u32 sig_comp_iv;
  402. u32 state;
  403. u8 phy_link;
  404. u8 full_duplex;
  405. u8 autoneg;
  406. u8 num_def_qps;
  407. wait_queue_head_t swqe_avail_wq;
  408. wait_queue_head_t restart_wq;
  409. };
  410. struct port_res_cfg {
  411. int max_entries_rcq;
  412. int max_entries_scq;
  413. int max_entries_sq;
  414. int max_entries_rq1;
  415. int max_entries_rq2;
  416. int max_entries_rq3;
  417. };
  418. enum ehea_flag_bits {
  419. __EHEA_STOP_XFER,
  420. __EHEA_DISABLE_PORT_RESET
  421. };
  422. void ehea_set_ethtool_ops(struct net_device *netdev);
  423. int ehea_sense_port_attr(struct ehea_port *port);
  424. int ehea_set_portspeed(struct ehea_port *port, u32 port_speed);
  425. #endif /* __EHEA_H__ */