ehea.h 12 KB

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