Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  *    Copyright IBM Corp. 2007
0004  *    Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
0005  *       Frank Pavlic <fpavlic@de.ibm.com>,
0006  *       Thomas Spatzier <tspat@de.ibm.com>,
0007  *       Frank Blaschka <frank.blaschka@de.ibm.com>
0008  */
0009 
0010 #ifndef __QETH_CORE_H__
0011 #define __QETH_CORE_H__
0012 
0013 #include <linux/completion.h>
0014 #include <linux/debugfs.h>
0015 #include <linux/if.h>
0016 #include <linux/if_arp.h>
0017 #include <linux/etherdevice.h>
0018 #include <linux/if_vlan.h>
0019 #include <linux/ctype.h>
0020 #include <linux/in6.h>
0021 #include <linux/bitops.h>
0022 #include <linux/seq_file.h>
0023 #include <linux/hashtable.h>
0024 #include <linux/ip.h>
0025 #include <linux/rcupdate.h>
0026 #include <linux/refcount.h>
0027 #include <linux/timer.h>
0028 #include <linux/types.h>
0029 #include <linux/wait.h>
0030 #include <linux/workqueue.h>
0031 
0032 #include <net/dst.h>
0033 #include <net/ip6_fib.h>
0034 #include <net/ipv6.h>
0035 #include <net/if_inet6.h>
0036 #include <net/addrconf.h>
0037 #include <net/route.h>
0038 #include <net/sch_generic.h>
0039 #include <net/tcp.h>
0040 
0041 #include <asm/debug.h>
0042 #include <asm/qdio.h>
0043 #include <asm/ccwdev.h>
0044 #include <asm/ccwgroup.h>
0045 #include <asm/sysinfo.h>
0046 
0047 #include <uapi/linux/if_link.h>
0048 
0049 #include "qeth_core_mpc.h"
0050 
0051 /**
0052  * Debug Facility stuff
0053  */
0054 enum qeth_dbf_names {
0055     QETH_DBF_SETUP,
0056     QETH_DBF_MSG,
0057     QETH_DBF_CTRL,
0058     QETH_DBF_INFOS  /* must be last element */
0059 };
0060 
0061 struct qeth_dbf_info {
0062     char name[DEBUG_MAX_NAME_LEN];
0063     int pages;
0064     int areas;
0065     int len;
0066     int level;
0067     struct debug_view *view;
0068     debug_info_t *id;
0069 };
0070 
0071 #define QETH_DBF_CTRL_LEN 256U
0072 
0073 #define QETH_DBF_TEXT(name, level, text) \
0074     debug_text_event(qeth_dbf[QETH_DBF_##name].id, level, text)
0075 
0076 #define QETH_DBF_HEX(name, level, addr, len) \
0077     debug_event(qeth_dbf[QETH_DBF_##name].id, level, (void *)(addr), len)
0078 
0079 #define QETH_DBF_MESSAGE(level, text...) \
0080     debug_sprintf_event(qeth_dbf[QETH_DBF_MSG].id, level, text)
0081 
0082 #define QETH_DBF_TEXT_(name, level, text...) \
0083     qeth_dbf_longtext(qeth_dbf[QETH_DBF_##name].id, level, text)
0084 
0085 #define QETH_CARD_TEXT(card, level, text) \
0086     debug_text_event(card->debug, level, text)
0087 
0088 #define QETH_CARD_HEX(card, level, addr, len) \
0089     debug_event(card->debug, level, (void *)(addr), len)
0090 
0091 #define QETH_CARD_MESSAGE(card, text...) \
0092     debug_sprintf_event(card->debug, level, text)
0093 
0094 #define QETH_CARD_TEXT_(card, level, text...) \
0095     qeth_dbf_longtext(card->debug, level, text)
0096 
0097 #define SENSE_COMMAND_REJECT_BYTE 0
0098 #define SENSE_COMMAND_REJECT_FLAG 0x80
0099 #define SENSE_RESETTING_EVENT_BYTE 1
0100 #define SENSE_RESETTING_EVENT_FLAG 0x80
0101 
0102 static inline u32 qeth_get_device_id(struct ccw_device *cdev)
0103 {
0104     struct ccw_dev_id dev_id;
0105     u32 id;
0106 
0107     ccw_device_get_id(cdev, &dev_id);
0108     id = dev_id.devno;
0109     id |= (u32) (dev_id.ssid << 16);
0110 
0111     return id;
0112 }
0113 
0114 /*
0115  * Common IO related definitions
0116  */
0117 #define CARD_RDEV(card) card->read.ccwdev
0118 #define CARD_WDEV(card) card->write.ccwdev
0119 #define CARD_DDEV(card) card->data.ccwdev
0120 #define CARD_BUS_ID(card) dev_name(&card->gdev->dev)
0121 #define CARD_RDEV_ID(card) dev_name(&card->read.ccwdev->dev)
0122 #define CARD_WDEV_ID(card) dev_name(&card->write.ccwdev->dev)
0123 #define CARD_DDEV_ID(card) dev_name(&card->data.ccwdev->dev)
0124 #define CCW_DEVID(cdev)     (qeth_get_device_id(cdev))
0125 #define CARD_DEVID(card)    (CCW_DEVID(CARD_RDEV(card)))
0126 
0127 /* Routing stuff */
0128 struct qeth_routing_info {
0129     enum qeth_routing_types type;
0130 };
0131 
0132 /* SETBRIDGEPORT stuff */
0133 enum qeth_sbp_roles {
0134     QETH_SBP_ROLE_NONE  = 0,
0135     QETH_SBP_ROLE_PRIMARY   = 1,
0136     QETH_SBP_ROLE_SECONDARY = 2,
0137 };
0138 
0139 enum qeth_sbp_states {
0140     QETH_SBP_STATE_INACTIVE = 0,
0141     QETH_SBP_STATE_STANDBY  = 1,
0142     QETH_SBP_STATE_ACTIVE   = 2,
0143 };
0144 
0145 #define QETH_SBP_HOST_NOTIFICATION 1
0146 
0147 struct qeth_sbp_info {
0148     __u32 supported_funcs;
0149     enum qeth_sbp_roles role;
0150     __u32 hostnotification:1;
0151     __u32 reflect_promisc:1;
0152     __u32 reflect_promisc_primary:1;
0153 };
0154 
0155 struct qeth_vnicc_info {
0156     /* supported/currently configured VNICCs; updated in IPA exchanges */
0157     u32 sup_chars;
0158     u32 cur_chars;
0159     /* supported commands: bitmasks which VNICCs support respective cmd */
0160     u32 set_char_sup;
0161     u32 getset_timeout_sup;
0162     /* timeout value for the learning characteristic */
0163     u32 learning_timeout;
0164     /* characteristics wanted/configured by user */
0165     u32 wanted_chars;
0166     /* has user explicitly enabled rx_bcast while online? */
0167     bool rx_bcast_enabled;
0168 };
0169 
0170 #define QETH_IDX_FUNC_LEVEL_OSD      0x0101
0171 #define QETH_IDX_FUNC_LEVEL_IQD      0x4108
0172 
0173 #define QETH_BUFSIZE        4096
0174 #define CCW_CMD_WRITE       0x01
0175 #define CCW_CMD_READ        0x02
0176 
0177 /**
0178  * some more defs
0179  */
0180 #define QETH_TX_TIMEOUT     (100 * HZ)
0181 #define QETH_RCD_TIMEOUT    (60 * HZ)
0182 #define QETH_RECLAIM_WORK_TIME  HZ
0183 #define QETH_MAX_PORTNO     15
0184 
0185 /*****************************************************************************/
0186 /* QDIO queue and buffer handling                                            */
0187 /*****************************************************************************/
0188 #define QETH_MAX_OUT_QUEUES 4
0189 #define QETH_IQD_MIN_TXQ    2   /* One for ucast, one for mcast. */
0190 #define QETH_IQD_MCAST_TXQ  0
0191 #define QETH_IQD_MIN_UCAST_TXQ  1
0192 
0193 #define QETH_MAX_IN_QUEUES  2
0194 #define QETH_RX_COPYBREAK      (PAGE_SIZE >> 1)
0195 #define QETH_IN_BUF_SIZE_DEFAULT 65536
0196 #define QETH_IN_BUF_COUNT_DEFAULT 64
0197 #define QETH_IN_BUF_COUNT_HSDEFAULT 128
0198 #define QETH_IN_BUF_COUNT_MIN   8U
0199 #define QETH_IN_BUF_COUNT_MAX   128U
0200 #define QETH_MAX_BUFFER_ELEMENTS(card) ((card)->qdio.in_buf_size >> 12)
0201 #define QETH_IN_BUF_REQUEUE_THRESHOLD(card) \
0202          ((card)->qdio.in_buf_pool.buf_count / 2)
0203 
0204 /* buffers we have to be behind before we get a PCI */
0205 #define QETH_PCI_THRESHOLD_A(card) ((card)->qdio.in_buf_pool.buf_count+1)
0206 /*enqueued free buffers left before we get a PCI*/
0207 #define QETH_PCI_THRESHOLD_B(card) 0
0208 /*not used unless the microcode gets patched*/
0209 #define QETH_PCI_TIMER_VALUE(card) 3
0210 
0211 /* priority queing */
0212 #define QETH_PRIOQ_DEFAULT QETH_NO_PRIO_QUEUEING
0213 #define QETH_DEFAULT_QUEUE    2
0214 #define QETH_NO_PRIO_QUEUEING 0
0215 #define QETH_PRIO_Q_ING_PREC  1
0216 #define QETH_PRIO_Q_ING_TOS   2
0217 #define QETH_PRIO_Q_ING_SKB   3
0218 #define QETH_PRIO_Q_ING_VLAN  4
0219 #define QETH_PRIO_Q_ING_FIXED 5
0220 
0221 /* Packing */
0222 #define QETH_LOW_WATERMARK_PACK  2
0223 #define QETH_HIGH_WATERMARK_PACK 5
0224 #define QETH_WATERMARK_PACK_FUZZ 1
0225 
0226 struct qeth_hdr_layer3 {
0227     __u8  id;
0228     __u8  flags;
0229     __u16 inbound_checksum; /*TSO:__u16 seqno */
0230     __u32 token;        /*TSO: __u32 reserved */
0231     __u16 length;
0232     __u8  vlan_prio;
0233     __u8  ext_flags;
0234     __u16 vlan_id;
0235     __u16 frame_offset;
0236     union {
0237         /* TX: */
0238         struct in6_addr addr;
0239         /* RX: */
0240         struct rx {
0241             u8 res1[2];
0242             u8 src_mac[6];
0243             u8 res2[4];
0244             u16 vlan_id;
0245             u8 res3[2];
0246         } rx;
0247     } next_hop;
0248 };
0249 
0250 struct qeth_hdr_layer2 {
0251     __u8 id;
0252     __u8 flags[3];
0253     __u8 port_no;
0254     __u8 hdr_length;
0255     __u16 pkt_length;
0256     __u16 seq_no;
0257     __u16 vlan_id;
0258     __u32 reserved;
0259     __u8 reserved2[16];
0260 } __attribute__ ((packed));
0261 
0262 struct qeth_hdr {
0263     union {
0264         struct qeth_hdr_layer2 l2;
0265         struct qeth_hdr_layer3 l3;
0266     } hdr;
0267 } __attribute__ ((packed));
0268 
0269 #define QETH_QIB_PQUE_ORDER_RR      0
0270 #define QETH_QIB_PQUE_UNITS_SBAL    2
0271 #define QETH_QIB_PQUE_PRIO_DEFAULT  4
0272 
0273 struct qeth_qib_parms {
0274     char pcit_magic[4];
0275     u32 pcit_a;
0276     u32 pcit_b;
0277     u32 pcit_c;
0278     char blkt_magic[4];
0279     u32 blkt_total;
0280     u32 blkt_inter_packet;
0281     u32 blkt_inter_packet_jumbo;
0282     char pque_magic[4];
0283     u8 pque_order;
0284     u8 pque_units;
0285     u16 reserved;
0286     u32 pque_priority[4];
0287 };
0288 
0289 /*TCP Segmentation Offload header*/
0290 struct qeth_hdr_ext_tso {
0291     __u16 hdr_tot_len;
0292     __u8  imb_hdr_no;
0293     __u8  reserved;
0294     __u8  hdr_type;
0295     __u8  hdr_version;
0296     __u16 hdr_len;
0297     __u32 payload_len;
0298     __u16 mss;
0299     __u16 dg_hdr_len;
0300     __u8  padding[16];
0301 } __attribute__ ((packed));
0302 
0303 struct qeth_hdr_tso {
0304     struct qeth_hdr hdr;    /*hdr->hdr.l3.xxx*/
0305     struct qeth_hdr_ext_tso ext;
0306 } __attribute__ ((packed));
0307 
0308 
0309 /* flags for qeth_hdr.flags */
0310 #define QETH_HDR_PASSTHRU 0x10
0311 #define QETH_HDR_IPV6     0x80
0312 #define QETH_HDR_CAST_MASK 0x07
0313 enum qeth_cast_flags {
0314     QETH_CAST_UNICAST   = 0x06,
0315     QETH_CAST_MULTICAST = 0x04,
0316     QETH_CAST_BROADCAST = 0x05,
0317     QETH_CAST_ANYCAST   = 0x07,
0318     QETH_CAST_NOCAST    = 0x00,
0319 };
0320 
0321 enum qeth_layer2_frame_flags {
0322     QETH_LAYER2_FLAG_MULTICAST = 0x01,
0323     QETH_LAYER2_FLAG_BROADCAST = 0x02,
0324     QETH_LAYER2_FLAG_UNICAST   = 0x04,
0325     QETH_LAYER2_FLAG_VLAN      = 0x10,
0326 };
0327 
0328 enum qeth_header_ids {
0329     QETH_HEADER_TYPE_LAYER3 = 0x01,
0330     QETH_HEADER_TYPE_LAYER2 = 0x02,
0331     QETH_HEADER_TYPE_L3_TSO = 0x03,
0332     QETH_HEADER_TYPE_L2_TSO = 0x06,
0333     QETH_HEADER_MASK_INVAL  = 0x80,
0334 };
0335 /* flags for qeth_hdr.ext_flags */
0336 #define QETH_HDR_EXT_VLAN_FRAME       0x01
0337 #define QETH_HDR_EXT_TOKEN_ID         0x02
0338 #define QETH_HDR_EXT_INCLUDE_VLAN_TAG 0x04
0339 #define QETH_HDR_EXT_SRC_MAC_ADDR     0x08
0340 #define QETH_HDR_EXT_CSUM_HDR_REQ     0x10
0341 #define QETH_HDR_EXT_CSUM_TRANSP_REQ  0x20
0342 #define QETH_HDR_EXT_UDP          0x40 /*bit off for TCP*/
0343 
0344 static inline bool qeth_l2_same_vlan(struct qeth_hdr_layer2 *h1,
0345                      struct qeth_hdr_layer2 *h2)
0346 {
0347     return !((h1->flags[2] ^ h2->flags[2]) & QETH_LAYER2_FLAG_VLAN) &&
0348            h1->vlan_id == h2->vlan_id;
0349 }
0350 
0351 static inline bool qeth_l3_iqd_same_vlan(struct qeth_hdr_layer3 *h1,
0352                      struct qeth_hdr_layer3 *h2)
0353 {
0354     return !((h1->ext_flags ^ h2->ext_flags) & QETH_HDR_EXT_VLAN_FRAME) &&
0355            h1->vlan_id == h2->vlan_id;
0356 }
0357 
0358 static inline bool qeth_l3_same_next_hop(struct qeth_hdr_layer3 *h1,
0359                      struct qeth_hdr_layer3 *h2)
0360 {
0361     return !((h1->flags ^ h2->flags) & QETH_HDR_IPV6) &&
0362            ipv6_addr_equal(&h1->next_hop.addr, &h2->next_hop.addr);
0363 }
0364 
0365 struct qeth_local_addr {
0366     struct hlist_node hnode;
0367     struct rcu_head rcu;
0368     struct in6_addr addr;
0369 };
0370 
0371 enum qeth_qdio_info_states {
0372     QETH_QDIO_UNINITIALIZED,
0373     QETH_QDIO_ALLOCATED,
0374     QETH_QDIO_ESTABLISHED,
0375     QETH_QDIO_CLEANING
0376 };
0377 
0378 struct qeth_buffer_pool_entry {
0379     struct list_head list;
0380     struct list_head init_list;
0381     struct page *elements[QDIO_MAX_ELEMENTS_PER_BUFFER];
0382 };
0383 
0384 struct qeth_qdio_buffer_pool {
0385     struct list_head entry_list;
0386     int buf_count;
0387 };
0388 
0389 struct qeth_qdio_buffer {
0390     struct qdio_buffer *buffer;
0391     /* the buffer pool entry currently associated to this buffer */
0392     struct qeth_buffer_pool_entry *pool_entry;
0393     struct sk_buff *rx_skb;
0394 };
0395 
0396 struct qeth_qdio_q {
0397     struct qdio_buffer *qdio_bufs[QDIO_MAX_BUFFERS_PER_Q];
0398     struct qeth_qdio_buffer bufs[QDIO_MAX_BUFFERS_PER_Q];
0399     int next_buf_to_init;
0400 };
0401 
0402 enum qeth_qdio_out_buffer_state {
0403     /* Owned by driver, in order to be filled. */
0404     QETH_QDIO_BUF_EMPTY,
0405     /* Filled by driver; owned by hardware in order to be sent. */
0406     QETH_QDIO_BUF_PRIMED,
0407 };
0408 
0409 enum qeth_qaob_state {
0410     QETH_QAOB_ISSUED,
0411     QETH_QAOB_PENDING,
0412     QETH_QAOB_DONE,
0413 };
0414 
0415 struct qeth_qaob_priv1 {
0416     unsigned int state;
0417     u8 queue_no;
0418 };
0419 
0420 struct qeth_qdio_out_buffer {
0421     struct qdio_buffer *buffer;
0422     atomic_t state;
0423     int next_element_to_fill;
0424     unsigned int frames;
0425     unsigned int bytes;
0426     struct sk_buff_head skb_list;
0427     DECLARE_BITMAP(from_kmem_cache, QDIO_MAX_ELEMENTS_PER_BUFFER);
0428 
0429     struct list_head list_entry;
0430     struct qaob *aob;
0431 };
0432 
0433 struct qeth_card;
0434 
0435 #define QETH_CARD_STAT_ADD(_c, _stat, _val) ((_c)->stats._stat += (_val))
0436 #define QETH_CARD_STAT_INC(_c, _stat)       QETH_CARD_STAT_ADD(_c, _stat, 1)
0437 
0438 #define QETH_TXQ_STAT_ADD(_q, _stat, _val)  ((_q)->stats._stat += (_val))
0439 #define QETH_TXQ_STAT_INC(_q, _stat)        QETH_TXQ_STAT_ADD(_q, _stat, 1)
0440 
0441 struct qeth_card_stats {
0442     u64 rx_bufs;
0443     u64 rx_skb_csum;
0444     u64 rx_sg_skbs;
0445     u64 rx_sg_frags;
0446     u64 rx_sg_alloc_page;
0447 
0448     u64 rx_dropped_nomem;
0449     u64 rx_dropped_notsupp;
0450     u64 rx_dropped_runt;
0451 
0452     /* rtnl_link_stats64 */
0453     u64 rx_packets;
0454     u64 rx_bytes;
0455     u64 rx_multicast;
0456     u64 rx_length_errors;
0457     u64 rx_frame_errors;
0458     u64 rx_fifo_errors;
0459 };
0460 
0461 struct qeth_out_q_stats {
0462     u64 bufs;
0463     u64 bufs_pack;
0464     u64 buf_elements;
0465     u64 skbs_pack;
0466     u64 skbs_sg;
0467     u64 skbs_csum;
0468     u64 skbs_tso;
0469     u64 skbs_linearized;
0470     u64 skbs_linearized_fail;
0471     u64 tso_bytes;
0472     u64 packing_mode_switch;
0473     u64 stopped;
0474     u64 doorbell;
0475     u64 coal_frames;
0476     u64 completion_irq;
0477     u64 completion_yield;
0478     u64 completion_timer;
0479 
0480     /* rtnl_link_stats64 */
0481     u64 tx_packets;
0482     u64 tx_bytes;
0483     u64 tx_errors;
0484     u64 tx_dropped;
0485 };
0486 
0487 #define QETH_TX_MAX_COALESCED_FRAMES    1
0488 #define QETH_TX_COALESCE_USECS      25
0489 #define QETH_TX_TIMER_USECS     500
0490 
0491 struct qeth_qdio_out_q {
0492     struct qdio_buffer *qdio_bufs[QDIO_MAX_BUFFERS_PER_Q];
0493     struct qeth_qdio_out_buffer *bufs[QDIO_MAX_BUFFERS_PER_Q];
0494     struct list_head pending_bufs;
0495     struct qeth_out_q_stats stats;
0496     spinlock_t lock;
0497     unsigned int priority;
0498     u8 next_buf_to_fill;
0499     u8 max_elements;
0500     u8 queue_no;
0501     u8 do_pack;
0502     struct qeth_card *card;
0503     /*
0504      * number of buffers that are currently filled (PRIMED)
0505      * -> these buffers are hardware-owned
0506      */
0507     atomic_t used_buffers;
0508     /* indicates whether PCI flag must be set (or if one is outstanding) */
0509     atomic_t set_pci_flags_count;
0510     struct napi_struct napi;
0511     struct timer_list timer;
0512     struct qeth_hdr *prev_hdr;
0513     unsigned int coalesced_frames;
0514     u8 bulk_start;
0515     u8 bulk_count;
0516     u8 bulk_max;
0517 
0518     unsigned int coalesce_usecs;
0519     unsigned int max_coalesced_frames;
0520     unsigned int rescan_usecs;
0521 };
0522 
0523 #define qeth_for_each_output_queue(card, q, i)      \
0524     for (i = 0; i < card->qdio.no_out_queues && \
0525             (q = card->qdio.out_qs[i]); i++)
0526 
0527 #define qeth_napi_to_out_queue(n) container_of(n, struct qeth_qdio_out_q, napi)
0528 
0529 static inline void qeth_tx_arm_timer(struct qeth_qdio_out_q *queue,
0530                      unsigned long usecs)
0531 {
0532     timer_reduce(&queue->timer, usecs_to_jiffies(usecs) + jiffies);
0533 }
0534 
0535 static inline bool qeth_out_queue_is_full(struct qeth_qdio_out_q *queue)
0536 {
0537     return atomic_read(&queue->used_buffers) >= QDIO_MAX_BUFFERS_PER_Q;
0538 }
0539 
0540 static inline bool qeth_out_queue_is_empty(struct qeth_qdio_out_q *queue)
0541 {
0542     return atomic_read(&queue->used_buffers) == 0;
0543 }
0544 
0545 struct qeth_qdio_info {
0546     atomic_t state;
0547     /* input */
0548     struct qeth_qdio_q *in_q;
0549     struct qeth_qdio_q *c_q;
0550     struct qeth_qdio_buffer_pool in_buf_pool;
0551     struct qeth_qdio_buffer_pool init_pool;
0552     int in_buf_size;
0553 
0554     /* output */
0555     unsigned int no_out_queues;
0556     struct qeth_qdio_out_q *out_qs[QETH_MAX_OUT_QUEUES];
0557 
0558     /* priority queueing */
0559     int do_prio_queueing;
0560     int default_out_queue;
0561 };
0562 
0563 /**
0564  *  channel state machine
0565  */
0566 enum qeth_channel_states {
0567     CH_STATE_UP,
0568     CH_STATE_DOWN,
0569     CH_STATE_HALTED,
0570     CH_STATE_STOPPED,
0571 };
0572 /**
0573  * card state machine
0574  */
0575 enum qeth_card_states {
0576     CARD_STATE_DOWN,
0577     CARD_STATE_SOFTSETUP,
0578 };
0579 
0580 /**
0581  * Protocol versions
0582  */
0583 enum qeth_prot_versions {
0584     QETH_PROT_NONE = 0x0000,
0585     QETH_PROT_IPV4 = 0x0004,
0586     QETH_PROT_IPV6 = 0x0006,
0587 };
0588 
0589 enum qeth_cq {
0590     QETH_CQ_DISABLED = 0,
0591     QETH_CQ_ENABLED = 1,
0592     QETH_CQ_NOTAVAILABLE = 2,
0593 };
0594 
0595 struct qeth_ipato {
0596     bool enabled;
0597     bool invert4;
0598     bool invert6;
0599     struct list_head entries;
0600 };
0601 
0602 struct qeth_channel {
0603     struct ccw_device *ccwdev;
0604     struct qeth_cmd_buffer *active_cmd;
0605     enum qeth_channel_states state;
0606 };
0607 
0608 struct qeth_reply {
0609     int (*callback)(struct qeth_card *card, struct qeth_reply *reply,
0610             unsigned long data);
0611     void *param;
0612 };
0613 
0614 struct qeth_cmd_buffer {
0615     struct list_head list_entry;
0616     struct completion done;
0617     spinlock_t lock;
0618     unsigned int length;
0619     refcount_t ref_count;
0620     struct qeth_channel *channel;
0621     struct qeth_reply reply;
0622     long timeout;
0623     unsigned char *data;
0624     void (*finalize)(struct qeth_card *card, struct qeth_cmd_buffer *iob);
0625     bool (*match)(struct qeth_cmd_buffer *iob,
0626               struct qeth_cmd_buffer *reply);
0627     void (*callback)(struct qeth_card *card, struct qeth_cmd_buffer *iob,
0628              unsigned int data_length);
0629     int rc;
0630 };
0631 
0632 static inline void qeth_get_cmd(struct qeth_cmd_buffer *iob)
0633 {
0634     refcount_inc(&iob->ref_count);
0635 }
0636 
0637 static inline struct qeth_ipa_cmd *__ipa_reply(struct qeth_cmd_buffer *iob)
0638 {
0639     if (!IS_IPA(iob->data))
0640         return NULL;
0641 
0642     return (struct qeth_ipa_cmd *) PDU_ENCAPSULATION(iob->data);
0643 }
0644 
0645 static inline struct qeth_ipa_cmd *__ipa_cmd(struct qeth_cmd_buffer *iob)
0646 {
0647     return (struct qeth_ipa_cmd *)(iob->data + IPA_PDU_HEADER_SIZE);
0648 }
0649 
0650 static inline struct ccw1 *__ccw_from_cmd(struct qeth_cmd_buffer *iob)
0651 {
0652     return (struct ccw1 *)(iob->data + ALIGN(iob->length, 8));
0653 }
0654 
0655 /**
0656  *  OSA card related definitions
0657  */
0658 struct qeth_token {
0659     __u32 issuer_rm_w;
0660     __u32 issuer_rm_r;
0661     __u32 cm_filter_w;
0662     __u32 cm_filter_r;
0663     __u32 cm_connection_w;
0664     __u32 cm_connection_r;
0665     __u32 ulp_filter_w;
0666     __u32 ulp_filter_r;
0667     __u32 ulp_connection_w;
0668     __u32 ulp_connection_r;
0669 };
0670 
0671 struct qeth_seqno {
0672     __u32 trans_hdr;
0673     __u32 pdu_hdr;
0674     __u32 pdu_hdr_ack;
0675     __u16 ipa;
0676 };
0677 
0678 struct qeth_card_blkt {
0679     int time_total;
0680     int inter_packet;
0681     int inter_packet_jumbo;
0682 };
0683 
0684 enum qeth_pnso_mode {
0685     QETH_PNSO_NONE,
0686     QETH_PNSO_BRIDGEPORT,
0687     QETH_PNSO_ADDR_INFO,
0688 };
0689 
0690 enum qeth_link_mode {
0691     QETH_LINK_MODE_UNKNOWN,
0692     QETH_LINK_MODE_FIBRE_SHORT,
0693     QETH_LINK_MODE_FIBRE_LONG,
0694 };
0695 
0696 struct qeth_link_info {
0697     u32 speed;
0698     u8 duplex;
0699     u8 port;
0700     enum qeth_link_mode link_mode;
0701 };
0702 
0703 #define QETH_BROADCAST_WITH_ECHO    0x01
0704 #define QETH_BROADCAST_WITHOUT_ECHO 0x02
0705 struct qeth_card_info {
0706     unsigned short unit_addr2;
0707     unsigned short cula;
0708     __u16 func_level;
0709     char mcl_level[QETH_MCL_LENGTH + 1];
0710     /* doubleword below corresponds to net_if_token */
0711     u16 ddev_devno;
0712     u8 cssid;
0713     u8 iid;
0714     u8 ssid;
0715     u8 chpid;
0716     u16 chid;
0717     u8 ids_valid:1; /* cssid,iid,chid */
0718     u8 dev_addr_is_registered:1;
0719     u8 open_when_online:1;
0720     u8 promisc_mode:1;
0721     u8 use_v1_blkt:1;
0722     u8 is_vm_nic:1;
0723     /* no bitfield, we take a pointer on these two: */
0724     u8 has_lp2lp_cso_v6;
0725     u8 has_lp2lp_cso_v4;
0726     enum qeth_pnso_mode pnso_mode;
0727     enum qeth_card_types type;
0728     enum qeth_link_types link_type;
0729     int broadcast_capable;
0730     bool layer_enforced;
0731     struct qeth_card_blkt blkt;
0732     __u32 diagass_support;
0733     __u32 hwtrap;
0734     struct qeth_link_info link_info;
0735 };
0736 
0737 enum qeth_discipline_id {
0738     QETH_DISCIPLINE_UNDETERMINED = -1,
0739     QETH_DISCIPLINE_LAYER3 = 0,
0740     QETH_DISCIPLINE_LAYER2 = 1,
0741 };
0742 
0743 struct qeth_card_options {
0744     struct qeth_ipa_caps ipa4;
0745     struct qeth_ipa_caps ipa6;
0746     struct qeth_routing_info route4;
0747     struct qeth_routing_info route6;
0748     struct qeth_ipa_caps adp; /* Adapter parameters */
0749     struct qeth_sbp_info sbp; /* SETBRIDGEPORT options */
0750     struct qeth_vnicc_info vnicc; /* VNICC options */
0751     enum qeth_discipline_id layer;
0752     enum qeth_ipa_isolation_modes isolation;
0753     int sniffer;
0754     enum qeth_cq cq;
0755     char hsuid[9];
0756 };
0757 
0758 #define IS_LAYER2(card) ((card)->options.layer == QETH_DISCIPLINE_LAYER2)
0759 #define IS_LAYER3(card) ((card)->options.layer == QETH_DISCIPLINE_LAYER3)
0760 
0761 /*
0762  * thread bits for qeth_card thread masks
0763  */
0764 enum qeth_threads {
0765     QETH_RECOVER_THREAD = 1,
0766 };
0767 
0768 struct qeth_discipline {
0769     int (*setup) (struct ccwgroup_device *);
0770     void (*remove) (struct ccwgroup_device *);
0771     int (*set_online)(struct qeth_card *card, bool carrier_ok);
0772     void (*set_offline)(struct qeth_card *card);
0773     int (*control_event_handler)(struct qeth_card *card,
0774                     struct qeth_ipa_cmd *cmd);
0775 };
0776 
0777 enum qeth_addr_disposition {
0778     QETH_DISP_ADDR_DELETE = 0,
0779     QETH_DISP_ADDR_DO_NOTHING = 1,
0780     QETH_DISP_ADDR_ADD = 2,
0781 };
0782 
0783 struct qeth_rx {
0784     int b_count;
0785     int b_index;
0786     u8 buf_element;
0787     int e_offset;
0788     int qdio_err;
0789     u8 bufs_refill;
0790 };
0791 
0792 struct qeth_switch_info {
0793     __u32 capabilities;
0794     __u32 settings;
0795 };
0796 
0797 struct qeth_priv {
0798     unsigned int rx_copybreak;
0799     unsigned int tx_wanted_queues;
0800     u32 brport_hw_features;
0801     u32 brport_features;
0802 };
0803 
0804 struct qeth_card {
0805     enum qeth_card_states state;
0806     spinlock_t lock;
0807     struct ccwgroup_device *gdev;
0808     struct qeth_cmd_buffer *read_cmd;
0809     struct qeth_channel read;
0810     struct qeth_channel write;
0811     struct qeth_channel data;
0812 
0813     struct net_device *dev;
0814     struct dentry *debugfs;
0815     struct qeth_card_stats stats;
0816     struct qeth_card_info info;
0817     struct qeth_token token;
0818     struct qeth_seqno seqno;
0819     struct qeth_card_options options;
0820 
0821     struct workqueue_struct *event_wq;
0822     struct workqueue_struct *cmd_wq;
0823     wait_queue_head_t wait_q;
0824 
0825     struct mutex ip_lock;
0826     /* protected by ip_lock: */
0827     DECLARE_HASHTABLE(ip_htable, 4);
0828     struct qeth_ipato ipato;
0829 
0830     DECLARE_HASHTABLE(local_addrs4, 4);
0831     DECLARE_HASHTABLE(local_addrs6, 4);
0832     spinlock_t local_addrs4_lock;
0833     spinlock_t local_addrs6_lock;
0834     DECLARE_HASHTABLE(rx_mode_addrs, 4);
0835     struct work_struct rx_mode_work;
0836     struct work_struct kernel_thread_starter;
0837     spinlock_t thread_mask_lock;
0838     unsigned long thread_start_mask;
0839     unsigned long thread_allowed_mask;
0840     unsigned long thread_running_mask;
0841     struct list_head cmd_waiter_list;
0842     /* QDIO buffer handling */
0843     struct qeth_qdio_info qdio;
0844     int read_or_write_problem;
0845     const struct qeth_discipline *discipline;
0846     atomic_t force_alloc_skb;
0847     struct service_level qeth_service_level;
0848     struct qdio_ssqd_desc ssqd;
0849     debug_info_t *debug;
0850     struct mutex sbp_lock;
0851     struct mutex conf_mutex;
0852     struct mutex discipline_mutex;
0853     struct napi_struct napi;
0854     struct qeth_rx rx;
0855     struct delayed_work buffer_reclaim_work;
0856 };
0857 
0858 static inline bool qeth_card_hw_is_reachable(struct qeth_card *card)
0859 {
0860     return card->state == CARD_STATE_SOFTSETUP;
0861 }
0862 
0863 static inline bool qeth_use_tx_irqs(struct qeth_card *card)
0864 {
0865     return !IS_IQD(card);
0866 }
0867 
0868 static inline void qeth_unlock_channel(struct qeth_card *card,
0869                        struct qeth_channel *channel)
0870 {
0871     xchg(&channel->active_cmd, NULL);
0872     wake_up(&card->wait_q);
0873 }
0874 
0875 static inline bool qeth_trylock_channel(struct qeth_channel *channel,
0876                     struct qeth_cmd_buffer *cmd)
0877 {
0878     return cmpxchg(&channel->active_cmd, NULL, cmd) == NULL;
0879 }
0880 
0881 struct qeth_trap_id {
0882     __u16 lparnr;
0883     char vmname[8];
0884     __u8 chpid;
0885     __u8 ssid;
0886     __u16 devno;
0887 } __packed;
0888 
0889 static inline bool qeth_uses_tx_prio_queueing(struct qeth_card *card)
0890 {
0891     return card->qdio.do_prio_queueing != QETH_NO_PRIO_QUEUEING;
0892 }
0893 
0894 static inline unsigned int qeth_tx_actual_queues(struct qeth_card *card)
0895 {
0896     struct qeth_priv *priv = netdev_priv(card->dev);
0897 
0898     if (qeth_uses_tx_prio_queueing(card))
0899         return min(card->dev->num_tx_queues, card->qdio.no_out_queues);
0900 
0901     return min(priv->tx_wanted_queues, card->qdio.no_out_queues);
0902 }
0903 
0904 static inline u16 qeth_iqd_translate_txq(struct net_device *dev, u16 txq)
0905 {
0906     if (txq == QETH_IQD_MCAST_TXQ)
0907         return dev->num_tx_queues - 1;
0908     if (txq == dev->num_tx_queues - 1)
0909         return QETH_IQD_MCAST_TXQ;
0910     return txq;
0911 }
0912 
0913 static inline bool qeth_iqd_is_mcast_queue(struct qeth_card *card,
0914                        struct qeth_qdio_out_q *queue)
0915 {
0916     return qeth_iqd_translate_txq(card->dev, queue->queue_no) ==
0917            QETH_IQD_MCAST_TXQ;
0918 }
0919 
0920 static inline void qeth_scrub_qdio_buffer(struct qdio_buffer *buf,
0921                       unsigned int elements)
0922 {
0923     unsigned int i;
0924 
0925     for (i = 0; i < elements; i++)
0926         memset(&buf->element[i], 0, sizeof(struct qdio_buffer_element));
0927     buf->element[14].sflags = 0;
0928     buf->element[15].sflags = 0;
0929 }
0930 
0931 /**
0932  * qeth_get_elements_for_range() -  find number of SBALEs to cover range.
0933  * @start:              Start of the address range.
0934  * @end:                Address after the end of the range.
0935  *
0936  * Returns the number of pages, and thus QDIO buffer elements, needed to cover
0937  * the specified address range.
0938  */
0939 static inline int qeth_get_elements_for_range(addr_t start, addr_t end)
0940 {
0941     return PFN_UP(end) - PFN_DOWN(start);
0942 }
0943 
0944 static inline int qeth_get_ether_cast_type(struct sk_buff *skb)
0945 {
0946     u8 *addr = eth_hdr(skb)->h_dest;
0947 
0948     if (is_multicast_ether_addr(addr))
0949         return is_broadcast_ether_addr(addr) ? RTN_BROADCAST :
0950                                RTN_MULTICAST;
0951     return RTN_UNICAST;
0952 }
0953 
0954 static inline struct dst_entry *qeth_dst_check_rcu(struct sk_buff *skb,
0955                            __be16 proto)
0956 {
0957     struct dst_entry *dst = skb_dst(skb);
0958     struct rt6_info *rt;
0959 
0960     rt = (struct rt6_info *) dst;
0961     if (dst) {
0962         if (proto == htons(ETH_P_IPV6))
0963             dst = dst_check(dst, rt6_get_cookie(rt));
0964         else
0965             dst = dst_check(dst, 0);
0966     }
0967 
0968     return dst;
0969 }
0970 
0971 static inline __be32 qeth_next_hop_v4_rcu(struct sk_buff *skb,
0972                       struct dst_entry *dst)
0973 {
0974     struct rtable *rt = (struct rtable *) dst;
0975 
0976     return (rt) ? rt_nexthop(rt, ip_hdr(skb)->daddr) : ip_hdr(skb)->daddr;
0977 }
0978 
0979 static inline struct in6_addr *qeth_next_hop_v6_rcu(struct sk_buff *skb,
0980                             struct dst_entry *dst)
0981 {
0982     struct rt6_info *rt = (struct rt6_info *) dst;
0983 
0984     if (rt && !ipv6_addr_any(&rt->rt6i_gateway))
0985         return &rt->rt6i_gateway;
0986     else
0987         return &ipv6_hdr(skb)->daddr;
0988 }
0989 
0990 static inline void qeth_tx_csum(struct sk_buff *skb, u8 *flags, __be16 proto)
0991 {
0992     *flags |= QETH_HDR_EXT_CSUM_TRANSP_REQ;
0993     if ((proto == htons(ETH_P_IP) && ip_hdr(skb)->protocol == IPPROTO_UDP) ||
0994         (proto == htons(ETH_P_IPV6) && ipv6_hdr(skb)->nexthdr == IPPROTO_UDP))
0995         *flags |= QETH_HDR_EXT_UDP;
0996 }
0997 
0998 static inline void qeth_put_buffer_pool_entry(struct qeth_card *card,
0999         struct qeth_buffer_pool_entry *entry)
1000 {
1001     list_add_tail(&entry->list, &card->qdio.in_buf_pool.entry_list);
1002 }
1003 
1004 static inline int qeth_is_diagass_supported(struct qeth_card *card,
1005         enum qeth_diags_cmds cmd)
1006 {
1007     return card->info.diagass_support & (__u32)cmd;
1008 }
1009 
1010 int qeth_send_simple_setassparms_prot(struct qeth_card *card,
1011                       enum qeth_ipa_funcs ipa_func,
1012                       u16 cmd_code, u32 *data,
1013                       enum qeth_prot_versions prot);
1014 /* IPv4 variant */
1015 static inline int qeth_send_simple_setassparms(struct qeth_card *card,
1016                            enum qeth_ipa_funcs ipa_func,
1017                            u16 cmd_code, u32 *data)
1018 {
1019     return qeth_send_simple_setassparms_prot(card, ipa_func, cmd_code,
1020                          data, QETH_PROT_IPV4);
1021 }
1022 
1023 static inline int qeth_send_simple_setassparms_v6(struct qeth_card *card,
1024                           enum qeth_ipa_funcs ipa_func,
1025                           u16 cmd_code, u32 *data)
1026 {
1027     return qeth_send_simple_setassparms_prot(card, ipa_func, cmd_code,
1028                          data, QETH_PROT_IPV6);
1029 }
1030 
1031 extern const struct qeth_discipline qeth_l2_discipline;
1032 extern const struct qeth_discipline qeth_l3_discipline;
1033 extern const struct ethtool_ops qeth_ethtool_ops;
1034 extern const struct attribute_group *qeth_dev_groups[];
1035 
1036 const char *qeth_get_cardname_short(struct qeth_card *);
1037 int qeth_resize_buffer_pool(struct qeth_card *card, unsigned int count);
1038 int qeth_setup_discipline(struct qeth_card *card, enum qeth_discipline_id disc);
1039 void qeth_remove_discipline(struct qeth_card *card);
1040 
1041 /* exports for qeth discipline device drivers */
1042 extern struct qeth_dbf_info qeth_dbf[QETH_DBF_INFOS];
1043 
1044 struct net_device *qeth_clone_netdev(struct net_device *orig);
1045 void qeth_set_allowed_threads(struct qeth_card *card, unsigned long threads,
1046                   int clear_start_mask);
1047 int qeth_threads_running(struct qeth_card *, unsigned long);
1048 int qeth_set_offline(struct qeth_card *card, const struct qeth_discipline *disc,
1049              bool resetting);
1050 
1051 int qeth_send_ipa_cmd(struct qeth_card *, struct qeth_cmd_buffer *,
1052           int (*reply_cb)
1053           (struct qeth_card *, struct qeth_reply *, unsigned long),
1054           void *);
1055 struct qeth_cmd_buffer *qeth_ipa_alloc_cmd(struct qeth_card *card,
1056                        enum qeth_ipa_cmds cmd_code,
1057                        enum qeth_prot_versions prot,
1058                        unsigned int data_length);
1059 struct qeth_cmd_buffer *qeth_get_setassparms_cmd(struct qeth_card *card,
1060                          enum qeth_ipa_funcs ipa_func,
1061                          u16 cmd_code,
1062                          unsigned int data_length,
1063                          enum qeth_prot_versions prot);
1064 struct qeth_cmd_buffer *qeth_get_diag_cmd(struct qeth_card *card,
1065                       enum qeth_diags_cmds sub_cmd,
1066                       unsigned int data_length);
1067 
1068 int qeth_schedule_recovery(struct qeth_card *card);
1069 int qeth_poll(struct napi_struct *napi, int budget);
1070 void qeth_setadp_promisc_mode(struct qeth_card *card, bool enable);
1071 int qeth_setadpparms_change_macaddr(struct qeth_card *);
1072 void qeth_tx_timeout(struct net_device *, unsigned int txqueue);
1073 int qeth_query_switch_attributes(struct qeth_card *card,
1074                   struct qeth_switch_info *sw_info);
1075 int qeth_query_card_info(struct qeth_card *card,
1076              struct qeth_link_info *link_info);
1077 int qeth_setadpparms_set_access_ctrl(struct qeth_card *card,
1078                      enum qeth_ipa_isolation_modes mode);
1079 
1080 int qeth_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
1081 int qeth_siocdevprivate(struct net_device *dev, struct ifreq *rq,
1082             void __user *data, int cmd);
1083 __printf(3, 4)
1084 void qeth_dbf_longtext(debug_info_t *id, int level, char *text, ...);
1085 int qeth_configure_cq(struct qeth_card *, enum qeth_cq);
1086 int qeth_hw_trap(struct qeth_card *, enum qeth_diags_trap_action);
1087 int qeth_setassparms_cb(struct qeth_card *, struct qeth_reply *, unsigned long);
1088 int qeth_set_features(struct net_device *, netdev_features_t);
1089 void qeth_enable_hw_features(struct net_device *dev);
1090 netdev_features_t qeth_fix_features(struct net_device *, netdev_features_t);
1091 netdev_features_t qeth_features_check(struct sk_buff *skb,
1092                       struct net_device *dev,
1093                       netdev_features_t features);
1094 void qeth_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats);
1095 int qeth_set_real_num_tx_queues(struct qeth_card *card, unsigned int count);
1096 u16 qeth_iqd_select_queue(struct net_device *dev, struct sk_buff *skb,
1097               u8 cast_type, struct net_device *sb_dev);
1098 u16 qeth_osa_select_queue(struct net_device *dev, struct sk_buff *skb,
1099               struct net_device *sb_dev);
1100 int qeth_open(struct net_device *dev);
1101 int qeth_stop(struct net_device *dev);
1102 
1103 int qeth_vm_request_mac(struct qeth_card *card);
1104 int qeth_xmit(struct qeth_card *card, struct sk_buff *skb,
1105           struct qeth_qdio_out_q *queue, __be16 proto,
1106           void (*fill_header)(struct qeth_qdio_out_q *queue,
1107                   struct qeth_hdr *hdr, struct sk_buff *skb,
1108                   __be16 proto, unsigned int data_len));
1109 
1110 #endif /* __QETH_CORE_H__ */