root/drivers/s390/net/qeth_core.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. qeth_get_device_id
  2. qeth_is_adp_supported
  3. qeth_is_ipa_supported
  4. qeth_is_ipa_enabled
  5. qeth_l2_same_vlan
  6. qeth_l3_iqd_same_vlan
  7. qeth_l3_same_next_hop
  8. qeth_tx_arm_timer
  9. qeth_out_queue_is_full
  10. qeth_out_queue_is_empty
  11. qeth_get_cmd
  12. __ipa_cmd
  13. __ccw_from_cmd
  14. qeth_trylock_channel
  15. qeth_card_hw_is_reachable
  16. qeth_netdev_is_registered
  17. qeth_iqd_translate_txq
  18. qeth_scrub_qdio_buffer
  19. qeth_get_elements_for_range
  20. qeth_get_ip_version
  21. qeth_get_ether_cast_type
  22. qeth_dst_check_rcu
  23. qeth_rx_csum
  24. qeth_tx_csum
  25. qeth_put_buffer_pool_entry
  26. qeth_is_diagass_supported
  27. qeth_send_simple_setassparms
  28. qeth_send_simple_setassparms_v6

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

/* [<][>][^][v][top][bottom][index][help] */