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