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