qeth_core.h 29 KB

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