qeth_core.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright IBM Corp. 2007
  4. * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
  5. * Frank Pavlic <fpavlic@de.ibm.com>,
  6. * Thomas Spatzier <tspat@de.ibm.com>,
  7. * Frank Blaschka <frank.blaschka@de.ibm.com>
  8. */
  9. #ifndef __QETH_CORE_H__
  10. #define __QETH_CORE_H__
  11. #include <linux/if.h>
  12. #include <linux/if_arp.h>
  13. #include <linux/etherdevice.h>
  14. #include <linux/if_vlan.h>
  15. #include <linux/ctype.h>
  16. #include <linux/in6.h>
  17. #include <linux/bitops.h>
  18. #include <linux/seq_file.h>
  19. #include <linux/ethtool.h>
  20. #include <linux/hashtable.h>
  21. #include <linux/ip.h>
  22. #include <linux/refcount.h>
  23. #include <net/ipv6.h>
  24. #include <net/if_inet6.h>
  25. #include <net/addrconf.h>
  26. #include <asm/debug.h>
  27. #include <asm/qdio.h>
  28. #include <asm/ccwdev.h>
  29. #include <asm/ccwgroup.h>
  30. #include <asm/sysinfo.h>
  31. #include "qeth_core_mpc.h"
  32. /**
  33. * Debug Facility stuff
  34. */
  35. enum qeth_dbf_names {
  36. QETH_DBF_SETUP,
  37. QETH_DBF_MSG,
  38. QETH_DBF_CTRL,
  39. QETH_DBF_INFOS /* must be last element */
  40. };
  41. struct qeth_dbf_info {
  42. char name[DEBUG_MAX_NAME_LEN];
  43. int pages;
  44. int areas;
  45. int len;
  46. int level;
  47. struct debug_view *view;
  48. debug_info_t *id;
  49. };
  50. #define QETH_DBF_CTRL_LEN 256
  51. #define QETH_DBF_TEXT(name, level, text) \
  52. debug_text_event(qeth_dbf[QETH_DBF_##name].id, level, text)
  53. #define QETH_DBF_HEX(name, level, addr, len) \
  54. debug_event(qeth_dbf[QETH_DBF_##name].id, level, (void *)(addr), len)
  55. #define QETH_DBF_MESSAGE(level, text...) \
  56. debug_sprintf_event(qeth_dbf[QETH_DBF_MSG].id, level, text)
  57. #define QETH_DBF_TEXT_(name, level, text...) \
  58. qeth_dbf_longtext(qeth_dbf[QETH_DBF_##name].id, level, text)
  59. #define QETH_CARD_TEXT(card, level, text) \
  60. debug_text_event(card->debug, level, text)
  61. #define QETH_CARD_HEX(card, level, addr, len) \
  62. debug_event(card->debug, level, (void *)(addr), len)
  63. #define QETH_CARD_MESSAGE(card, text...) \
  64. debug_sprintf_event(card->debug, level, text)
  65. #define QETH_CARD_TEXT_(card, level, text...) \
  66. qeth_dbf_longtext(card->debug, level, text)
  67. #define SENSE_COMMAND_REJECT_BYTE 0
  68. #define SENSE_COMMAND_REJECT_FLAG 0x80
  69. #define SENSE_RESETTING_EVENT_BYTE 1
  70. #define SENSE_RESETTING_EVENT_FLAG 0x80
  71. /*
  72. * Common IO related definitions
  73. */
  74. #define CARD_RDEV(card) card->read.ccwdev
  75. #define CARD_WDEV(card) card->write.ccwdev
  76. #define CARD_DDEV(card) card->data.ccwdev
  77. #define CARD_BUS_ID(card) dev_name(&card->gdev->dev)
  78. #define CARD_RDEV_ID(card) dev_name(&card->read.ccwdev->dev)
  79. #define CARD_WDEV_ID(card) dev_name(&card->write.ccwdev->dev)
  80. #define CARD_DDEV_ID(card) dev_name(&card->data.ccwdev->dev)
  81. #define CHANNEL_ID(channel) dev_name(&channel->ccwdev->dev)
  82. /**
  83. * card stuff
  84. */
  85. struct qeth_perf_stats {
  86. unsigned int bufs_rec;
  87. unsigned int bufs_sent;
  88. unsigned int skbs_sent_pack;
  89. unsigned int bufs_sent_pack;
  90. unsigned int sc_dp_p;
  91. unsigned int sc_p_dp;
  92. /* qdio_cq_handler: number of times called, time spent in */
  93. __u64 cq_start_time;
  94. unsigned int cq_cnt;
  95. unsigned int cq_time;
  96. /* qdio_input_handler: number of times called, time spent in */
  97. __u64 inbound_start_time;
  98. unsigned int inbound_cnt;
  99. unsigned int inbound_time;
  100. /* qeth_send_packet: number of times called, time spent in */
  101. __u64 outbound_start_time;
  102. unsigned int outbound_cnt;
  103. unsigned int outbound_time;
  104. /* qdio_output_handler: number of times called, time spent in */
  105. __u64 outbound_handler_start_time;
  106. unsigned int outbound_handler_cnt;
  107. unsigned int outbound_handler_time;
  108. /* number of calls to and time spent in do_QDIO for inbound queue */
  109. __u64 inbound_do_qdio_start_time;
  110. unsigned int inbound_do_qdio_cnt;
  111. unsigned int inbound_do_qdio_time;
  112. /* number of calls to and time spent in do_QDIO for outbound queues */
  113. __u64 outbound_do_qdio_start_time;
  114. unsigned int outbound_do_qdio_cnt;
  115. unsigned int outbound_do_qdio_time;
  116. unsigned int large_send_bytes;
  117. unsigned int large_send_cnt;
  118. unsigned int sg_skbs_sent;
  119. unsigned int sg_frags_sent;
  120. /* initial values when measuring starts */
  121. unsigned long initial_rx_packets;
  122. unsigned long initial_tx_packets;
  123. /* inbound scatter gather data */
  124. unsigned int sg_skbs_rx;
  125. unsigned int sg_frags_rx;
  126. unsigned int sg_alloc_page_rx;
  127. unsigned int tx_csum;
  128. unsigned int tx_lin;
  129. unsigned int tx_linfail;
  130. unsigned int rx_csum;
  131. };
  132. /* Routing stuff */
  133. struct qeth_routing_info {
  134. enum qeth_routing_types type;
  135. };
  136. /* IPA stuff */
  137. struct qeth_ipa_info {
  138. __u32 supported_funcs;
  139. __u32 enabled_funcs;
  140. };
  141. /* SETBRIDGEPORT stuff */
  142. enum qeth_sbp_roles {
  143. QETH_SBP_ROLE_NONE = 0,
  144. QETH_SBP_ROLE_PRIMARY = 1,
  145. QETH_SBP_ROLE_SECONDARY = 2,
  146. };
  147. enum qeth_sbp_states {
  148. QETH_SBP_STATE_INACTIVE = 0,
  149. QETH_SBP_STATE_STANDBY = 1,
  150. QETH_SBP_STATE_ACTIVE = 2,
  151. };
  152. #define QETH_SBP_HOST_NOTIFICATION 1
  153. struct qeth_sbp_info {
  154. __u32 supported_funcs;
  155. enum qeth_sbp_roles role;
  156. __u32 hostnotification:1;
  157. __u32 reflect_promisc:1;
  158. __u32 reflect_promisc_primary:1;
  159. };
  160. struct qeth_vnicc_info {
  161. /* supported/currently configured VNICCs; updated in IPA exchanges */
  162. u32 sup_chars;
  163. u32 cur_chars;
  164. /* supported commands: bitmasks which VNICCs support respective cmd */
  165. u32 set_char_sup;
  166. u32 getset_timeout_sup;
  167. /* timeout value for the learning characteristic */
  168. u32 learning_timeout;
  169. /* characteristics wanted/configured by user */
  170. u32 wanted_chars;
  171. /* has user explicitly enabled rx_bcast while online? */
  172. bool rx_bcast_enabled;
  173. };
  174. static inline int qeth_is_ipa_supported(struct qeth_ipa_info *ipa,
  175. enum qeth_ipa_funcs func)
  176. {
  177. return (ipa->supported_funcs & func);
  178. }
  179. static inline int qeth_is_ipa_enabled(struct qeth_ipa_info *ipa,
  180. enum qeth_ipa_funcs func)
  181. {
  182. return (ipa->supported_funcs & ipa->enabled_funcs & func);
  183. }
  184. #define qeth_adp_supported(c, f) \
  185. qeth_is_ipa_supported(&c->options.adp, f)
  186. #define qeth_adp_enabled(c, f) \
  187. qeth_is_ipa_enabled(&c->options.adp, f)
  188. #define qeth_is_supported(c, f) \
  189. qeth_is_ipa_supported(&c->options.ipa4, f)
  190. #define qeth_is_enabled(c, f) \
  191. qeth_is_ipa_enabled(&c->options.ipa4, f)
  192. #define qeth_is_supported6(c, f) \
  193. qeth_is_ipa_supported(&c->options.ipa6, f)
  194. #define qeth_is_enabled6(c, f) \
  195. qeth_is_ipa_enabled(&c->options.ipa6, f)
  196. #define qeth_is_ipafunc_supported(c, prot, f) \
  197. ((prot == QETH_PROT_IPV6) ? \
  198. qeth_is_supported6(c, f) : qeth_is_supported(c, f))
  199. #define qeth_is_ipafunc_enabled(c, prot, f) \
  200. ((prot == QETH_PROT_IPV6) ? \
  201. qeth_is_enabled6(c, f) : qeth_is_enabled(c, f))
  202. #define QETH_IDX_FUNC_LEVEL_OSD 0x0101
  203. #define QETH_IDX_FUNC_LEVEL_IQD 0x4108
  204. #define QETH_BUFSIZE 4096
  205. /**
  206. * some more defs
  207. */
  208. #define QETH_TX_TIMEOUT 100 * HZ
  209. #define QETH_RCD_TIMEOUT 60 * HZ
  210. #define QETH_RECLAIM_WORK_TIME HZ
  211. #define QETH_MAX_PORTNO 15
  212. /*IPv6 address autoconfiguration stuff*/
  213. #define UNIQUE_ID_IF_CREATE_ADDR_FAILED 0xfffe
  214. #define UNIQUE_ID_NOT_BY_CARD 0x10000
  215. /*****************************************************************************/
  216. /* QDIO queue and buffer handling */
  217. /*****************************************************************************/
  218. #define QETH_MAX_QUEUES 4
  219. #define QETH_IN_BUF_SIZE_DEFAULT 65536
  220. #define QETH_IN_BUF_COUNT_DEFAULT 64
  221. #define QETH_IN_BUF_COUNT_HSDEFAULT 128
  222. #define QETH_IN_BUF_COUNT_MIN 8
  223. #define QETH_IN_BUF_COUNT_MAX 128
  224. #define QETH_MAX_BUFFER_ELEMENTS(card) ((card)->qdio.in_buf_size >> 12)
  225. #define QETH_IN_BUF_REQUEUE_THRESHOLD(card) \
  226. ((card)->qdio.in_buf_pool.buf_count / 2)
  227. /* buffers we have to be behind before we get a PCI */
  228. #define QETH_PCI_THRESHOLD_A(card) ((card)->qdio.in_buf_pool.buf_count+1)
  229. /*enqueued free buffers left before we get a PCI*/
  230. #define QETH_PCI_THRESHOLD_B(card) 0
  231. /*not used unless the microcode gets patched*/
  232. #define QETH_PCI_TIMER_VALUE(card) 3
  233. /* priority queing */
  234. #define QETH_PRIOQ_DEFAULT QETH_NO_PRIO_QUEUEING
  235. #define QETH_DEFAULT_QUEUE 2
  236. #define QETH_NO_PRIO_QUEUEING 0
  237. #define QETH_PRIO_Q_ING_PREC 1
  238. #define QETH_PRIO_Q_ING_TOS 2
  239. #define QETH_PRIO_Q_ING_SKB 3
  240. #define QETH_PRIO_Q_ING_VLAN 4
  241. /* Packing */
  242. #define QETH_LOW_WATERMARK_PACK 2
  243. #define QETH_HIGH_WATERMARK_PACK 5
  244. #define QETH_WATERMARK_PACK_FUZZ 1
  245. /* large receive scatter gather copy break */
  246. #define QETH_RX_SG_CB (PAGE_SIZE >> 1)
  247. #define QETH_RX_PULL_LEN 256
  248. struct qeth_hdr_layer3 {
  249. __u8 id;
  250. __u8 flags;
  251. __u16 inbound_checksum; /*TSO:__u16 seqno */
  252. __u32 token; /*TSO: __u32 reserved */
  253. __u16 length;
  254. __u8 vlan_prio;
  255. __u8 ext_flags;
  256. __u16 vlan_id;
  257. __u16 frame_offset;
  258. union {
  259. /* TX: */
  260. u8 ipv6_addr[16];
  261. struct ipv4 {
  262. u8 res[12];
  263. u32 addr;
  264. } ipv4;
  265. /* RX: */
  266. struct rx {
  267. u8 res1[2];
  268. u8 src_mac[6];
  269. u8 res2[4];
  270. u16 vlan_id;
  271. u8 res3[2];
  272. } rx;
  273. } next_hop;
  274. };
  275. struct qeth_hdr_layer2 {
  276. __u8 id;
  277. __u8 flags[3];
  278. __u8 port_no;
  279. __u8 hdr_length;
  280. __u16 pkt_length;
  281. __u16 seq_no;
  282. __u16 vlan_id;
  283. __u32 reserved;
  284. __u8 reserved2[16];
  285. } __attribute__ ((packed));
  286. struct qeth_hdr_osn {
  287. __u8 id;
  288. __u8 reserved;
  289. __u16 seq_no;
  290. __u16 reserved2;
  291. __u16 control_flags;
  292. __u16 pdu_length;
  293. __u8 reserved3[18];
  294. __u32 ccid;
  295. } __attribute__ ((packed));
  296. struct qeth_hdr {
  297. union {
  298. struct qeth_hdr_layer2 l2;
  299. struct qeth_hdr_layer3 l3;
  300. struct qeth_hdr_osn osn;
  301. } hdr;
  302. } __attribute__ ((packed));
  303. /*TCP Segmentation Offload header*/
  304. struct qeth_hdr_ext_tso {
  305. __u16 hdr_tot_len;
  306. __u8 imb_hdr_no;
  307. __u8 reserved;
  308. __u8 hdr_type;
  309. __u8 hdr_version;
  310. __u16 hdr_len;
  311. __u32 payload_len;
  312. __u16 mss;
  313. __u16 dg_hdr_len;
  314. __u8 padding[16];
  315. } __attribute__ ((packed));
  316. struct qeth_hdr_tso {
  317. struct qeth_hdr hdr; /*hdr->hdr.l3.xxx*/
  318. struct qeth_hdr_ext_tso ext;
  319. } __attribute__ ((packed));
  320. /* flags for qeth_hdr.flags */
  321. #define QETH_HDR_PASSTHRU 0x10
  322. #define QETH_HDR_IPV6 0x80
  323. #define QETH_HDR_CAST_MASK 0x07
  324. enum qeth_cast_flags {
  325. QETH_CAST_UNICAST = 0x06,
  326. QETH_CAST_MULTICAST = 0x04,
  327. QETH_CAST_BROADCAST = 0x05,
  328. QETH_CAST_ANYCAST = 0x07,
  329. QETH_CAST_NOCAST = 0x00,
  330. };
  331. enum qeth_layer2_frame_flags {
  332. QETH_LAYER2_FLAG_MULTICAST = 0x01,
  333. QETH_LAYER2_FLAG_BROADCAST = 0x02,
  334. QETH_LAYER2_FLAG_UNICAST = 0x04,
  335. QETH_LAYER2_FLAG_VLAN = 0x10,
  336. };
  337. enum qeth_header_ids {
  338. QETH_HEADER_TYPE_LAYER3 = 0x01,
  339. QETH_HEADER_TYPE_LAYER2 = 0x02,
  340. QETH_HEADER_TYPE_TSO = 0x03,
  341. QETH_HEADER_TYPE_OSN = 0x04,
  342. };
  343. /* flags for qeth_hdr.ext_flags */
  344. #define QETH_HDR_EXT_VLAN_FRAME 0x01
  345. #define QETH_HDR_EXT_TOKEN_ID 0x02
  346. #define QETH_HDR_EXT_INCLUDE_VLAN_TAG 0x04
  347. #define QETH_HDR_EXT_SRC_MAC_ADDR 0x08
  348. #define QETH_HDR_EXT_CSUM_HDR_REQ 0x10
  349. #define QETH_HDR_EXT_CSUM_TRANSP_REQ 0x20
  350. #define QETH_HDR_EXT_UDP 0x40 /*bit off for TCP*/
  351. enum qeth_qdio_buffer_states {
  352. /*
  353. * inbound: read out by driver; owned by hardware in order to be filled
  354. * outbound: owned by driver in order to be filled
  355. */
  356. QETH_QDIO_BUF_EMPTY,
  357. /*
  358. * inbound: filled by hardware; owned by driver in order to be read out
  359. * outbound: filled by driver; owned by hardware in order to be sent
  360. */
  361. QETH_QDIO_BUF_PRIMED,
  362. /*
  363. * inbound: not applicable
  364. * outbound: identified to be pending in TPQ
  365. */
  366. QETH_QDIO_BUF_PENDING,
  367. /*
  368. * inbound: not applicable
  369. * outbound: found in completion queue
  370. */
  371. QETH_QDIO_BUF_IN_CQ,
  372. /*
  373. * inbound: not applicable
  374. * outbound: handled via transfer pending / completion queue
  375. */
  376. QETH_QDIO_BUF_HANDLED_DELAYED,
  377. };
  378. enum qeth_qdio_info_states {
  379. QETH_QDIO_UNINITIALIZED,
  380. QETH_QDIO_ALLOCATED,
  381. QETH_QDIO_ESTABLISHED,
  382. QETH_QDIO_CLEANING
  383. };
  384. struct qeth_buffer_pool_entry {
  385. struct list_head list;
  386. struct list_head init_list;
  387. void *elements[QDIO_MAX_ELEMENTS_PER_BUFFER];
  388. };
  389. struct qeth_qdio_buffer_pool {
  390. struct list_head entry_list;
  391. int buf_count;
  392. };
  393. struct qeth_qdio_buffer {
  394. struct qdio_buffer *buffer;
  395. /* the buffer pool entry currently associated to this buffer */
  396. struct qeth_buffer_pool_entry *pool_entry;
  397. struct sk_buff *rx_skb;
  398. };
  399. struct qeth_qdio_q {
  400. struct qdio_buffer *qdio_bufs[QDIO_MAX_BUFFERS_PER_Q];
  401. struct qeth_qdio_buffer bufs[QDIO_MAX_BUFFERS_PER_Q];
  402. int next_buf_to_init;
  403. };
  404. struct qeth_qdio_out_buffer {
  405. struct qdio_buffer *buffer;
  406. atomic_t state;
  407. int next_element_to_fill;
  408. struct sk_buff_head skb_list;
  409. int is_header[QDIO_MAX_ELEMENTS_PER_BUFFER];
  410. struct qeth_qdio_out_q *q;
  411. struct qeth_qdio_out_buffer *next_pending;
  412. };
  413. struct qeth_card;
  414. enum qeth_out_q_states {
  415. QETH_OUT_Q_UNLOCKED,
  416. QETH_OUT_Q_LOCKED,
  417. QETH_OUT_Q_LOCKED_FLUSH,
  418. };
  419. struct qeth_qdio_out_q {
  420. struct qdio_buffer *qdio_bufs[QDIO_MAX_BUFFERS_PER_Q];
  421. struct qeth_qdio_out_buffer *bufs[QDIO_MAX_BUFFERS_PER_Q];
  422. struct qdio_outbuf_state *bufstates; /* convenience pointer */
  423. int queue_no;
  424. struct qeth_card *card;
  425. atomic_t state;
  426. int do_pack;
  427. /*
  428. * index of buffer to be filled by driver; state EMPTY or PACKING
  429. */
  430. int next_buf_to_fill;
  431. /*
  432. * number of buffers that are currently filled (PRIMED)
  433. * -> these buffers are hardware-owned
  434. */
  435. atomic_t used_buffers;
  436. /* indicates whether PCI flag must be set (or if one is outstanding) */
  437. atomic_t set_pci_flags_count;
  438. };
  439. struct qeth_qdio_info {
  440. atomic_t state;
  441. /* input */
  442. int no_in_queues;
  443. struct qeth_qdio_q *in_q;
  444. struct qeth_qdio_q *c_q;
  445. struct qeth_qdio_buffer_pool in_buf_pool;
  446. struct qeth_qdio_buffer_pool init_pool;
  447. int in_buf_size;
  448. /* output */
  449. int no_out_queues;
  450. struct qeth_qdio_out_q **out_qs;
  451. struct qdio_outbuf_state *out_bufstates;
  452. /* priority queueing */
  453. int do_prio_queueing;
  454. int default_out_queue;
  455. };
  456. /**
  457. * buffer stuff for read channel
  458. */
  459. #define QETH_CMD_BUFFER_NO 8
  460. /**
  461. * channel state machine
  462. */
  463. enum qeth_channel_states {
  464. CH_STATE_UP,
  465. CH_STATE_DOWN,
  466. CH_STATE_ACTIVATING,
  467. CH_STATE_HALTED,
  468. CH_STATE_STOPPED,
  469. CH_STATE_RCD,
  470. CH_STATE_RCD_DONE,
  471. };
  472. /**
  473. * card state machine
  474. */
  475. enum qeth_card_states {
  476. CARD_STATE_DOWN,
  477. CARD_STATE_HARDSETUP,
  478. CARD_STATE_SOFTSETUP,
  479. CARD_STATE_UP,
  480. CARD_STATE_RECOVER,
  481. };
  482. /**
  483. * Protocol versions
  484. */
  485. enum qeth_prot_versions {
  486. QETH_PROT_IPV4 = 0x0004,
  487. QETH_PROT_IPV6 = 0x0006,
  488. };
  489. enum qeth_cmd_buffer_state {
  490. BUF_STATE_FREE,
  491. BUF_STATE_LOCKED,
  492. };
  493. enum qeth_cq {
  494. QETH_CQ_DISABLED = 0,
  495. QETH_CQ_ENABLED = 1,
  496. QETH_CQ_NOTAVAILABLE = 2,
  497. };
  498. struct qeth_ipato {
  499. bool enabled;
  500. bool invert4;
  501. bool invert6;
  502. struct list_head entries;
  503. };
  504. struct qeth_channel;
  505. struct qeth_cmd_buffer {
  506. enum qeth_cmd_buffer_state state;
  507. struct qeth_channel *channel;
  508. unsigned char *data;
  509. int rc;
  510. void (*callback) (struct qeth_channel *, struct qeth_cmd_buffer *);
  511. };
  512. static inline struct qeth_ipa_cmd *__ipa_cmd(struct qeth_cmd_buffer *iob)
  513. {
  514. return (struct qeth_ipa_cmd *)(iob->data + IPA_PDU_HEADER_SIZE);
  515. }
  516. /**
  517. * definition of a qeth channel, used for read and write
  518. */
  519. struct qeth_channel {
  520. enum qeth_channel_states state;
  521. struct ccw1 ccw;
  522. spinlock_t iob_lock;
  523. wait_queue_head_t wait_q;
  524. struct ccw_device *ccwdev;
  525. /*command buffer for control data*/
  526. struct qeth_cmd_buffer iob[QETH_CMD_BUFFER_NO];
  527. atomic_t irq_pending;
  528. int io_buf_no;
  529. };
  530. /**
  531. * OSA card related definitions
  532. */
  533. struct qeth_token {
  534. __u32 issuer_rm_w;
  535. __u32 issuer_rm_r;
  536. __u32 cm_filter_w;
  537. __u32 cm_filter_r;
  538. __u32 cm_connection_w;
  539. __u32 cm_connection_r;
  540. __u32 ulp_filter_w;
  541. __u32 ulp_filter_r;
  542. __u32 ulp_connection_w;
  543. __u32 ulp_connection_r;
  544. };
  545. struct qeth_seqno {
  546. __u32 trans_hdr;
  547. __u32 pdu_hdr;
  548. __u32 pdu_hdr_ack;
  549. __u16 ipa;
  550. __u32 pkt_seqno;
  551. };
  552. struct qeth_reply {
  553. struct list_head list;
  554. wait_queue_head_t wait_q;
  555. int (*callback)(struct qeth_card *, struct qeth_reply *,
  556. unsigned long);
  557. u32 seqno;
  558. unsigned long offset;
  559. atomic_t received;
  560. int rc;
  561. void *param;
  562. struct qeth_card *card;
  563. refcount_t refcnt;
  564. };
  565. struct qeth_card_blkt {
  566. int time_total;
  567. int inter_packet;
  568. int inter_packet_jumbo;
  569. };
  570. #define QETH_BROADCAST_WITH_ECHO 0x01
  571. #define QETH_BROADCAST_WITHOUT_ECHO 0x02
  572. #define QETH_LAYER2_MAC_READ 0x01
  573. #define QETH_LAYER2_MAC_REGISTERED 0x02
  574. struct qeth_card_info {
  575. unsigned short unit_addr2;
  576. unsigned short cula;
  577. unsigned short chpid;
  578. __u16 func_level;
  579. char mcl_level[QETH_MCL_LENGTH + 1];
  580. int guestlan;
  581. int mac_bits;
  582. int portno;
  583. enum qeth_card_types type;
  584. enum qeth_link_types link_type;
  585. int initial_mtu;
  586. int max_mtu;
  587. int broadcast_capable;
  588. int unique_id;
  589. bool layer_enforced;
  590. struct qeth_card_blkt blkt;
  591. enum qeth_ipa_promisc_modes promisc_mode;
  592. __u32 diagass_support;
  593. __u32 hwtrap;
  594. };
  595. struct qeth_card_options {
  596. struct qeth_routing_info route4;
  597. struct qeth_ipa_info ipa4;
  598. struct qeth_ipa_info adp; /*Adapter parameters*/
  599. struct qeth_routing_info route6;
  600. struct qeth_ipa_info ipa6;
  601. struct qeth_sbp_info sbp; /* SETBRIDGEPORT options */
  602. struct qeth_vnicc_info vnicc; /* VNICC options */
  603. int fake_broadcast;
  604. int layer2;
  605. int performance_stats;
  606. int rx_sg_cb;
  607. enum qeth_ipa_isolation_modes isolation;
  608. enum qeth_ipa_isolation_modes prev_isolation;
  609. int sniffer;
  610. enum qeth_cq cq;
  611. char hsuid[9];
  612. };
  613. /*
  614. * thread bits for qeth_card thread masks
  615. */
  616. enum qeth_threads {
  617. QETH_RECOVER_THREAD = 1,
  618. };
  619. struct qeth_osn_info {
  620. int (*assist_cb)(struct net_device *dev, void *data);
  621. int (*data_cb)(struct sk_buff *skb);
  622. };
  623. enum qeth_discipline_id {
  624. QETH_DISCIPLINE_UNDETERMINED = -1,
  625. QETH_DISCIPLINE_LAYER3 = 0,
  626. QETH_DISCIPLINE_LAYER2 = 1,
  627. };
  628. struct qeth_discipline {
  629. const struct device_type *devtype;
  630. int (*process_rx_buffer)(struct qeth_card *card, int budget, int *done);
  631. int (*recover)(void *ptr);
  632. int (*setup) (struct ccwgroup_device *);
  633. void (*remove) (struct ccwgroup_device *);
  634. int (*set_online) (struct ccwgroup_device *);
  635. int (*set_offline) (struct ccwgroup_device *);
  636. int (*freeze)(struct ccwgroup_device *);
  637. int (*thaw) (struct ccwgroup_device *);
  638. int (*restore)(struct ccwgroup_device *);
  639. int (*do_ioctl)(struct net_device *dev, struct ifreq *rq, int cmd);
  640. int (*control_event_handler)(struct qeth_card *card,
  641. struct qeth_ipa_cmd *cmd);
  642. };
  643. struct qeth_vlan_vid {
  644. struct list_head list;
  645. unsigned short vid;
  646. };
  647. enum qeth_addr_disposition {
  648. QETH_DISP_ADDR_DELETE = 0,
  649. QETH_DISP_ADDR_DO_NOTHING = 1,
  650. QETH_DISP_ADDR_ADD = 2,
  651. };
  652. struct qeth_rx {
  653. int b_count;
  654. int b_index;
  655. struct qdio_buffer_element *b_element;
  656. int e_offset;
  657. int qdio_err;
  658. };
  659. struct carrier_info {
  660. __u8 card_type;
  661. __u16 port_mode;
  662. __u32 port_speed;
  663. };
  664. struct qeth_switch_info {
  665. __u32 capabilities;
  666. __u32 settings;
  667. };
  668. #define QETH_NAPI_WEIGHT NAPI_POLL_WEIGHT
  669. struct qeth_card {
  670. struct list_head list;
  671. enum qeth_card_states state;
  672. int lan_online;
  673. spinlock_t lock;
  674. struct ccwgroup_device *gdev;
  675. struct qeth_channel read;
  676. struct qeth_channel write;
  677. struct qeth_channel data;
  678. struct net_device *dev;
  679. struct net_device_stats stats;
  680. struct qeth_card_info info;
  681. struct qeth_token token;
  682. struct qeth_seqno seqno;
  683. struct qeth_card_options options;
  684. wait_queue_head_t wait_q;
  685. spinlock_t mclock;
  686. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  687. struct mutex vid_list_mutex; /* vid_list */
  688. struct list_head vid_list;
  689. DECLARE_HASHTABLE(mac_htable, 4);
  690. DECLARE_HASHTABLE(ip_htable, 4);
  691. DECLARE_HASHTABLE(ip_mc_htable, 4);
  692. struct work_struct kernel_thread_starter;
  693. spinlock_t thread_mask_lock;
  694. unsigned long thread_start_mask;
  695. unsigned long thread_allowed_mask;
  696. unsigned long thread_running_mask;
  697. struct task_struct *recovery_task;
  698. spinlock_t ip_lock;
  699. struct qeth_ipato ipato;
  700. struct list_head cmd_waiter_list;
  701. /* QDIO buffer handling */
  702. struct qeth_qdio_info qdio;
  703. struct qeth_perf_stats perf_stats;
  704. int read_or_write_problem;
  705. struct qeth_osn_info osn_info;
  706. struct qeth_discipline *discipline;
  707. atomic_t force_alloc_skb;
  708. struct service_level qeth_service_level;
  709. struct qdio_ssqd_desc ssqd;
  710. debug_info_t *debug;
  711. struct mutex conf_mutex;
  712. struct mutex discipline_mutex;
  713. struct napi_struct napi;
  714. struct qeth_rx rx;
  715. struct delayed_work buffer_reclaim_work;
  716. int reclaim_index;
  717. struct work_struct close_dev_work;
  718. };
  719. struct qeth_card_list_struct {
  720. struct list_head list;
  721. rwlock_t rwlock;
  722. };
  723. struct qeth_trap_id {
  724. __u16 lparnr;
  725. char vmname[8];
  726. __u8 chpid;
  727. __u8 ssid;
  728. __u16 devno;
  729. } __packed;
  730. /*some helper functions*/
  731. #define QETH_CARD_IFNAME(card) (((card)->dev)? (card)->dev->name : "")
  732. static inline void qeth_scrub_qdio_buffer(struct qdio_buffer *buf,
  733. unsigned int elements)
  734. {
  735. unsigned int i;
  736. for (i = 0; i < elements; i++)
  737. memset(&buf->element[i], 0, sizeof(struct qdio_buffer_element));
  738. buf->element[14].sflags = 0;
  739. buf->element[15].sflags = 0;
  740. }
  741. /**
  742. * qeth_get_elements_for_range() - find number of SBALEs to cover range.
  743. * @start: Start of the address range.
  744. * @end: Address after the end of the range.
  745. *
  746. * Returns the number of pages, and thus QDIO buffer elements, needed to cover
  747. * the specified address range.
  748. */
  749. static inline int qeth_get_elements_for_range(addr_t start, addr_t end)
  750. {
  751. return PFN_UP(end) - PFN_DOWN(start);
  752. }
  753. static inline int qeth_get_micros(void)
  754. {
  755. return (int) (get_tod_clock() >> 12);
  756. }
  757. static inline int qeth_get_ip_version(struct sk_buff *skb)
  758. {
  759. struct vlan_ethhdr *veth = vlan_eth_hdr(skb);
  760. __be16 prot = veth->h_vlan_proto;
  761. if (prot == htons(ETH_P_8021Q))
  762. prot = veth->h_vlan_encapsulated_proto;
  763. switch (prot) {
  764. case htons(ETH_P_IPV6):
  765. return 6;
  766. case htons(ETH_P_IP):
  767. return 4;
  768. default:
  769. return 0;
  770. }
  771. }
  772. static inline void qeth_rx_csum(struct qeth_card *card, struct sk_buff *skb,
  773. u8 flags)
  774. {
  775. if ((card->dev->features & NETIF_F_RXCSUM) &&
  776. (flags & QETH_HDR_EXT_CSUM_TRANSP_REQ)) {
  777. skb->ip_summed = CHECKSUM_UNNECESSARY;
  778. if (card->options.performance_stats)
  779. card->perf_stats.rx_csum++;
  780. } else {
  781. skb->ip_summed = CHECKSUM_NONE;
  782. }
  783. }
  784. static inline void qeth_tx_csum(struct sk_buff *skb, u8 *flags, int ipv)
  785. {
  786. *flags |= QETH_HDR_EXT_CSUM_TRANSP_REQ;
  787. if ((ipv == 4 && ip_hdr(skb)->protocol == IPPROTO_UDP) ||
  788. (ipv == 6 && ipv6_hdr(skb)->nexthdr == IPPROTO_UDP))
  789. *flags |= QETH_HDR_EXT_UDP;
  790. if (ipv == 4) {
  791. /* some HW requires combined L3+L4 csum offload: */
  792. *flags |= QETH_HDR_EXT_CSUM_HDR_REQ;
  793. ip_hdr(skb)->check = 0;
  794. }
  795. }
  796. static inline void qeth_put_buffer_pool_entry(struct qeth_card *card,
  797. struct qeth_buffer_pool_entry *entry)
  798. {
  799. list_add_tail(&entry->list, &card->qdio.in_buf_pool.entry_list);
  800. }
  801. static inline int qeth_is_diagass_supported(struct qeth_card *card,
  802. enum qeth_diags_cmds cmd)
  803. {
  804. return card->info.diagass_support & (__u32)cmd;
  805. }
  806. int qeth_send_simple_setassparms_prot(struct qeth_card *card,
  807. enum qeth_ipa_funcs ipa_func,
  808. u16 cmd_code, long data,
  809. enum qeth_prot_versions prot);
  810. /* IPv4 variant */
  811. static inline int qeth_send_simple_setassparms(struct qeth_card *card,
  812. enum qeth_ipa_funcs ipa_func,
  813. u16 cmd_code, long data)
  814. {
  815. return qeth_send_simple_setassparms_prot(card, ipa_func, cmd_code,
  816. data, QETH_PROT_IPV4);
  817. }
  818. static inline int qeth_send_simple_setassparms_v6(struct qeth_card *card,
  819. enum qeth_ipa_funcs ipa_func,
  820. u16 cmd_code, long data)
  821. {
  822. return qeth_send_simple_setassparms_prot(card, ipa_func, cmd_code,
  823. data, QETH_PROT_IPV6);
  824. }
  825. int qeth_get_priority_queue(struct qeth_card *card, struct sk_buff *skb,
  826. int ipv);
  827. static inline struct qeth_qdio_out_q *qeth_get_tx_queue(struct qeth_card *card,
  828. struct sk_buff *skb,
  829. int ipv, int cast_type)
  830. {
  831. if (IS_IQD(card) && cast_type != RTN_UNICAST)
  832. return card->qdio.out_qs[card->qdio.no_out_queues - 1];
  833. if (!card->qdio.do_prio_queueing)
  834. return card->qdio.out_qs[card->qdio.default_out_queue];
  835. return card->qdio.out_qs[qeth_get_priority_queue(card, skb, ipv)];
  836. }
  837. extern struct qeth_discipline qeth_l2_discipline;
  838. extern struct qeth_discipline qeth_l3_discipline;
  839. extern const struct attribute_group *qeth_generic_attr_groups[];
  840. extern const struct attribute_group *qeth_osn_attr_groups[];
  841. extern const struct attribute_group qeth_device_attr_group;
  842. extern const struct attribute_group qeth_device_blkt_group;
  843. extern const struct device_type qeth_generic_devtype;
  844. extern struct workqueue_struct *qeth_wq;
  845. int qeth_card_hw_is_reachable(struct qeth_card *);
  846. const char *qeth_get_cardname_short(struct qeth_card *);
  847. int qeth_realloc_buffer_pool(struct qeth_card *, int);
  848. int qeth_core_load_discipline(struct qeth_card *, enum qeth_discipline_id);
  849. void qeth_core_free_discipline(struct qeth_card *);
  850. /* exports for qeth discipline device drivers */
  851. extern struct qeth_card_list_struct qeth_core_card_list;
  852. extern struct kmem_cache *qeth_core_header_cache;
  853. extern struct qeth_dbf_info qeth_dbf[QETH_DBF_INFOS];
  854. void qeth_set_recovery_task(struct qeth_card *);
  855. void qeth_clear_recovery_task(struct qeth_card *);
  856. void qeth_set_allowed_threads(struct qeth_card *, unsigned long , int);
  857. int qeth_threads_running(struct qeth_card *, unsigned long);
  858. int qeth_wait_for_threads(struct qeth_card *, unsigned long);
  859. int qeth_do_run_thread(struct qeth_card *, unsigned long);
  860. void qeth_clear_thread_start_bit(struct qeth_card *, unsigned long);
  861. void qeth_clear_thread_running_bit(struct qeth_card *, unsigned long);
  862. int qeth_core_hardsetup_card(struct qeth_card *);
  863. void qeth_print_status_message(struct qeth_card *);
  864. int qeth_init_qdio_queues(struct qeth_card *);
  865. int qeth_send_ipa_cmd(struct qeth_card *, struct qeth_cmd_buffer *,
  866. int (*reply_cb)
  867. (struct qeth_card *, struct qeth_reply *, unsigned long),
  868. void *);
  869. struct qeth_cmd_buffer *qeth_get_ipacmd_buffer(struct qeth_card *,
  870. enum qeth_ipa_cmds, enum qeth_prot_versions);
  871. struct sk_buff *qeth_core_get_next_skb(struct qeth_card *,
  872. struct qeth_qdio_buffer *, struct qdio_buffer_element **, int *,
  873. struct qeth_hdr **);
  874. void qeth_schedule_recovery(struct qeth_card *);
  875. int qeth_poll(struct napi_struct *napi, int budget);
  876. void qeth_clear_ipacmd_list(struct qeth_card *);
  877. int qeth_qdio_clear_card(struct qeth_card *, int);
  878. void qeth_clear_working_pool_list(struct qeth_card *);
  879. void qeth_clear_cmd_buffers(struct qeth_channel *);
  880. void qeth_clear_qdio_buffers(struct qeth_card *);
  881. void qeth_setadp_promisc_mode(struct qeth_card *);
  882. struct net_device_stats *qeth_get_stats(struct net_device *);
  883. int qeth_change_mtu(struct net_device *, int);
  884. int qeth_setadpparms_change_macaddr(struct qeth_card *);
  885. void qeth_tx_timeout(struct net_device *);
  886. void qeth_prepare_control_data(struct qeth_card *, int,
  887. struct qeth_cmd_buffer *);
  888. void qeth_release_buffer(struct qeth_channel *, struct qeth_cmd_buffer *);
  889. void qeth_prepare_ipa_cmd(struct qeth_card *, struct qeth_cmd_buffer *, char);
  890. struct qeth_cmd_buffer *qeth_wait_for_buffer(struct qeth_channel *);
  891. int qeth_query_switch_attributes(struct qeth_card *card,
  892. struct qeth_switch_info *sw_info);
  893. int qeth_send_control_data(struct qeth_card *, int, struct qeth_cmd_buffer *,
  894. int (*reply_cb)(struct qeth_card *, struct qeth_reply*, unsigned long),
  895. void *reply_param);
  896. int qeth_get_elements_no(struct qeth_card *card, struct sk_buff *skb,
  897. int extra_elems, int data_offset);
  898. int qeth_get_elements_for_frags(struct sk_buff *);
  899. int qeth_do_send_packet_fast(struct qeth_qdio_out_q *queue, struct sk_buff *skb,
  900. struct qeth_hdr *hdr, unsigned int offset,
  901. unsigned int hd_len);
  902. int qeth_do_send_packet(struct qeth_card *card, struct qeth_qdio_out_q *queue,
  903. struct sk_buff *skb, struct qeth_hdr *hdr,
  904. unsigned int offset, unsigned int hd_len,
  905. int elements_needed);
  906. int qeth_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  907. int qeth_core_get_sset_count(struct net_device *, int);
  908. void qeth_core_get_ethtool_stats(struct net_device *,
  909. struct ethtool_stats *, u64 *);
  910. void qeth_core_get_strings(struct net_device *, u32, u8 *);
  911. void qeth_core_get_drvinfo(struct net_device *, struct ethtool_drvinfo *);
  912. void qeth_dbf_longtext(debug_info_t *id, int level, char *text, ...);
  913. int qeth_core_ethtool_get_link_ksettings(struct net_device *netdev,
  914. struct ethtool_link_ksettings *cmd);
  915. int qeth_set_access_ctrl_online(struct qeth_card *card, int fallback);
  916. int qeth_hdr_chk_and_bounce(struct sk_buff *, struct qeth_hdr **, int);
  917. int qeth_configure_cq(struct qeth_card *, enum qeth_cq);
  918. int qeth_hw_trap(struct qeth_card *, enum qeth_diags_trap_action);
  919. void qeth_trace_features(struct qeth_card *);
  920. void qeth_close_dev(struct qeth_card *);
  921. int qeth_send_setassparms(struct qeth_card *, struct qeth_cmd_buffer *, __u16,
  922. long,
  923. int (*reply_cb)(struct qeth_card *,
  924. struct qeth_reply *, unsigned long),
  925. void *);
  926. int qeth_setassparms_cb(struct qeth_card *, struct qeth_reply *, unsigned long);
  927. struct qeth_cmd_buffer *qeth_get_setassparms_cmd(struct qeth_card *,
  928. enum qeth_ipa_funcs,
  929. __u16, __u16,
  930. enum qeth_prot_versions);
  931. int qeth_set_features(struct net_device *, netdev_features_t);
  932. void qeth_enable_hw_features(struct net_device *dev);
  933. netdev_features_t qeth_fix_features(struct net_device *, netdev_features_t);
  934. netdev_features_t qeth_features_check(struct sk_buff *skb,
  935. struct net_device *dev,
  936. netdev_features_t features);
  937. int qeth_vm_request_mac(struct qeth_card *card);
  938. int qeth_push_hdr(struct sk_buff *skb, struct qeth_hdr **hdr, unsigned int len);
  939. /* exports for OSN */
  940. int qeth_osn_assist(struct net_device *, void *, int);
  941. int qeth_osn_register(unsigned char *read_dev_no, struct net_device **,
  942. int (*assist_cb)(struct net_device *, void *),
  943. int (*data_cb)(struct sk_buff *));
  944. void qeth_osn_deregister(struct net_device *);
  945. #endif /* __QETH_CORE_H__ */