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