1 /* SPDX-License-Identifier: GPL-2.0 */
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>
10 #ifndef __QETH_CORE_H__
11 #define __QETH_CORE_H__
13 #include <linux/completion.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>
24 #include <linux/refcount.h>
25 #include <linux/timer.h>
26 #include <linux/wait.h>
27 #include <linux/workqueue.h>
30 #include <net/ip6_fib.h>
32 #include <net/if_inet6.h>
33 #include <net/addrconf.h>
34 #include <net/sch_generic.h>
37 #include <asm/debug.h>
39 #include <asm/ccwdev.h>
40 #include <asm/ccwgroup.h>
41 #include <asm/sysinfo.h>
43 #include <uapi/linux/if_link.h>
45 #include "qeth_core_mpc.h"
48 * Debug Facility stuff
54 QETH_DBF_INFOS
/* must be last element */
57 struct qeth_dbf_info
{
58 char name
[DEBUG_MAX_NAME_LEN
];
63 struct debug_view
*view
;
67 #define QETH_DBF_CTRL_LEN 256U
69 #define QETH_DBF_TEXT(name, level, text) \
70 debug_text_event(qeth_dbf[QETH_DBF_##name].id, level, text)
72 #define QETH_DBF_HEX(name, level, addr, len) \
73 debug_event(qeth_dbf[QETH_DBF_##name].id, level, (void *)(addr), len)
75 #define QETH_DBF_MESSAGE(level, text...) \
76 debug_sprintf_event(qeth_dbf[QETH_DBF_MSG].id, level, text)
78 #define QETH_DBF_TEXT_(name, level, text...) \
79 qeth_dbf_longtext(qeth_dbf[QETH_DBF_##name].id, level, text)
81 #define QETH_CARD_TEXT(card, level, text) \
82 debug_text_event(card->debug, level, text)
84 #define QETH_CARD_HEX(card, level, addr, len) \
85 debug_event(card->debug, level, (void *)(addr), len)
87 #define QETH_CARD_MESSAGE(card, text...) \
88 debug_sprintf_event(card->debug, level, text)
90 #define QETH_CARD_TEXT_(card, level, text...) \
91 qeth_dbf_longtext(card->debug, level, text)
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
98 static inline u32
qeth_get_device_id(struct ccw_device
*cdev
)
100 struct ccw_dev_id dev_id
;
103 ccw_device_get_id(cdev
, &dev_id
);
105 id
|= (u32
) (dev_id
.ssid
<< 16);
111 * Common IO related definitions
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)))
124 struct qeth_routing_info
{
125 enum qeth_routing_types type
;
129 struct qeth_ipa_info
{
130 __u32 supported_funcs
;
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,
141 enum qeth_sbp_states
{
142 QETH_SBP_STATE_INACTIVE
= 0,
143 QETH_SBP_STATE_STANDBY
= 1,
144 QETH_SBP_STATE_ACTIVE
= 2,
147 #define QETH_SBP_HOST_NOTIFICATION 1
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;
157 struct qeth_vnicc_info
{
158 /* supported/currently configured VNICCs; updated in IPA exchanges */
161 /* supported commands: bitmasks which VNICCs support respective cmd */
163 u32 getset_timeout_sup
;
164 /* timeout value for the learning characteristic */
165 u32 learning_timeout
;
166 /* characteristics wanted/configured by user */
168 /* has user explicitly enabled rx_bcast while online? */
169 bool rx_bcast_enabled
;
172 static inline int qeth_is_adp_supported(struct qeth_ipa_info
*ipa
,
173 enum qeth_ipa_setadp_cmd func
)
175 return (ipa
->supported_funcs
& func
);
178 static inline int qeth_is_ipa_supported(struct qeth_ipa_info
*ipa
,
179 enum qeth_ipa_funcs func
)
181 return (ipa
->supported_funcs
& func
);
184 static inline int qeth_is_ipa_enabled(struct qeth_ipa_info
*ipa
,
185 enum qeth_ipa_funcs func
)
187 return (ipa
->supported_funcs
& ipa
->enabled_funcs
& func
);
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))
207 #define QETH_IDX_FUNC_LEVEL_OSD 0x0101
208 #define QETH_IDX_FUNC_LEVEL_IQD 0x4108
210 #define QETH_BUFSIZE 4096
211 #define CCW_CMD_WRITE 0x01
212 #define CCW_CMD_READ 0x02
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
222 /*IPv6 address autoconfiguration stuff*/
223 #define UNIQUE_ID_IF_CREATE_ADDR_FAILED 0xfffe
224 #define UNIQUE_ID_NOT_BY_CARD 0x10000
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)
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
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
259 #define QETH_LOW_WATERMARK_PACK 2
260 #define QETH_HIGH_WATERMARK_PACK 5
261 #define QETH_WATERMARK_PACK_FUZZ 1
263 /* large receive scatter gather copy break */
264 #define QETH_RX_SG_CB (PAGE_SIZE >> 1)
265 #define QETH_RX_PULL_LEN 256
267 struct qeth_hdr_layer3
{
270 __u16 inbound_checksum
; /*TSO:__u16 seqno */
271 __u32 token
; /*TSO: __u32 reserved */
279 struct in6_addr ipv6_addr
;
295 struct qeth_hdr_layer2
{
305 } __attribute__ ((packed
));
307 struct qeth_hdr_osn
{
316 } __attribute__ ((packed
));
320 struct qeth_hdr_layer2 l2
;
321 struct qeth_hdr_layer3 l3
;
322 struct qeth_hdr_osn osn
;
324 } __attribute__ ((packed
));
326 /*TCP Segmentation Offload header*/
327 struct qeth_hdr_ext_tso
{
338 } __attribute__ ((packed
));
340 struct qeth_hdr_tso
{
341 struct qeth_hdr hdr
; /*hdr->hdr.l3.xxx*/
342 struct qeth_hdr_ext_tso ext
;
343 } __attribute__ ((packed
));
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,
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,
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 QETH_HEADER_MASK_INVAL
= 0x80,
373 /* flags for qeth_hdr.ext_flags */
374 #define QETH_HDR_EXT_VLAN_FRAME 0x01
375 #define QETH_HDR_EXT_TOKEN_ID 0x02
376 #define QETH_HDR_EXT_INCLUDE_VLAN_TAG 0x04
377 #define QETH_HDR_EXT_SRC_MAC_ADDR 0x08
378 #define QETH_HDR_EXT_CSUM_HDR_REQ 0x10
379 #define QETH_HDR_EXT_CSUM_TRANSP_REQ 0x20
380 #define QETH_HDR_EXT_UDP 0x40 /*bit off for TCP*/
382 static inline bool qeth_l2_same_vlan(struct qeth_hdr_layer2
*h1
,
383 struct qeth_hdr_layer2
*h2
)
385 return !((h1
->flags
[2] ^ h2
->flags
[2]) & QETH_LAYER2_FLAG_VLAN
) &&
386 h1
->vlan_id
== h2
->vlan_id
;
389 static inline bool qeth_l3_iqd_same_vlan(struct qeth_hdr_layer3
*h1
,
390 struct qeth_hdr_layer3
*h2
)
392 return !((h1
->ext_flags
^ h2
->ext_flags
) & QETH_HDR_EXT_VLAN_FRAME
) &&
393 h1
->vlan_id
== h2
->vlan_id
;
396 static inline bool qeth_l3_same_next_hop(struct qeth_hdr_layer3
*h1
,
397 struct qeth_hdr_layer3
*h2
)
399 return !((h1
->flags
^ h2
->flags
) & QETH_HDR_IPV6
) &&
400 ipv6_addr_equal(&h1
->next_hop
.ipv6_addr
,
401 &h2
->next_hop
.ipv6_addr
);
404 enum qeth_qdio_info_states
{
405 QETH_QDIO_UNINITIALIZED
,
407 QETH_QDIO_ESTABLISHED
,
411 struct qeth_buffer_pool_entry
{
412 struct list_head list
;
413 struct list_head init_list
;
414 void *elements
[QDIO_MAX_ELEMENTS_PER_BUFFER
];
417 struct qeth_qdio_buffer_pool
{
418 struct list_head entry_list
;
422 struct qeth_qdio_buffer
{
423 struct qdio_buffer
*buffer
;
424 /* the buffer pool entry currently associated to this buffer */
425 struct qeth_buffer_pool_entry
*pool_entry
;
426 struct sk_buff
*rx_skb
;
430 struct qdio_buffer
*qdio_bufs
[QDIO_MAX_BUFFERS_PER_Q
];
431 struct qeth_qdio_buffer bufs
[QDIO_MAX_BUFFERS_PER_Q
];
432 int next_buf_to_init
;
435 enum qeth_qdio_out_buffer_state
{
436 /* Owned by driver, in order to be filled. */
438 /* Filled by driver; owned by hardware in order to be sent. */
439 QETH_QDIO_BUF_PRIMED
,
440 /* Identified to be pending in TPQ. */
441 QETH_QDIO_BUF_PENDING
,
442 /* Found in completion queue. */
444 /* Handled via transfer pending / completion queue. */
445 QETH_QDIO_BUF_HANDLED_DELAYED
,
448 struct qeth_qdio_out_buffer
{
449 struct qdio_buffer
*buffer
;
451 int next_element_to_fill
;
453 struct sk_buff_head skb_list
;
454 int is_header
[QDIO_MAX_ELEMENTS_PER_BUFFER
];
456 struct qeth_qdio_out_q
*q
;
457 struct qeth_qdio_out_buffer
*next_pending
;
462 enum qeth_out_q_states
{
465 QETH_OUT_Q_LOCKED_FLUSH
,
468 #define QETH_CARD_STAT_ADD(_c, _stat, _val) ((_c)->stats._stat += (_val))
469 #define QETH_CARD_STAT_INC(_c, _stat) QETH_CARD_STAT_ADD(_c, _stat, 1)
471 #define QETH_TXQ_STAT_ADD(_q, _stat, _val) ((_q)->stats._stat += (_val))
472 #define QETH_TXQ_STAT_INC(_q, _stat) QETH_TXQ_STAT_ADD(_q, _stat, 1)
474 struct qeth_card_stats
{
479 u64 rx_sg_alloc_page
;
481 u64 rx_dropped_nomem
;
482 u64 rx_dropped_notsupp
;
485 /* rtnl_link_stats64 */
489 u64 rx_length_errors
;
494 struct qeth_out_q_stats
{
503 u64 skbs_linearized_fail
;
505 u64 packing_mode_switch
;
507 u64 completion_yield
;
508 u64 completion_timer
;
510 /* rtnl_link_stats64 */
517 #define QETH_TX_TIMER_USECS 500
519 struct qeth_qdio_out_q
{
520 struct qdio_buffer
*qdio_bufs
[QDIO_MAX_BUFFERS_PER_Q
];
521 struct qeth_qdio_out_buffer
*bufs
[QDIO_MAX_BUFFERS_PER_Q
];
522 struct qdio_outbuf_state
*bufstates
; /* convenience pointer */
523 struct qeth_out_q_stats stats
;
528 struct qeth_card
*card
;
531 * number of buffers that are currently filled (PRIMED)
532 * -> these buffers are hardware-owned
534 atomic_t used_buffers
;
535 /* indicates whether PCI flag must be set (or if one is outstanding) */
536 atomic_t set_pci_flags_count
;
537 struct napi_struct napi
;
538 struct timer_list timer
;
539 struct qeth_hdr
*prev_hdr
;
545 #define qeth_for_each_output_queue(card, q, i) \
546 for (i = 0; i < card->qdio.no_out_queues && \
547 (q = card->qdio.out_qs[i]); i++)
549 #define qeth_napi_to_out_queue(n) container_of(n, struct qeth_qdio_out_q, napi)
551 static inline void qeth_tx_arm_timer(struct qeth_qdio_out_q
*queue
)
553 if (timer_pending(&queue
->timer
))
555 mod_timer(&queue
->timer
, usecs_to_jiffies(QETH_TX_TIMER_USECS
) +
559 static inline bool qeth_out_queue_is_full(struct qeth_qdio_out_q
*queue
)
561 return atomic_read(&queue
->used_buffers
) >= QDIO_MAX_BUFFERS_PER_Q
;
564 static inline bool qeth_out_queue_is_empty(struct qeth_qdio_out_q
*queue
)
566 return atomic_read(&queue
->used_buffers
) == 0;
569 struct qeth_qdio_info
{
573 struct qeth_qdio_q
*in_q
;
574 struct qeth_qdio_q
*c_q
;
575 struct qeth_qdio_buffer_pool in_buf_pool
;
576 struct qeth_qdio_buffer_pool init_pool
;
581 struct qeth_qdio_out_q
*out_qs
[QETH_MAX_QUEUES
];
582 struct qdio_outbuf_state
*out_bufstates
;
584 /* priority queueing */
585 int do_prio_queueing
;
586 int default_out_queue
;
590 * channel state machine
592 enum qeth_channel_states
{
601 enum qeth_card_states
{
603 CARD_STATE_HARDSETUP
,
604 CARD_STATE_SOFTSETUP
,
610 enum qeth_prot_versions
{
611 QETH_PROT_NONE
= 0x0000,
612 QETH_PROT_IPV4
= 0x0004,
613 QETH_PROT_IPV6
= 0x0006,
617 QETH_CQ_DISABLED
= 0,
619 QETH_CQ_NOTAVAILABLE
= 2,
626 struct list_head entries
;
629 struct qeth_channel
{
630 struct ccw_device
*ccwdev
;
631 struct qeth_cmd_buffer
*active_cmd
;
632 enum qeth_channel_states state
;
633 atomic_t irq_pending
;
637 int (*callback
)(struct qeth_card
*card
, struct qeth_reply
*reply
,
642 struct qeth_cmd_buffer
{
643 struct list_head list
;
644 struct completion done
;
647 refcount_t ref_count
;
648 struct qeth_channel
*channel
;
649 struct qeth_reply reply
;
652 void (*finalize
)(struct qeth_card
*card
, struct qeth_cmd_buffer
*iob
);
653 void (*callback
)(struct qeth_card
*card
, struct qeth_cmd_buffer
*iob
,
654 unsigned int data_length
);
658 static inline void qeth_get_cmd(struct qeth_cmd_buffer
*iob
)
660 refcount_inc(&iob
->ref_count
);
663 static inline struct qeth_ipa_cmd
*__ipa_cmd(struct qeth_cmd_buffer
*iob
)
665 return (struct qeth_ipa_cmd
*)(iob
->data
+ IPA_PDU_HEADER_SIZE
);
668 static inline struct ccw1
*__ccw_from_cmd(struct qeth_cmd_buffer
*iob
)
670 return (struct ccw1
*)(iob
->data
+ ALIGN(iob
->length
, 8));
673 static inline bool qeth_trylock_channel(struct qeth_channel
*channel
)
675 return atomic_cmpxchg(&channel
->irq_pending
, 0, 1) == 0;
679 * OSA card related definitions
686 __u32 cm_connection_w
;
687 __u32 cm_connection_r
;
690 __u32 ulp_connection_w
;
691 __u32 ulp_connection_r
;
701 struct qeth_card_blkt
{
704 int inter_packet_jumbo
;
707 #define QETH_BROADCAST_WITH_ECHO 0x01
708 #define QETH_BROADCAST_WITHOUT_ECHO 0x02
709 #define QETH_LAYER2_MAC_REGISTERED 0x02
710 struct qeth_card_info
{
711 unsigned short unit_addr2
;
715 char mcl_level
[QETH_MCL_LENGTH
+ 1];
716 u8 open_when_online
:1;
721 enum qeth_card_types type
;
722 enum qeth_link_types link_type
;
723 int broadcast_capable
;
726 struct qeth_card_blkt blkt
;
727 __u32 diagass_support
;
731 enum qeth_discipline_id
{
732 QETH_DISCIPLINE_UNDETERMINED
= -1,
733 QETH_DISCIPLINE_LAYER3
= 0,
734 QETH_DISCIPLINE_LAYER2
= 1,
737 struct qeth_card_options
{
738 struct qeth_routing_info route4
;
739 struct qeth_ipa_info ipa4
;
740 struct qeth_ipa_info adp
; /*Adapter parameters*/
741 struct qeth_routing_info route6
;
742 struct qeth_ipa_info ipa6
;
743 struct qeth_sbp_info sbp
; /* SETBRIDGEPORT options */
744 struct qeth_vnicc_info vnicc
; /* VNICC options */
746 enum qeth_discipline_id layer
;
748 enum qeth_ipa_isolation_modes isolation
;
749 enum qeth_ipa_isolation_modes prev_isolation
;
755 #define IS_LAYER2(card) ((card)->options.layer == QETH_DISCIPLINE_LAYER2)
756 #define IS_LAYER3(card) ((card)->options.layer == QETH_DISCIPLINE_LAYER3)
759 * thread bits for qeth_card thread masks
762 QETH_RECOVER_THREAD
= 1,
765 struct qeth_osn_info
{
766 int (*assist_cb
)(struct net_device
*dev
, void *data
);
767 int (*data_cb
)(struct sk_buff
*skb
);
770 struct qeth_discipline
{
771 const struct device_type
*devtype
;
772 int (*process_rx_buffer
)(struct qeth_card
*card
, int budget
, int *done
);
773 int (*recover
)(void *ptr
);
774 int (*setup
) (struct ccwgroup_device
*);
775 void (*remove
) (struct ccwgroup_device
*);
776 int (*set_online
) (struct ccwgroup_device
*);
777 int (*set_offline
) (struct ccwgroup_device
*);
778 int (*do_ioctl
)(struct net_device
*dev
, struct ifreq
*rq
, int cmd
);
779 int (*control_event_handler
)(struct qeth_card
*card
,
780 struct qeth_ipa_cmd
*cmd
);
783 enum qeth_addr_disposition
{
784 QETH_DISP_ADDR_DELETE
= 0,
785 QETH_DISP_ADDR_DO_NOTHING
= 1,
786 QETH_DISP_ADDR_ADD
= 2,
792 struct qdio_buffer_element
*b_element
;
797 struct carrier_info
{
803 struct qeth_switch_info
{
808 #define QETH_NAPI_WEIGHT NAPI_POLL_WEIGHT
811 enum qeth_card_states state
;
813 struct ccwgroup_device
*gdev
;
814 struct qeth_cmd_buffer
*read_cmd
;
815 struct qeth_channel read
;
816 struct qeth_channel write
;
817 struct qeth_channel data
;
819 struct net_device
*dev
;
820 struct qeth_card_stats stats
;
821 struct qeth_card_info info
;
822 struct qeth_token token
;
823 struct qeth_seqno seqno
;
824 struct qeth_card_options options
;
826 struct workqueue_struct
*event_wq
;
827 struct workqueue_struct
*cmd_wq
;
828 wait_queue_head_t wait_q
;
829 DECLARE_HASHTABLE(mac_htable
, 4);
830 DECLARE_HASHTABLE(ip_htable
, 4);
831 struct mutex ip_lock
;
832 DECLARE_HASHTABLE(ip_mc_htable
, 4);
833 struct work_struct rx_mode_work
;
834 struct work_struct kernel_thread_starter
;
835 spinlock_t thread_mask_lock
;
836 unsigned long thread_start_mask
;
837 unsigned long thread_allowed_mask
;
838 unsigned long thread_running_mask
;
839 struct qeth_ipato ipato
;
840 struct list_head cmd_waiter_list
;
841 /* QDIO buffer handling */
842 struct qeth_qdio_info qdio
;
843 int read_or_write_problem
;
844 struct qeth_osn_info osn_info
;
845 struct qeth_discipline
*discipline
;
846 atomic_t force_alloc_skb
;
847 struct service_level qeth_service_level
;
848 struct qdio_ssqd_desc ssqd
;
850 struct mutex sbp_lock
;
851 struct mutex conf_mutex
;
852 struct mutex discipline_mutex
;
853 struct napi_struct napi
;
855 struct delayed_work buffer_reclaim_work
;
857 struct work_struct close_dev_work
;
860 static inline bool qeth_card_hw_is_reachable(struct qeth_card
*card
)
862 return card
->state
== CARD_STATE_SOFTSETUP
;
865 struct qeth_trap_id
{
873 /*some helper functions*/
874 #define QETH_CARD_IFNAME(card) (((card)->dev)? (card)->dev->name : "")
876 static inline bool qeth_netdev_is_registered(struct net_device
*dev
)
878 return dev
->netdev_ops
!= NULL
;
881 static inline u16
qeth_iqd_translate_txq(struct net_device
*dev
, u16 txq
)
883 if (txq
== QETH_IQD_MCAST_TXQ
)
884 return dev
->num_tx_queues
- 1;
885 if (txq
== dev
->num_tx_queues
- 1)
886 return QETH_IQD_MCAST_TXQ
;
890 static inline bool qeth_iqd_is_mcast_queue(struct qeth_card
*card
,
891 struct qeth_qdio_out_q
*queue
)
893 return qeth_iqd_translate_txq(card
->dev
, queue
->queue_no
) ==
897 static inline void qeth_scrub_qdio_buffer(struct qdio_buffer
*buf
,
898 unsigned int elements
)
902 for (i
= 0; i
< elements
; i
++)
903 memset(&buf
->element
[i
], 0, sizeof(struct qdio_buffer_element
));
904 buf
->element
[14].sflags
= 0;
905 buf
->element
[15].sflags
= 0;
909 * qeth_get_elements_for_range() - find number of SBALEs to cover range.
910 * @start: Start of the address range.
911 * @end: Address after the end of the range.
913 * Returns the number of pages, and thus QDIO buffer elements, needed to cover
914 * the specified address range.
916 static inline int qeth_get_elements_for_range(addr_t start
, addr_t end
)
918 return PFN_UP(end
) - PFN_DOWN(start
);
921 static inline int qeth_get_ip_version(struct sk_buff
*skb
)
923 struct vlan_ethhdr
*veth
= vlan_eth_hdr(skb
);
924 __be16 prot
= veth
->h_vlan_proto
;
926 if (prot
== htons(ETH_P_8021Q
))
927 prot
= veth
->h_vlan_encapsulated_proto
;
930 case htons(ETH_P_IPV6
):
932 case htons(ETH_P_IP
):
939 static inline int qeth_get_ether_cast_type(struct sk_buff
*skb
)
941 u8
*addr
= eth_hdr(skb
)->h_dest
;
943 if (is_multicast_ether_addr(addr
))
944 return is_broadcast_ether_addr(addr
) ? RTN_BROADCAST
:
949 static inline struct dst_entry
*qeth_dst_check_rcu(struct sk_buff
*skb
, int ipv
)
951 struct dst_entry
*dst
= skb_dst(skb
);
954 rt
= (struct rt6_info
*) dst
;
956 dst
= dst_check(dst
, (ipv
== 6) ? rt6_get_cookie(rt
) : 0);
960 static inline void qeth_rx_csum(struct qeth_card
*card
, struct sk_buff
*skb
,
963 if ((card
->dev
->features
& NETIF_F_RXCSUM
) &&
964 (flags
& QETH_HDR_EXT_CSUM_TRANSP_REQ
)) {
965 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
966 QETH_CARD_STAT_INC(card
, rx_skb_csum
);
968 skb
->ip_summed
= CHECKSUM_NONE
;
972 static inline void qeth_tx_csum(struct sk_buff
*skb
, u8
*flags
, int ipv
)
974 *flags
|= QETH_HDR_EXT_CSUM_TRANSP_REQ
;
975 if ((ipv
== 4 && ip_hdr(skb
)->protocol
== IPPROTO_UDP
) ||
976 (ipv
== 6 && ipv6_hdr(skb
)->nexthdr
== IPPROTO_UDP
))
977 *flags
|= QETH_HDR_EXT_UDP
;
980 static inline void qeth_put_buffer_pool_entry(struct qeth_card
*card
,
981 struct qeth_buffer_pool_entry
*entry
)
983 list_add_tail(&entry
->list
, &card
->qdio
.in_buf_pool
.entry_list
);
986 static inline int qeth_is_diagass_supported(struct qeth_card
*card
,
987 enum qeth_diags_cmds cmd
)
989 return card
->info
.diagass_support
& (__u32
)cmd
;
992 int qeth_send_simple_setassparms_prot(struct qeth_card
*card
,
993 enum qeth_ipa_funcs ipa_func
,
994 u16 cmd_code
, u32
*data
,
995 enum qeth_prot_versions prot
);
997 static inline int qeth_send_simple_setassparms(struct qeth_card
*card
,
998 enum qeth_ipa_funcs ipa_func
,
999 u16 cmd_code
, u32
*data
)
1001 return qeth_send_simple_setassparms_prot(card
, ipa_func
, cmd_code
,
1002 data
, QETH_PROT_IPV4
);
1005 static inline int qeth_send_simple_setassparms_v6(struct qeth_card
*card
,
1006 enum qeth_ipa_funcs ipa_func
,
1007 u16 cmd_code
, u32
*data
)
1009 return qeth_send_simple_setassparms_prot(card
, ipa_func
, cmd_code
,
1010 data
, QETH_PROT_IPV6
);
1013 int qeth_get_priority_queue(struct qeth_card
*card
, struct sk_buff
*skb
);
1015 extern struct qeth_discipline qeth_l2_discipline
;
1016 extern struct qeth_discipline qeth_l3_discipline
;
1017 extern const struct ethtool_ops qeth_ethtool_ops
;
1018 extern const struct ethtool_ops qeth_osn_ethtool_ops
;
1019 extern const struct attribute_group
*qeth_generic_attr_groups
[];
1020 extern const struct attribute_group
*qeth_osn_attr_groups
[];
1021 extern const struct attribute_group qeth_device_attr_group
;
1022 extern const struct attribute_group qeth_device_blkt_group
;
1023 extern const struct device_type qeth_generic_devtype
;
1025 const char *qeth_get_cardname_short(struct qeth_card
*);
1026 int qeth_realloc_buffer_pool(struct qeth_card
*, int);
1027 int qeth_core_load_discipline(struct qeth_card
*, enum qeth_discipline_id
);
1028 void qeth_core_free_discipline(struct qeth_card
*);
1030 /* exports for qeth discipline device drivers */
1031 extern struct kmem_cache
*qeth_core_header_cache
;
1032 extern struct qeth_dbf_info qeth_dbf
[QETH_DBF_INFOS
];
1034 struct net_device
*qeth_clone_netdev(struct net_device
*orig
);
1035 struct qeth_card
*qeth_get_card_by_busid(char *bus_id
);
1036 void qeth_set_allowed_threads(struct qeth_card
*, unsigned long , int);
1037 int qeth_threads_running(struct qeth_card
*, unsigned long);
1038 int qeth_do_run_thread(struct qeth_card
*, unsigned long);
1039 void qeth_clear_thread_start_bit(struct qeth_card
*, unsigned long);
1040 void qeth_clear_thread_running_bit(struct qeth_card
*, unsigned long);
1041 int qeth_core_hardsetup_card(struct qeth_card
*card
, bool *carrier_ok
);
1042 int qeth_stop_channel(struct qeth_channel
*channel
);
1044 void qeth_print_status_message(struct qeth_card
*);
1045 int qeth_init_qdio_queues(struct qeth_card
*);
1046 int qeth_send_ipa_cmd(struct qeth_card
*, struct qeth_cmd_buffer
*,
1048 (struct qeth_card
*, struct qeth_reply
*, unsigned long),
1050 struct qeth_cmd_buffer
*qeth_ipa_alloc_cmd(struct qeth_card
*card
,
1051 enum qeth_ipa_cmds cmd_code
,
1052 enum qeth_prot_versions prot
,
1053 unsigned int data_length
);
1054 struct qeth_cmd_buffer
*qeth_alloc_cmd(struct qeth_channel
*channel
,
1055 unsigned int length
, unsigned int ccws
,
1057 struct qeth_cmd_buffer
*qeth_get_setassparms_cmd(struct qeth_card
*card
,
1058 enum qeth_ipa_funcs ipa_func
,
1060 unsigned int data_length
,
1061 enum qeth_prot_versions prot
);
1062 struct qeth_cmd_buffer
*qeth_get_diag_cmd(struct qeth_card
*card
,
1063 enum qeth_diags_cmds sub_cmd
,
1064 unsigned int data_length
);
1065 void qeth_notify_cmd(struct qeth_cmd_buffer
*iob
, int reason
);
1066 void qeth_put_cmd(struct qeth_cmd_buffer
*iob
);
1068 struct sk_buff
*qeth_core_get_next_skb(struct qeth_card
*,
1069 struct qeth_qdio_buffer
*, struct qdio_buffer_element
**, int *,
1070 struct qeth_hdr
**);
1071 void qeth_schedule_recovery(struct qeth_card
*);
1072 int qeth_poll(struct napi_struct
*napi
, int budget
);
1073 void qeth_clear_ipacmd_list(struct qeth_card
*);
1074 int qeth_qdio_clear_card(struct qeth_card
*, int);
1075 void qeth_clear_working_pool_list(struct qeth_card
*);
1076 void qeth_drain_output_queues(struct qeth_card
*card
);
1077 void qeth_setadp_promisc_mode(struct qeth_card
*card
, bool enable
);
1078 int qeth_setadpparms_change_macaddr(struct qeth_card
*);
1079 void qeth_tx_timeout(struct net_device
*);
1080 void qeth_prepare_ipa_cmd(struct qeth_card
*card
, struct qeth_cmd_buffer
*iob
,
1082 int qeth_query_switch_attributes(struct qeth_card
*card
,
1083 struct qeth_switch_info
*sw_info
);
1084 int qeth_query_card_info(struct qeth_card
*card
,
1085 struct carrier_info
*carrier_info
);
1086 unsigned int qeth_count_elements(struct sk_buff
*skb
, unsigned int data_offset
);
1087 int qeth_do_send_packet(struct qeth_card
*card
, struct qeth_qdio_out_q
*queue
,
1088 struct sk_buff
*skb
, struct qeth_hdr
*hdr
,
1089 unsigned int offset
, unsigned int hd_len
,
1090 int elements_needed
);
1091 int qeth_do_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
);
1092 void qeth_dbf_longtext(debug_info_t
*id
, int level
, char *text
, ...);
1093 int qeth_set_access_ctrl_online(struct qeth_card
*card
, int fallback
);
1094 int qeth_configure_cq(struct qeth_card
*, enum qeth_cq
);
1095 int qeth_hw_trap(struct qeth_card
*, enum qeth_diags_trap_action
);
1096 void qeth_trace_features(struct qeth_card
*);
1097 int qeth_setassparms_cb(struct qeth_card
*, struct qeth_reply
*, unsigned long);
1098 int qeth_set_features(struct net_device
*, netdev_features_t
);
1099 void qeth_enable_hw_features(struct net_device
*dev
);
1100 netdev_features_t
qeth_fix_features(struct net_device
*, netdev_features_t
);
1101 netdev_features_t
qeth_features_check(struct sk_buff
*skb
,
1102 struct net_device
*dev
,
1103 netdev_features_t features
);
1104 void qeth_get_stats64(struct net_device
*dev
, struct rtnl_link_stats64
*stats
);
1105 u16
qeth_iqd_select_queue(struct net_device
*dev
, struct sk_buff
*skb
,
1106 u8 cast_type
, struct net_device
*sb_dev
);
1107 int qeth_open(struct net_device
*dev
);
1108 int qeth_stop(struct net_device
*dev
);
1110 int qeth_vm_request_mac(struct qeth_card
*card
);
1111 int qeth_xmit(struct qeth_card
*card
, struct sk_buff
*skb
,
1112 struct qeth_qdio_out_q
*queue
, int ipv
,
1113 void (*fill_header
)(struct qeth_qdio_out_q
*queue
,
1114 struct qeth_hdr
*hdr
, struct sk_buff
*skb
,
1115 int ipv
, unsigned int data_len
));
1117 /* exports for OSN */
1118 int qeth_osn_assist(struct net_device
*, void *, int);
1119 int qeth_osn_register(unsigned char *read_dev_no
, struct net_device
**,
1120 int (*assist_cb
)(struct net_device
*, void *),
1121 int (*data_cb
)(struct sk_buff
*));
1122 void qeth_osn_deregister(struct net_device
*);
1124 #endif /* __QETH_CORE_H__ */