qeth_core.h 29 KB

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