1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright IBM Corp. 2007, 2009
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 #define KMSG_COMPONENT "qeth"
11 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13 #include <linux/compat.h>
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/string.h>
17 #include <linux/errno.h>
18 #include <linux/kernel.h>
20 #include <linux/tcp.h>
21 #include <linux/mii.h>
22 #include <linux/kthread.h>
23 #include <linux/slab.h>
24 #include <linux/if_vlan.h>
25 #include <linux/netdevice.h>
26 #include <linux/netdev_features.h>
27 #include <linux/skbuff.h>
29 #include <net/iucv/af_iucv.h>
30 #include <net/dsfield.h>
32 #include <asm/ebcdic.h>
33 #include <asm/chpid.h>
35 #include <asm/sysinfo.h>
38 #include <asm/ccwdev.h>
39 #include <asm/cpcmd.h>
41 #include "qeth_core.h"
43 struct qeth_dbf_info qeth_dbf
[QETH_DBF_INFOS
] = {
44 /* define dbf - Name, Pages, Areas, Maxlen, Level, View, Handle */
46 [QETH_DBF_SETUP
] = {"qeth_setup",
47 8, 1, 8, 5, &debug_hex_ascii_view
, NULL
},
48 [QETH_DBF_MSG
] = {"qeth_msg", 8, 1, 11 * sizeof(long), 3,
49 &debug_sprintf_view
, NULL
},
50 [QETH_DBF_CTRL
] = {"qeth_control",
51 8, 1, QETH_DBF_CTRL_LEN
, 5, &debug_hex_ascii_view
, NULL
},
53 EXPORT_SYMBOL_GPL(qeth_dbf
);
55 struct qeth_card_list_struct qeth_core_card_list
;
56 EXPORT_SYMBOL_GPL(qeth_core_card_list
);
57 struct kmem_cache
*qeth_core_header_cache
;
58 EXPORT_SYMBOL_GPL(qeth_core_header_cache
);
59 static struct kmem_cache
*qeth_qdio_outbuf_cache
;
61 static struct device
*qeth_core_root_dev
;
62 static struct lock_class_key qdio_out_skb_queue_key
;
63 static struct mutex qeth_mod_mutex
;
65 static void qeth_send_control_data_cb(struct qeth_channel
*,
66 struct qeth_cmd_buffer
*);
67 static struct qeth_cmd_buffer
*qeth_get_buffer(struct qeth_channel
*);
68 static void qeth_setup_ccw(struct qeth_channel
*, unsigned char *, __u32
);
69 static void qeth_free_buffer_pool(struct qeth_card
*);
70 static int qeth_qdio_establish(struct qeth_card
*);
71 static void qeth_free_qdio_buffers(struct qeth_card
*);
72 static void qeth_notify_skbs(struct qeth_qdio_out_q
*queue
,
73 struct qeth_qdio_out_buffer
*buf
,
74 enum iucv_tx_notify notification
);
75 static void qeth_release_skbs(struct qeth_qdio_out_buffer
*buf
);
76 static int qeth_init_qdio_out_buf(struct qeth_qdio_out_q
*, int);
78 struct workqueue_struct
*qeth_wq
;
79 EXPORT_SYMBOL_GPL(qeth_wq
);
81 int qeth_card_hw_is_reachable(struct qeth_card
*card
)
83 return (card
->state
== CARD_STATE_SOFTSETUP
) ||
84 (card
->state
== CARD_STATE_UP
);
86 EXPORT_SYMBOL_GPL(qeth_card_hw_is_reachable
);
88 static void qeth_close_dev_handler(struct work_struct
*work
)
90 struct qeth_card
*card
;
92 card
= container_of(work
, struct qeth_card
, close_dev_work
);
93 QETH_CARD_TEXT(card
, 2, "cldevhdl");
97 ccwgroup_set_offline(card
->gdev
);
100 void qeth_close_dev(struct qeth_card
*card
)
102 QETH_CARD_TEXT(card
, 2, "cldevsubm");
103 queue_work(qeth_wq
, &card
->close_dev_work
);
105 EXPORT_SYMBOL_GPL(qeth_close_dev
);
107 static const char *qeth_get_cardname(struct qeth_card
*card
)
109 if (card
->info
.guestlan
) {
110 switch (card
->info
.type
) {
111 case QETH_CARD_TYPE_OSD
:
112 return " Virtual NIC QDIO";
113 case QETH_CARD_TYPE_IQD
:
114 return " Virtual NIC Hiper";
115 case QETH_CARD_TYPE_OSM
:
116 return " Virtual NIC QDIO - OSM";
117 case QETH_CARD_TYPE_OSX
:
118 return " Virtual NIC QDIO - OSX";
123 switch (card
->info
.type
) {
124 case QETH_CARD_TYPE_OSD
:
125 return " OSD Express";
126 case QETH_CARD_TYPE_IQD
:
127 return " HiperSockets";
128 case QETH_CARD_TYPE_OSN
:
130 case QETH_CARD_TYPE_OSM
:
132 case QETH_CARD_TYPE_OSX
:
141 /* max length to be returned: 14 */
142 const char *qeth_get_cardname_short(struct qeth_card
*card
)
144 if (card
->info
.guestlan
) {
145 switch (card
->info
.type
) {
146 case QETH_CARD_TYPE_OSD
:
147 return "Virt.NIC QDIO";
148 case QETH_CARD_TYPE_IQD
:
149 return "Virt.NIC Hiper";
150 case QETH_CARD_TYPE_OSM
:
151 return "Virt.NIC OSM";
152 case QETH_CARD_TYPE_OSX
:
153 return "Virt.NIC OSX";
158 switch (card
->info
.type
) {
159 case QETH_CARD_TYPE_OSD
:
160 switch (card
->info
.link_type
) {
161 case QETH_LINK_TYPE_FAST_ETH
:
163 case QETH_LINK_TYPE_HSTR
:
165 case QETH_LINK_TYPE_GBIT_ETH
:
167 case QETH_LINK_TYPE_10GBIT_ETH
:
169 case QETH_LINK_TYPE_LANE_ETH100
:
170 return "OSD_FE_LANE";
171 case QETH_LINK_TYPE_LANE_TR
:
172 return "OSD_TR_LANE";
173 case QETH_LINK_TYPE_LANE_ETH1000
:
174 return "OSD_GbE_LANE";
175 case QETH_LINK_TYPE_LANE
:
176 return "OSD_ATM_LANE";
178 return "OSD_Express";
180 case QETH_CARD_TYPE_IQD
:
181 return "HiperSockets";
182 case QETH_CARD_TYPE_OSN
:
184 case QETH_CARD_TYPE_OSM
:
186 case QETH_CARD_TYPE_OSX
:
195 void qeth_set_recovery_task(struct qeth_card
*card
)
197 card
->recovery_task
= current
;
199 EXPORT_SYMBOL_GPL(qeth_set_recovery_task
);
201 void qeth_clear_recovery_task(struct qeth_card
*card
)
203 card
->recovery_task
= NULL
;
205 EXPORT_SYMBOL_GPL(qeth_clear_recovery_task
);
207 static bool qeth_is_recovery_task(const struct qeth_card
*card
)
209 return card
->recovery_task
== current
;
212 void qeth_set_allowed_threads(struct qeth_card
*card
, unsigned long threads
,
213 int clear_start_mask
)
217 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
218 card
->thread_allowed_mask
= threads
;
219 if (clear_start_mask
)
220 card
->thread_start_mask
&= threads
;
221 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
222 wake_up(&card
->wait_q
);
224 EXPORT_SYMBOL_GPL(qeth_set_allowed_threads
);
226 int qeth_threads_running(struct qeth_card
*card
, unsigned long threads
)
231 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
232 rc
= (card
->thread_running_mask
& threads
);
233 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
236 EXPORT_SYMBOL_GPL(qeth_threads_running
);
238 int qeth_wait_for_threads(struct qeth_card
*card
, unsigned long threads
)
240 if (qeth_is_recovery_task(card
))
242 return wait_event_interruptible(card
->wait_q
,
243 qeth_threads_running(card
, threads
) == 0);
245 EXPORT_SYMBOL_GPL(qeth_wait_for_threads
);
247 void qeth_clear_working_pool_list(struct qeth_card
*card
)
249 struct qeth_buffer_pool_entry
*pool_entry
, *tmp
;
251 QETH_CARD_TEXT(card
, 5, "clwrklst");
252 list_for_each_entry_safe(pool_entry
, tmp
,
253 &card
->qdio
.in_buf_pool
.entry_list
, list
){
254 list_del(&pool_entry
->list
);
257 EXPORT_SYMBOL_GPL(qeth_clear_working_pool_list
);
259 static int qeth_alloc_buffer_pool(struct qeth_card
*card
)
261 struct qeth_buffer_pool_entry
*pool_entry
;
265 QETH_CARD_TEXT(card
, 5, "alocpool");
266 for (i
= 0; i
< card
->qdio
.init_pool
.buf_count
; ++i
) {
267 pool_entry
= kzalloc(sizeof(*pool_entry
), GFP_KERNEL
);
269 qeth_free_buffer_pool(card
);
272 for (j
= 0; j
< QETH_MAX_BUFFER_ELEMENTS(card
); ++j
) {
273 ptr
= (void *) __get_free_page(GFP_KERNEL
);
276 free_page((unsigned long)
277 pool_entry
->elements
[--j
]);
279 qeth_free_buffer_pool(card
);
282 pool_entry
->elements
[j
] = ptr
;
284 list_add(&pool_entry
->init_list
,
285 &card
->qdio
.init_pool
.entry_list
);
290 int qeth_realloc_buffer_pool(struct qeth_card
*card
, int bufcnt
)
292 QETH_CARD_TEXT(card
, 2, "realcbp");
294 if ((card
->state
!= CARD_STATE_DOWN
) &&
295 (card
->state
!= CARD_STATE_RECOVER
))
298 /* TODO: steel/add buffers from/to a running card's buffer pool (?) */
299 qeth_clear_working_pool_list(card
);
300 qeth_free_buffer_pool(card
);
301 card
->qdio
.in_buf_pool
.buf_count
= bufcnt
;
302 card
->qdio
.init_pool
.buf_count
= bufcnt
;
303 return qeth_alloc_buffer_pool(card
);
305 EXPORT_SYMBOL_GPL(qeth_realloc_buffer_pool
);
307 static void qeth_free_qdio_queue(struct qeth_qdio_q
*q
)
312 qdio_free_buffers(q
->qdio_bufs
, QDIO_MAX_BUFFERS_PER_Q
);
316 static struct qeth_qdio_q
*qeth_alloc_qdio_queue(void)
318 struct qeth_qdio_q
*q
= kzalloc(sizeof(*q
), GFP_KERNEL
);
324 if (qdio_alloc_buffers(q
->qdio_bufs
, QDIO_MAX_BUFFERS_PER_Q
)) {
329 for (i
= 0; i
< QDIO_MAX_BUFFERS_PER_Q
; ++i
)
330 q
->bufs
[i
].buffer
= q
->qdio_bufs
[i
];
332 QETH_DBF_HEX(SETUP
, 2, &q
, sizeof(void *));
336 static int qeth_cq_init(struct qeth_card
*card
)
340 if (card
->options
.cq
== QETH_CQ_ENABLED
) {
341 QETH_DBF_TEXT(SETUP
, 2, "cqinit");
342 qdio_reset_buffers(card
->qdio
.c_q
->qdio_bufs
,
343 QDIO_MAX_BUFFERS_PER_Q
);
344 card
->qdio
.c_q
->next_buf_to_init
= 127;
345 rc
= do_QDIO(CARD_DDEV(card
), QDIO_FLAG_SYNC_INPUT
,
346 card
->qdio
.no_in_queues
- 1, 0,
349 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
358 static int qeth_alloc_cq(struct qeth_card
*card
)
362 if (card
->options
.cq
== QETH_CQ_ENABLED
) {
364 struct qdio_outbuf_state
*outbuf_states
;
366 QETH_DBF_TEXT(SETUP
, 2, "cqon");
367 card
->qdio
.c_q
= qeth_alloc_qdio_queue();
368 if (!card
->qdio
.c_q
) {
372 card
->qdio
.no_in_queues
= 2;
373 card
->qdio
.out_bufstates
=
374 kcalloc(card
->qdio
.no_out_queues
*
375 QDIO_MAX_BUFFERS_PER_Q
,
376 sizeof(struct qdio_outbuf_state
),
378 outbuf_states
= card
->qdio
.out_bufstates
;
379 if (outbuf_states
== NULL
) {
383 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
384 card
->qdio
.out_qs
[i
]->bufstates
= outbuf_states
;
385 outbuf_states
+= QDIO_MAX_BUFFERS_PER_Q
;
388 QETH_DBF_TEXT(SETUP
, 2, "nocq");
389 card
->qdio
.c_q
= NULL
;
390 card
->qdio
.no_in_queues
= 1;
392 QETH_DBF_TEXT_(SETUP
, 2, "iqc%d", card
->qdio
.no_in_queues
);
397 qeth_free_qdio_queue(card
->qdio
.c_q
);
398 card
->qdio
.c_q
= NULL
;
400 dev_err(&card
->gdev
->dev
, "Failed to create completion queue\n");
404 static void qeth_free_cq(struct qeth_card
*card
)
406 if (card
->qdio
.c_q
) {
407 --card
->qdio
.no_in_queues
;
408 qeth_free_qdio_queue(card
->qdio
.c_q
);
409 card
->qdio
.c_q
= NULL
;
411 kfree(card
->qdio
.out_bufstates
);
412 card
->qdio
.out_bufstates
= NULL
;
415 static enum iucv_tx_notify
qeth_compute_cq_notification(int sbalf15
,
418 enum iucv_tx_notify n
;
422 n
= delayed
? TX_NOTIFY_DELAYED_OK
: TX_NOTIFY_OK
;
428 n
= delayed
? TX_NOTIFY_DELAYED_UNREACHABLE
:
429 TX_NOTIFY_UNREACHABLE
;
432 n
= delayed
? TX_NOTIFY_DELAYED_GENERALERROR
:
433 TX_NOTIFY_GENERALERROR
;
440 static void qeth_cleanup_handled_pending(struct qeth_qdio_out_q
*q
, int bidx
,
443 if (q
->card
->options
.cq
!= QETH_CQ_ENABLED
)
446 if (q
->bufs
[bidx
]->next_pending
!= NULL
) {
447 struct qeth_qdio_out_buffer
*head
= q
->bufs
[bidx
];
448 struct qeth_qdio_out_buffer
*c
= q
->bufs
[bidx
]->next_pending
;
451 if (forced_cleanup
||
452 atomic_read(&c
->state
) ==
453 QETH_QDIO_BUF_HANDLED_DELAYED
) {
454 struct qeth_qdio_out_buffer
*f
= c
;
455 QETH_CARD_TEXT(f
->q
->card
, 5, "fp");
456 QETH_CARD_TEXT_(f
->q
->card
, 5, "%lx", (long) f
);
457 /* release here to avoid interleaving between
458 outbound tasklet and inbound tasklet
459 regarding notifications and lifecycle */
460 qeth_release_skbs(c
);
463 WARN_ON_ONCE(head
->next_pending
!= f
);
464 head
->next_pending
= c
;
465 kmem_cache_free(qeth_qdio_outbuf_cache
, f
);
473 if (forced_cleanup
&& (atomic_read(&(q
->bufs
[bidx
]->state
)) ==
474 QETH_QDIO_BUF_HANDLED_DELAYED
)) {
475 /* for recovery situations */
476 q
->bufs
[bidx
]->aob
= q
->bufstates
[bidx
].aob
;
477 qeth_init_qdio_out_buf(q
, bidx
);
478 QETH_CARD_TEXT(q
->card
, 2, "clprecov");
483 static void qeth_qdio_handle_aob(struct qeth_card
*card
,
484 unsigned long phys_aob_addr
)
487 struct qeth_qdio_out_buffer
*buffer
;
488 enum iucv_tx_notify notification
;
491 aob
= (struct qaob
*) phys_to_virt(phys_aob_addr
);
492 QETH_CARD_TEXT(card
, 5, "haob");
493 QETH_CARD_TEXT_(card
, 5, "%lx", phys_aob_addr
);
494 buffer
= (struct qeth_qdio_out_buffer
*) aob
->user1
;
495 QETH_CARD_TEXT_(card
, 5, "%lx", aob
->user1
);
497 if (atomic_cmpxchg(&buffer
->state
, QETH_QDIO_BUF_PRIMED
,
498 QETH_QDIO_BUF_IN_CQ
) == QETH_QDIO_BUF_PRIMED
) {
499 notification
= TX_NOTIFY_OK
;
501 WARN_ON_ONCE(atomic_read(&buffer
->state
) !=
502 QETH_QDIO_BUF_PENDING
);
503 atomic_set(&buffer
->state
, QETH_QDIO_BUF_IN_CQ
);
504 notification
= TX_NOTIFY_DELAYED_OK
;
507 if (aob
->aorc
!= 0) {
508 QETH_CARD_TEXT_(card
, 2, "aorc%02X", aob
->aorc
);
509 notification
= qeth_compute_cq_notification(aob
->aorc
, 1);
511 qeth_notify_skbs(buffer
->q
, buffer
, notification
);
514 /* Free dangling allocations. The attached skbs are handled by
515 * qeth_cleanup_handled_pending().
518 i
< aob
->sb_count
&& i
< QETH_MAX_BUFFER_ELEMENTS(card
);
520 if (aob
->sba
[i
] && buffer
->is_header
[i
])
521 kmem_cache_free(qeth_core_header_cache
,
522 (void *) aob
->sba
[i
]);
524 atomic_set(&buffer
->state
, QETH_QDIO_BUF_HANDLED_DELAYED
);
526 qdio_release_aob(aob
);
529 static inline int qeth_is_cq(struct qeth_card
*card
, unsigned int queue
)
531 return card
->options
.cq
== QETH_CQ_ENABLED
&&
532 card
->qdio
.c_q
!= NULL
&&
534 queue
== card
->qdio
.no_in_queues
- 1;
537 static int __qeth_issue_next_read(struct qeth_card
*card
)
540 struct qeth_cmd_buffer
*iob
;
542 QETH_CARD_TEXT(card
, 5, "issnxrd");
543 if (card
->read
.state
!= CH_STATE_UP
)
545 iob
= qeth_get_buffer(&card
->read
);
547 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
548 "failed to recover an error on the device\n");
549 QETH_DBF_MESSAGE(2, "%s issue_next_read failed: no iob "
550 "available\n", dev_name(&card
->gdev
->dev
));
553 qeth_setup_ccw(&card
->read
, iob
->data
, QETH_BUFSIZE
);
554 QETH_CARD_TEXT(card
, 6, "noirqpnd");
555 rc
= ccw_device_start(card
->read
.ccwdev
, &card
->read
.ccw
,
558 QETH_DBF_MESSAGE(2, "%s error in starting next read ccw! "
559 "rc=%i\n", dev_name(&card
->gdev
->dev
), rc
);
560 atomic_set(&card
->read
.irq_pending
, 0);
561 card
->read_or_write_problem
= 1;
562 qeth_schedule_recovery(card
);
563 wake_up(&card
->wait_q
);
568 static int qeth_issue_next_read(struct qeth_card
*card
)
572 spin_lock_irq(get_ccwdev_lock(CARD_RDEV(card
)));
573 ret
= __qeth_issue_next_read(card
);
574 spin_unlock_irq(get_ccwdev_lock(CARD_RDEV(card
)));
579 static struct qeth_reply
*qeth_alloc_reply(struct qeth_card
*card
)
581 struct qeth_reply
*reply
;
583 reply
= kzalloc(sizeof(struct qeth_reply
), GFP_ATOMIC
);
585 refcount_set(&reply
->refcnt
, 1);
586 atomic_set(&reply
->received
, 0);
592 static void qeth_get_reply(struct qeth_reply
*reply
)
594 refcount_inc(&reply
->refcnt
);
597 static void qeth_put_reply(struct qeth_reply
*reply
)
599 if (refcount_dec_and_test(&reply
->refcnt
))
603 static void qeth_issue_ipa_msg(struct qeth_ipa_cmd
*cmd
, int rc
,
604 struct qeth_card
*card
)
607 int com
= cmd
->hdr
.command
;
608 ipa_name
= qeth_get_ipa_cmd_name(com
);
610 QETH_DBF_MESSAGE(2, "IPA: %s(x%X) for %s/%s returned "
612 ipa_name
, com
, dev_name(&card
->gdev
->dev
),
613 QETH_CARD_IFNAME(card
), rc
,
614 qeth_get_ipa_msg(rc
));
616 QETH_DBF_MESSAGE(5, "IPA: %s(x%X) for %s/%s succeeded\n",
617 ipa_name
, com
, dev_name(&card
->gdev
->dev
),
618 QETH_CARD_IFNAME(card
));
621 static struct qeth_ipa_cmd
*qeth_check_ipa_data(struct qeth_card
*card
,
622 struct qeth_cmd_buffer
*iob
)
624 struct qeth_ipa_cmd
*cmd
= NULL
;
626 QETH_CARD_TEXT(card
, 5, "chkipad");
627 if (IS_IPA(iob
->data
)) {
628 cmd
= (struct qeth_ipa_cmd
*) PDU_ENCAPSULATION(iob
->data
);
629 if (IS_IPA_REPLY(cmd
)) {
630 if (cmd
->hdr
.command
!= IPA_CMD_SETCCID
&&
631 cmd
->hdr
.command
!= IPA_CMD_DELCCID
&&
632 cmd
->hdr
.command
!= IPA_CMD_MODCCID
&&
633 cmd
->hdr
.command
!= IPA_CMD_SET_DIAG_ASS
)
634 qeth_issue_ipa_msg(cmd
,
635 cmd
->hdr
.return_code
, card
);
638 switch (cmd
->hdr
.command
) {
639 case IPA_CMD_STOPLAN
:
640 if (cmd
->hdr
.return_code
==
641 IPA_RC_VEPA_TO_VEB_TRANSITION
) {
642 dev_err(&card
->gdev
->dev
,
643 "Interface %s is down because the "
644 "adjacent port is no longer in "
645 "reflective relay mode\n",
646 QETH_CARD_IFNAME(card
));
647 qeth_close_dev(card
);
649 dev_warn(&card
->gdev
->dev
,
650 "The link for interface %s on CHPID"
652 QETH_CARD_IFNAME(card
),
654 qeth_issue_ipa_msg(cmd
,
655 cmd
->hdr
.return_code
, card
);
657 card
->lan_online
= 0;
658 if (card
->dev
&& netif_carrier_ok(card
->dev
))
659 netif_carrier_off(card
->dev
);
661 case IPA_CMD_STARTLAN
:
662 dev_info(&card
->gdev
->dev
,
663 "The link for %s on CHPID 0x%X has"
665 QETH_CARD_IFNAME(card
),
667 netif_carrier_on(card
->dev
);
668 card
->lan_online
= 1;
669 if (card
->info
.hwtrap
)
670 card
->info
.hwtrap
= 2;
671 qeth_schedule_recovery(card
);
673 case IPA_CMD_SETBRIDGEPORT_IQD
:
674 case IPA_CMD_SETBRIDGEPORT_OSA
:
675 case IPA_CMD_ADDRESS_CHANGE_NOTIF
:
676 if (card
->discipline
->control_event_handler
681 case IPA_CMD_MODCCID
:
683 case IPA_CMD_REGISTER_LOCAL_ADDR
:
684 QETH_CARD_TEXT(card
, 3, "irla");
686 case IPA_CMD_UNREGISTER_LOCAL_ADDR
:
687 QETH_CARD_TEXT(card
, 3, "urla");
690 QETH_DBF_MESSAGE(2, "Received data is IPA "
691 "but not a reply!\n");
699 void qeth_clear_ipacmd_list(struct qeth_card
*card
)
701 struct qeth_reply
*reply
, *r
;
704 QETH_CARD_TEXT(card
, 4, "clipalst");
706 spin_lock_irqsave(&card
->lock
, flags
);
707 list_for_each_entry_safe(reply
, r
, &card
->cmd_waiter_list
, list
) {
708 qeth_get_reply(reply
);
710 atomic_inc(&reply
->received
);
711 list_del_init(&reply
->list
);
712 wake_up(&reply
->wait_q
);
713 qeth_put_reply(reply
);
715 spin_unlock_irqrestore(&card
->lock
, flags
);
717 EXPORT_SYMBOL_GPL(qeth_clear_ipacmd_list
);
719 static int qeth_check_idx_response(struct qeth_card
*card
,
720 unsigned char *buffer
)
725 QETH_DBF_HEX(CTRL
, 2, buffer
, QETH_DBF_CTRL_LEN
);
726 if ((buffer
[2] & 0xc0) == 0xc0) {
727 QETH_DBF_MESSAGE(2, "received an IDX TERMINATE with cause code %#02x\n",
729 QETH_CARD_TEXT(card
, 2, "ckidxres");
730 QETH_CARD_TEXT(card
, 2, " idxterm");
731 QETH_CARD_TEXT_(card
, 2, " rc%d", -EIO
);
732 if (buffer
[4] == 0xf6) {
733 dev_err(&card
->gdev
->dev
,
734 "The qeth device is not configured "
735 "for the OSI layer required by z/VM\n");
743 static struct qeth_card
*CARD_FROM_CDEV(struct ccw_device
*cdev
)
745 struct qeth_card
*card
= dev_get_drvdata(&((struct ccwgroup_device
*)
746 dev_get_drvdata(&cdev
->dev
))->dev
);
750 static void qeth_setup_ccw(struct qeth_channel
*channel
, unsigned char *iob
,
753 struct qeth_card
*card
;
755 card
= CARD_FROM_CDEV(channel
->ccwdev
);
756 QETH_CARD_TEXT(card
, 4, "setupccw");
757 if (channel
== &card
->read
)
758 memcpy(&channel
->ccw
, READ_CCW
, sizeof(struct ccw1
));
760 memcpy(&channel
->ccw
, WRITE_CCW
, sizeof(struct ccw1
));
761 channel
->ccw
.count
= len
;
762 channel
->ccw
.cda
= (__u32
) __pa(iob
);
765 static struct qeth_cmd_buffer
*__qeth_get_buffer(struct qeth_channel
*channel
)
769 QETH_CARD_TEXT(CARD_FROM_CDEV(channel
->ccwdev
), 6, "getbuff");
770 index
= channel
->io_buf_no
;
772 if (channel
->iob
[index
].state
== BUF_STATE_FREE
) {
773 channel
->iob
[index
].state
= BUF_STATE_LOCKED
;
774 channel
->io_buf_no
= (channel
->io_buf_no
+ 1) %
776 memset(channel
->iob
[index
].data
, 0, QETH_BUFSIZE
);
777 return channel
->iob
+ index
;
779 index
= (index
+ 1) % QETH_CMD_BUFFER_NO
;
780 } while (index
!= channel
->io_buf_no
);
785 void qeth_release_buffer(struct qeth_channel
*channel
,
786 struct qeth_cmd_buffer
*iob
)
790 QETH_CARD_TEXT(CARD_FROM_CDEV(channel
->ccwdev
), 6, "relbuff");
791 spin_lock_irqsave(&channel
->iob_lock
, flags
);
792 memset(iob
->data
, 0, QETH_BUFSIZE
);
793 iob
->state
= BUF_STATE_FREE
;
794 iob
->callback
= qeth_send_control_data_cb
;
796 spin_unlock_irqrestore(&channel
->iob_lock
, flags
);
797 wake_up(&channel
->wait_q
);
799 EXPORT_SYMBOL_GPL(qeth_release_buffer
);
801 static struct qeth_cmd_buffer
*qeth_get_buffer(struct qeth_channel
*channel
)
803 struct qeth_cmd_buffer
*buffer
= NULL
;
806 spin_lock_irqsave(&channel
->iob_lock
, flags
);
807 buffer
= __qeth_get_buffer(channel
);
808 spin_unlock_irqrestore(&channel
->iob_lock
, flags
);
812 struct qeth_cmd_buffer
*qeth_wait_for_buffer(struct qeth_channel
*channel
)
814 struct qeth_cmd_buffer
*buffer
;
815 wait_event(channel
->wait_q
,
816 ((buffer
= qeth_get_buffer(channel
)) != NULL
));
819 EXPORT_SYMBOL_GPL(qeth_wait_for_buffer
);
821 void qeth_clear_cmd_buffers(struct qeth_channel
*channel
)
825 for (cnt
= 0; cnt
< QETH_CMD_BUFFER_NO
; cnt
++)
826 qeth_release_buffer(channel
, &channel
->iob
[cnt
]);
827 channel
->io_buf_no
= 0;
829 EXPORT_SYMBOL_GPL(qeth_clear_cmd_buffers
);
831 static void qeth_send_control_data_cb(struct qeth_channel
*channel
,
832 struct qeth_cmd_buffer
*iob
)
834 struct qeth_card
*card
;
835 struct qeth_reply
*reply
, *r
;
836 struct qeth_ipa_cmd
*cmd
;
841 card
= CARD_FROM_CDEV(channel
->ccwdev
);
842 QETH_CARD_TEXT(card
, 4, "sndctlcb");
843 rc
= qeth_check_idx_response(card
, iob
->data
);
848 qeth_clear_ipacmd_list(card
);
849 qeth_schedule_recovery(card
);
855 cmd
= qeth_check_ipa_data(card
, iob
);
856 if ((cmd
== NULL
) && (card
->state
!= CARD_STATE_DOWN
))
858 /*in case of OSN : check if cmd is set */
859 if (card
->info
.type
== QETH_CARD_TYPE_OSN
&&
861 cmd
->hdr
.command
!= IPA_CMD_STARTLAN
&&
862 card
->osn_info
.assist_cb
!= NULL
) {
863 card
->osn_info
.assist_cb(card
->dev
, cmd
);
867 spin_lock_irqsave(&card
->lock
, flags
);
868 list_for_each_entry_safe(reply
, r
, &card
->cmd_waiter_list
, list
) {
869 if ((reply
->seqno
== QETH_IDX_COMMAND_SEQNO
) ||
870 ((cmd
) && (reply
->seqno
== cmd
->hdr
.seqno
))) {
871 qeth_get_reply(reply
);
872 list_del_init(&reply
->list
);
873 spin_unlock_irqrestore(&card
->lock
, flags
);
875 if (reply
->callback
!= NULL
) {
877 reply
->offset
= (__u16
)((char *)cmd
-
879 keep_reply
= reply
->callback(card
,
883 keep_reply
= reply
->callback(card
,
888 reply
->rc
= (u16
) cmd
->hdr
.return_code
;
892 spin_lock_irqsave(&card
->lock
, flags
);
893 list_add_tail(&reply
->list
,
894 &card
->cmd_waiter_list
);
895 spin_unlock_irqrestore(&card
->lock
, flags
);
897 atomic_inc(&reply
->received
);
898 wake_up(&reply
->wait_q
);
900 qeth_put_reply(reply
);
904 spin_unlock_irqrestore(&card
->lock
, flags
);
906 memcpy(&card
->seqno
.pdu_hdr_ack
,
907 QETH_PDU_HEADER_SEQ_NO(iob
->data
),
909 qeth_release_buffer(channel
, iob
);
912 static int qeth_setup_channel(struct qeth_channel
*channel
)
916 QETH_DBF_TEXT(SETUP
, 2, "setupch");
917 for (cnt
= 0; cnt
< QETH_CMD_BUFFER_NO
; cnt
++) {
918 channel
->iob
[cnt
].data
=
919 kzalloc(QETH_BUFSIZE
, GFP_DMA
|GFP_KERNEL
);
920 if (channel
->iob
[cnt
].data
== NULL
)
922 channel
->iob
[cnt
].state
= BUF_STATE_FREE
;
923 channel
->iob
[cnt
].channel
= channel
;
924 channel
->iob
[cnt
].callback
= qeth_send_control_data_cb
;
925 channel
->iob
[cnt
].rc
= 0;
927 if (cnt
< QETH_CMD_BUFFER_NO
) {
929 kfree(channel
->iob
[cnt
].data
);
932 channel
->io_buf_no
= 0;
933 atomic_set(&channel
->irq_pending
, 0);
934 spin_lock_init(&channel
->iob_lock
);
936 init_waitqueue_head(&channel
->wait_q
);
940 static int qeth_set_thread_start_bit(struct qeth_card
*card
,
941 unsigned long thread
)
945 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
946 if (!(card
->thread_allowed_mask
& thread
) ||
947 (card
->thread_start_mask
& thread
)) {
948 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
951 card
->thread_start_mask
|= thread
;
952 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
956 void qeth_clear_thread_start_bit(struct qeth_card
*card
, unsigned long thread
)
960 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
961 card
->thread_start_mask
&= ~thread
;
962 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
963 wake_up(&card
->wait_q
);
965 EXPORT_SYMBOL_GPL(qeth_clear_thread_start_bit
);
967 void qeth_clear_thread_running_bit(struct qeth_card
*card
, unsigned long thread
)
971 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
972 card
->thread_running_mask
&= ~thread
;
973 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
974 wake_up_all(&card
->wait_q
);
976 EXPORT_SYMBOL_GPL(qeth_clear_thread_running_bit
);
978 static int __qeth_do_run_thread(struct qeth_card
*card
, unsigned long thread
)
983 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
984 if (card
->thread_start_mask
& thread
) {
985 if ((card
->thread_allowed_mask
& thread
) &&
986 !(card
->thread_running_mask
& thread
)) {
988 card
->thread_start_mask
&= ~thread
;
989 card
->thread_running_mask
|= thread
;
993 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
997 int qeth_do_run_thread(struct qeth_card
*card
, unsigned long thread
)
1001 wait_event(card
->wait_q
,
1002 (rc
= __qeth_do_run_thread(card
, thread
)) >= 0);
1005 EXPORT_SYMBOL_GPL(qeth_do_run_thread
);
1007 void qeth_schedule_recovery(struct qeth_card
*card
)
1009 QETH_CARD_TEXT(card
, 2, "startrec");
1010 if (qeth_set_thread_start_bit(card
, QETH_RECOVER_THREAD
) == 0)
1011 schedule_work(&card
->kernel_thread_starter
);
1013 EXPORT_SYMBOL_GPL(qeth_schedule_recovery
);
1015 static int qeth_get_problem(struct ccw_device
*cdev
, struct irb
*irb
)
1019 struct qeth_card
*card
;
1021 sense
= (char *) irb
->ecw
;
1022 cstat
= irb
->scsw
.cmd
.cstat
;
1023 dstat
= irb
->scsw
.cmd
.dstat
;
1024 card
= CARD_FROM_CDEV(cdev
);
1026 if (cstat
& (SCHN_STAT_CHN_CTRL_CHK
| SCHN_STAT_INTF_CTRL_CHK
|
1027 SCHN_STAT_CHN_DATA_CHK
| SCHN_STAT_CHAIN_CHECK
|
1028 SCHN_STAT_PROT_CHECK
| SCHN_STAT_PROG_CHECK
)) {
1029 QETH_CARD_TEXT(card
, 2, "CGENCHK");
1030 dev_warn(&cdev
->dev
, "The qeth device driver "
1031 "failed to recover an error on the device\n");
1032 QETH_DBF_MESSAGE(2, "%s check on device dstat=x%x, cstat=x%x\n",
1033 dev_name(&cdev
->dev
), dstat
, cstat
);
1034 print_hex_dump(KERN_WARNING
, "qeth: irb ", DUMP_PREFIX_OFFSET
,
1039 if (dstat
& DEV_STAT_UNIT_CHECK
) {
1040 if (sense
[SENSE_RESETTING_EVENT_BYTE
] &
1041 SENSE_RESETTING_EVENT_FLAG
) {
1042 QETH_CARD_TEXT(card
, 2, "REVIND");
1045 if (sense
[SENSE_COMMAND_REJECT_BYTE
] &
1046 SENSE_COMMAND_REJECT_FLAG
) {
1047 QETH_CARD_TEXT(card
, 2, "CMDREJi");
1050 if ((sense
[2] == 0xaf) && (sense
[3] == 0xfe)) {
1051 QETH_CARD_TEXT(card
, 2, "AFFE");
1054 if ((!sense
[0]) && (!sense
[1]) && (!sense
[2]) && (!sense
[3])) {
1055 QETH_CARD_TEXT(card
, 2, "ZEROSEN");
1058 QETH_CARD_TEXT(card
, 2, "DGENCHK");
1064 static long __qeth_check_irb_error(struct ccw_device
*cdev
,
1065 unsigned long intparm
, struct irb
*irb
)
1067 struct qeth_card
*card
;
1069 card
= CARD_FROM_CDEV(cdev
);
1071 if (!card
|| !IS_ERR(irb
))
1074 switch (PTR_ERR(irb
)) {
1076 QETH_DBF_MESSAGE(2, "%s i/o-error on device\n",
1077 dev_name(&cdev
->dev
));
1078 QETH_CARD_TEXT(card
, 2, "ckirberr");
1079 QETH_CARD_TEXT_(card
, 2, " rc%d", -EIO
);
1082 dev_warn(&cdev
->dev
, "A hardware operation timed out"
1083 " on the device\n");
1084 QETH_CARD_TEXT(card
, 2, "ckirberr");
1085 QETH_CARD_TEXT_(card
, 2, " rc%d", -ETIMEDOUT
);
1086 if (intparm
== QETH_RCD_PARM
) {
1087 if (card
->data
.ccwdev
== cdev
) {
1088 card
->data
.state
= CH_STATE_DOWN
;
1089 wake_up(&card
->wait_q
);
1094 QETH_DBF_MESSAGE(2, "%s unknown error %ld on device\n",
1095 dev_name(&cdev
->dev
), PTR_ERR(irb
));
1096 QETH_CARD_TEXT(card
, 2, "ckirberr");
1097 QETH_CARD_TEXT(card
, 2, " rc???");
1099 return PTR_ERR(irb
);
1102 static void qeth_irq(struct ccw_device
*cdev
, unsigned long intparm
,
1107 struct qeth_cmd_buffer
*iob
= NULL
;
1108 struct qeth_channel
*channel
;
1109 struct qeth_card
*card
;
1111 card
= CARD_FROM_CDEV(cdev
);
1115 QETH_CARD_TEXT(card
, 5, "irq");
1117 if (card
->read
.ccwdev
== cdev
) {
1118 channel
= &card
->read
;
1119 QETH_CARD_TEXT(card
, 5, "read");
1120 } else if (card
->write
.ccwdev
== cdev
) {
1121 channel
= &card
->write
;
1122 QETH_CARD_TEXT(card
, 5, "write");
1124 channel
= &card
->data
;
1125 QETH_CARD_TEXT(card
, 5, "data");
1128 if (qeth_intparm_is_iob(intparm
))
1129 iob
= (struct qeth_cmd_buffer
*) __va((addr_t
)intparm
);
1131 if (__qeth_check_irb_error(cdev
, intparm
, irb
)) {
1132 /* IO was terminated, free its resources. */
1134 qeth_release_buffer(iob
->channel
, iob
);
1135 atomic_set(&channel
->irq_pending
, 0);
1136 wake_up(&card
->wait_q
);
1140 atomic_set(&channel
->irq_pending
, 0);
1142 if (irb
->scsw
.cmd
.fctl
& (SCSW_FCTL_CLEAR_FUNC
))
1143 channel
->state
= CH_STATE_STOPPED
;
1145 if (irb
->scsw
.cmd
.fctl
& (SCSW_FCTL_HALT_FUNC
))
1146 channel
->state
= CH_STATE_HALTED
;
1148 /*let's wake up immediately on data channel*/
1149 if ((channel
== &card
->data
) && (intparm
!= 0) &&
1150 (intparm
!= QETH_RCD_PARM
))
1153 if (intparm
== QETH_CLEAR_CHANNEL_PARM
) {
1154 QETH_CARD_TEXT(card
, 6, "clrchpar");
1155 /* we don't have to handle this further */
1158 if (intparm
== QETH_HALT_CHANNEL_PARM
) {
1159 QETH_CARD_TEXT(card
, 6, "hltchpar");
1160 /* we don't have to handle this further */
1164 cstat
= irb
->scsw
.cmd
.cstat
;
1165 dstat
= irb
->scsw
.cmd
.dstat
;
1167 if ((dstat
& DEV_STAT_UNIT_EXCEP
) ||
1168 (dstat
& DEV_STAT_UNIT_CHECK
) ||
1170 if (irb
->esw
.esw0
.erw
.cons
) {
1171 dev_warn(&channel
->ccwdev
->dev
,
1172 "The qeth device driver failed to recover "
1173 "an error on the device\n");
1174 QETH_DBF_MESSAGE(2, "%s sense data available. cstat "
1175 "0x%X dstat 0x%X\n",
1176 dev_name(&channel
->ccwdev
->dev
), cstat
, dstat
);
1177 print_hex_dump(KERN_WARNING
, "qeth: irb ",
1178 DUMP_PREFIX_OFFSET
, 16, 1, irb
, 32, 1);
1179 print_hex_dump(KERN_WARNING
, "qeth: sense data ",
1180 DUMP_PREFIX_OFFSET
, 16, 1, irb
->ecw
, 32, 1);
1182 if (intparm
== QETH_RCD_PARM
) {
1183 channel
->state
= CH_STATE_DOWN
;
1186 rc
= qeth_get_problem(cdev
, irb
);
1188 card
->read_or_write_problem
= 1;
1189 qeth_clear_ipacmd_list(card
);
1190 qeth_schedule_recovery(card
);
1195 if (intparm
== QETH_RCD_PARM
) {
1196 channel
->state
= CH_STATE_RCD_DONE
;
1199 if (channel
== &card
->data
)
1201 if (channel
== &card
->read
&&
1202 channel
->state
== CH_STATE_UP
)
1203 __qeth_issue_next_read(card
);
1205 if (iob
&& iob
->callback
)
1206 iob
->callback(iob
->channel
, iob
);
1209 wake_up(&card
->wait_q
);
1213 static void qeth_notify_skbs(struct qeth_qdio_out_q
*q
,
1214 struct qeth_qdio_out_buffer
*buf
,
1215 enum iucv_tx_notify notification
)
1217 struct sk_buff
*skb
;
1219 if (skb_queue_empty(&buf
->skb_list
))
1221 skb
= skb_peek(&buf
->skb_list
);
1223 QETH_CARD_TEXT_(q
->card
, 5, "skbn%d", notification
);
1224 QETH_CARD_TEXT_(q
->card
, 5, "%lx", (long) skb
);
1225 if (be16_to_cpu(skb
->protocol
) == ETH_P_AF_IUCV
) {
1227 struct iucv_sock
*iucv
= iucv_sk(skb
->sk
);
1228 iucv
->sk_txnotify(skb
, notification
);
1231 if (skb_queue_is_last(&buf
->skb_list
, skb
))
1234 skb
= skb_queue_next(&buf
->skb_list
, skb
);
1240 static void qeth_release_skbs(struct qeth_qdio_out_buffer
*buf
)
1242 struct sk_buff
*skb
;
1243 struct iucv_sock
*iucv
;
1244 int notify_general_error
= 0;
1246 if (atomic_read(&buf
->state
) == QETH_QDIO_BUF_PENDING
)
1247 notify_general_error
= 1;
1249 /* release may never happen from within CQ tasklet scope */
1250 WARN_ON_ONCE(atomic_read(&buf
->state
) == QETH_QDIO_BUF_IN_CQ
);
1252 skb
= skb_dequeue(&buf
->skb_list
);
1254 QETH_CARD_TEXT(buf
->q
->card
, 5, "skbr");
1255 QETH_CARD_TEXT_(buf
->q
->card
, 5, "%lx", (long) skb
);
1256 if (notify_general_error
&&
1257 be16_to_cpu(skb
->protocol
) == ETH_P_AF_IUCV
) {
1259 iucv
= iucv_sk(skb
->sk
);
1260 iucv
->sk_txnotify(skb
, TX_NOTIFY_GENERALERROR
);
1263 refcount_dec(&skb
->users
);
1264 dev_kfree_skb_any(skb
);
1265 skb
= skb_dequeue(&buf
->skb_list
);
1269 static void qeth_clear_output_buffer(struct qeth_qdio_out_q
*queue
,
1270 struct qeth_qdio_out_buffer
*buf
,
1271 enum qeth_qdio_buffer_states newbufstate
)
1275 /* is PCI flag set on buffer? */
1276 if (buf
->buffer
->element
[0].sflags
& SBAL_SFLAGS0_PCI_REQ
)
1277 atomic_dec(&queue
->set_pci_flags_count
);
1279 if (newbufstate
== QETH_QDIO_BUF_EMPTY
) {
1280 qeth_release_skbs(buf
);
1282 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(queue
->card
); ++i
) {
1283 if (buf
->buffer
->element
[i
].addr
&& buf
->is_header
[i
])
1284 kmem_cache_free(qeth_core_header_cache
,
1285 buf
->buffer
->element
[i
].addr
);
1286 buf
->is_header
[i
] = 0;
1287 buf
->buffer
->element
[i
].length
= 0;
1288 buf
->buffer
->element
[i
].addr
= NULL
;
1289 buf
->buffer
->element
[i
].eflags
= 0;
1290 buf
->buffer
->element
[i
].sflags
= 0;
1292 buf
->buffer
->element
[15].eflags
= 0;
1293 buf
->buffer
->element
[15].sflags
= 0;
1294 buf
->next_element_to_fill
= 0;
1295 atomic_set(&buf
->state
, newbufstate
);
1298 static void qeth_clear_outq_buffers(struct qeth_qdio_out_q
*q
, int free
)
1302 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
) {
1305 qeth_cleanup_handled_pending(q
, j
, 1);
1306 qeth_clear_output_buffer(q
, q
->bufs
[j
], QETH_QDIO_BUF_EMPTY
);
1308 kmem_cache_free(qeth_qdio_outbuf_cache
, q
->bufs
[j
]);
1314 void qeth_clear_qdio_buffers(struct qeth_card
*card
)
1318 QETH_CARD_TEXT(card
, 2, "clearqdbf");
1319 /* clear outbound buffers to free skbs */
1320 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
1321 if (card
->qdio
.out_qs
[i
]) {
1322 qeth_clear_outq_buffers(card
->qdio
.out_qs
[i
], 0);
1326 EXPORT_SYMBOL_GPL(qeth_clear_qdio_buffers
);
1328 static void qeth_free_buffer_pool(struct qeth_card
*card
)
1330 struct qeth_buffer_pool_entry
*pool_entry
, *tmp
;
1332 list_for_each_entry_safe(pool_entry
, tmp
,
1333 &card
->qdio
.init_pool
.entry_list
, init_list
){
1334 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(card
); ++i
)
1335 free_page((unsigned long)pool_entry
->elements
[i
]);
1336 list_del(&pool_entry
->init_list
);
1341 static void qeth_clean_channel(struct qeth_channel
*channel
)
1345 QETH_DBF_TEXT(SETUP
, 2, "freech");
1346 for (cnt
= 0; cnt
< QETH_CMD_BUFFER_NO
; cnt
++)
1347 kfree(channel
->iob
[cnt
].data
);
1350 static void qeth_set_single_write_queues(struct qeth_card
*card
)
1352 if ((atomic_read(&card
->qdio
.state
) != QETH_QDIO_UNINITIALIZED
) &&
1353 (card
->qdio
.no_out_queues
== 4))
1354 qeth_free_qdio_buffers(card
);
1356 card
->qdio
.no_out_queues
= 1;
1357 if (card
->qdio
.default_out_queue
!= 0)
1358 dev_info(&card
->gdev
->dev
, "Priority Queueing not supported\n");
1360 card
->qdio
.default_out_queue
= 0;
1363 static void qeth_set_multiple_write_queues(struct qeth_card
*card
)
1365 if ((atomic_read(&card
->qdio
.state
) != QETH_QDIO_UNINITIALIZED
) &&
1366 (card
->qdio
.no_out_queues
== 1)) {
1367 qeth_free_qdio_buffers(card
);
1368 card
->qdio
.default_out_queue
= 2;
1370 card
->qdio
.no_out_queues
= 4;
1373 static void qeth_update_from_chp_desc(struct qeth_card
*card
)
1375 struct ccw_device
*ccwdev
;
1376 struct channel_path_desc_fmt0
*chp_dsc
;
1378 QETH_DBF_TEXT(SETUP
, 2, "chp_desc");
1380 ccwdev
= card
->data
.ccwdev
;
1381 chp_dsc
= ccw_device_get_chp_desc(ccwdev
, 0);
1385 card
->info
.func_level
= 0x4100 + chp_dsc
->desc
;
1386 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
1389 /* CHPP field bit 6 == 1 -> single queue */
1390 if ((chp_dsc
->chpp
& 0x02) == 0x02)
1391 qeth_set_single_write_queues(card
);
1393 qeth_set_multiple_write_queues(card
);
1396 QETH_DBF_TEXT_(SETUP
, 2, "nr:%x", card
->qdio
.no_out_queues
);
1397 QETH_DBF_TEXT_(SETUP
, 2, "lvl:%02x", card
->info
.func_level
);
1400 static void qeth_init_qdio_info(struct qeth_card
*card
)
1402 QETH_DBF_TEXT(SETUP
, 4, "intqdinf");
1403 atomic_set(&card
->qdio
.state
, QETH_QDIO_UNINITIALIZED
);
1405 card
->qdio
.no_in_queues
= 1;
1406 card
->qdio
.in_buf_size
= QETH_IN_BUF_SIZE_DEFAULT
;
1407 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
1408 card
->qdio
.init_pool
.buf_count
= QETH_IN_BUF_COUNT_HSDEFAULT
;
1410 card
->qdio
.init_pool
.buf_count
= QETH_IN_BUF_COUNT_DEFAULT
;
1411 card
->qdio
.in_buf_pool
.buf_count
= card
->qdio
.init_pool
.buf_count
;
1412 INIT_LIST_HEAD(&card
->qdio
.in_buf_pool
.entry_list
);
1413 INIT_LIST_HEAD(&card
->qdio
.init_pool
.entry_list
);
1416 static void qeth_set_intial_options(struct qeth_card
*card
)
1418 card
->options
.route4
.type
= NO_ROUTER
;
1419 card
->options
.route6
.type
= NO_ROUTER
;
1420 card
->options
.fake_broadcast
= 0;
1421 card
->options
.performance_stats
= 0;
1422 card
->options
.rx_sg_cb
= QETH_RX_SG_CB
;
1423 card
->options
.isolation
= ISOLATION_MODE_NONE
;
1424 card
->options
.cq
= QETH_CQ_DISABLED
;
1427 static int qeth_do_start_thread(struct qeth_card
*card
, unsigned long thread
)
1429 unsigned long flags
;
1432 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
1433 QETH_CARD_TEXT_(card
, 4, " %02x%02x%02x",
1434 (u8
) card
->thread_start_mask
,
1435 (u8
) card
->thread_allowed_mask
,
1436 (u8
) card
->thread_running_mask
);
1437 rc
= (card
->thread_start_mask
& thread
);
1438 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
1442 static void qeth_start_kernel_thread(struct work_struct
*work
)
1444 struct task_struct
*ts
;
1445 struct qeth_card
*card
= container_of(work
, struct qeth_card
,
1446 kernel_thread_starter
);
1447 QETH_CARD_TEXT(card
, 2, "strthrd");
1449 if (card
->read
.state
!= CH_STATE_UP
&&
1450 card
->write
.state
!= CH_STATE_UP
)
1452 if (qeth_do_start_thread(card
, QETH_RECOVER_THREAD
)) {
1453 ts
= kthread_run(card
->discipline
->recover
, (void *)card
,
1456 qeth_clear_thread_start_bit(card
, QETH_RECOVER_THREAD
);
1457 qeth_clear_thread_running_bit(card
,
1458 QETH_RECOVER_THREAD
);
1463 static void qeth_buffer_reclaim_work(struct work_struct
*);
1464 static int qeth_setup_card(struct qeth_card
*card
)
1467 QETH_DBF_TEXT(SETUP
, 2, "setupcrd");
1468 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
1470 card
->read
.state
= CH_STATE_DOWN
;
1471 card
->write
.state
= CH_STATE_DOWN
;
1472 card
->data
.state
= CH_STATE_DOWN
;
1473 card
->state
= CARD_STATE_DOWN
;
1474 card
->lan_online
= 0;
1475 card
->read_or_write_problem
= 0;
1477 spin_lock_init(&card
->mclock
);
1478 spin_lock_init(&card
->lock
);
1479 spin_lock_init(&card
->ip_lock
);
1480 spin_lock_init(&card
->thread_mask_lock
);
1481 mutex_init(&card
->conf_mutex
);
1482 mutex_init(&card
->discipline_mutex
);
1483 mutex_init(&card
->vid_list_mutex
);
1484 card
->thread_start_mask
= 0;
1485 card
->thread_allowed_mask
= 0;
1486 card
->thread_running_mask
= 0;
1487 INIT_WORK(&card
->kernel_thread_starter
, qeth_start_kernel_thread
);
1488 INIT_LIST_HEAD(&card
->cmd_waiter_list
);
1489 init_waitqueue_head(&card
->wait_q
);
1490 /* initial options */
1491 qeth_set_intial_options(card
);
1492 /* IP address takeover */
1493 INIT_LIST_HEAD(&card
->ipato
.entries
);
1494 card
->ipato
.enabled
= false;
1495 card
->ipato
.invert4
= false;
1496 card
->ipato
.invert6
= false;
1497 /* init QDIO stuff */
1498 qeth_init_qdio_info(card
);
1499 INIT_DELAYED_WORK(&card
->buffer_reclaim_work
, qeth_buffer_reclaim_work
);
1500 INIT_WORK(&card
->close_dev_work
, qeth_close_dev_handler
);
1504 static void qeth_core_sl_print(struct seq_file
*m
, struct service_level
*slr
)
1506 struct qeth_card
*card
= container_of(slr
, struct qeth_card
,
1507 qeth_service_level
);
1508 if (card
->info
.mcl_level
[0])
1509 seq_printf(m
, "qeth: %s firmware level %s\n",
1510 CARD_BUS_ID(card
), card
->info
.mcl_level
);
1513 static struct qeth_card
*qeth_alloc_card(void)
1515 struct qeth_card
*card
;
1517 QETH_DBF_TEXT(SETUP
, 2, "alloccrd");
1518 card
= kzalloc(sizeof(struct qeth_card
), GFP_DMA
|GFP_KERNEL
);
1521 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
1522 if (qeth_setup_channel(&card
->read
))
1524 if (qeth_setup_channel(&card
->write
))
1526 card
->options
.layer2
= -1;
1527 card
->qeth_service_level
.seq_print
= qeth_core_sl_print
;
1528 register_service_level(&card
->qeth_service_level
);
1532 qeth_clean_channel(&card
->read
);
1539 static void qeth_determine_card_type(struct qeth_card
*card
)
1541 QETH_DBF_TEXT(SETUP
, 2, "detcdtyp");
1543 card
->qdio
.do_prio_queueing
= QETH_PRIOQ_DEFAULT
;
1544 card
->qdio
.default_out_queue
= QETH_DEFAULT_QUEUE
;
1545 card
->info
.type
= CARD_RDEV(card
)->id
.driver_info
;
1546 card
->qdio
.no_out_queues
= QETH_MAX_QUEUES
;
1547 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
1548 card
->info
.is_multicast_different
= 0x0103;
1549 qeth_update_from_chp_desc(card
);
1552 static int qeth_clear_channel(struct qeth_channel
*channel
)
1554 unsigned long flags
;
1555 struct qeth_card
*card
;
1558 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1559 QETH_CARD_TEXT(card
, 3, "clearch");
1560 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1561 rc
= ccw_device_clear(channel
->ccwdev
, QETH_CLEAR_CHANNEL_PARM
);
1562 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1566 rc
= wait_event_interruptible_timeout(card
->wait_q
,
1567 channel
->state
== CH_STATE_STOPPED
, QETH_TIMEOUT
);
1568 if (rc
== -ERESTARTSYS
)
1570 if (channel
->state
!= CH_STATE_STOPPED
)
1572 channel
->state
= CH_STATE_DOWN
;
1576 static int qeth_halt_channel(struct qeth_channel
*channel
)
1578 unsigned long flags
;
1579 struct qeth_card
*card
;
1582 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1583 QETH_CARD_TEXT(card
, 3, "haltch");
1584 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1585 rc
= ccw_device_halt(channel
->ccwdev
, QETH_HALT_CHANNEL_PARM
);
1586 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1590 rc
= wait_event_interruptible_timeout(card
->wait_q
,
1591 channel
->state
== CH_STATE_HALTED
, QETH_TIMEOUT
);
1592 if (rc
== -ERESTARTSYS
)
1594 if (channel
->state
!= CH_STATE_HALTED
)
1599 static int qeth_halt_channels(struct qeth_card
*card
)
1601 int rc1
= 0, rc2
= 0, rc3
= 0;
1603 QETH_CARD_TEXT(card
, 3, "haltchs");
1604 rc1
= qeth_halt_channel(&card
->read
);
1605 rc2
= qeth_halt_channel(&card
->write
);
1606 rc3
= qeth_halt_channel(&card
->data
);
1614 static int qeth_clear_channels(struct qeth_card
*card
)
1616 int rc1
= 0, rc2
= 0, rc3
= 0;
1618 QETH_CARD_TEXT(card
, 3, "clearchs");
1619 rc1
= qeth_clear_channel(&card
->read
);
1620 rc2
= qeth_clear_channel(&card
->write
);
1621 rc3
= qeth_clear_channel(&card
->data
);
1629 static int qeth_clear_halt_card(struct qeth_card
*card
, int halt
)
1633 QETH_CARD_TEXT(card
, 3, "clhacrd");
1636 rc
= qeth_halt_channels(card
);
1639 return qeth_clear_channels(card
);
1642 int qeth_qdio_clear_card(struct qeth_card
*card
, int use_halt
)
1646 QETH_CARD_TEXT(card
, 3, "qdioclr");
1647 switch (atomic_cmpxchg(&card
->qdio
.state
, QETH_QDIO_ESTABLISHED
,
1648 QETH_QDIO_CLEANING
)) {
1649 case QETH_QDIO_ESTABLISHED
:
1650 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
1651 rc
= qdio_shutdown(CARD_DDEV(card
),
1652 QDIO_FLAG_CLEANUP_USING_HALT
);
1654 rc
= qdio_shutdown(CARD_DDEV(card
),
1655 QDIO_FLAG_CLEANUP_USING_CLEAR
);
1657 QETH_CARD_TEXT_(card
, 3, "1err%d", rc
);
1658 atomic_set(&card
->qdio
.state
, QETH_QDIO_ALLOCATED
);
1660 case QETH_QDIO_CLEANING
:
1665 rc
= qeth_clear_halt_card(card
, use_halt
);
1667 QETH_CARD_TEXT_(card
, 3, "2err%d", rc
);
1668 card
->state
= CARD_STATE_DOWN
;
1671 EXPORT_SYMBOL_GPL(qeth_qdio_clear_card
);
1673 static int qeth_read_conf_data(struct qeth_card
*card
, void **buffer
,
1679 struct qeth_channel
*channel
= &card
->data
;
1680 unsigned long flags
;
1683 * scan for RCD command in extended SenseID data
1685 ciw
= ccw_device_get_ciw(channel
->ccwdev
, CIW_TYPE_RCD
);
1686 if (!ciw
|| ciw
->cmd
== 0)
1688 rcd_buf
= kzalloc(ciw
->count
, GFP_KERNEL
| GFP_DMA
);
1692 channel
->ccw
.cmd_code
= ciw
->cmd
;
1693 channel
->ccw
.cda
= (__u32
) __pa(rcd_buf
);
1694 channel
->ccw
.count
= ciw
->count
;
1695 channel
->ccw
.flags
= CCW_FLAG_SLI
;
1696 channel
->state
= CH_STATE_RCD
;
1697 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1698 ret
= ccw_device_start_timeout(channel
->ccwdev
, &channel
->ccw
,
1699 QETH_RCD_PARM
, LPM_ANYPATH
, 0,
1701 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1703 wait_event(card
->wait_q
,
1704 (channel
->state
== CH_STATE_RCD_DONE
||
1705 channel
->state
== CH_STATE_DOWN
));
1706 if (channel
->state
== CH_STATE_DOWN
)
1709 channel
->state
= CH_STATE_DOWN
;
1715 *length
= ciw
->count
;
1721 static void qeth_configure_unitaddr(struct qeth_card
*card
, char *prcd
)
1723 QETH_DBF_TEXT(SETUP
, 2, "cfgunit");
1724 card
->info
.chpid
= prcd
[30];
1725 card
->info
.unit_addr2
= prcd
[31];
1726 card
->info
.cula
= prcd
[63];
1727 card
->info
.guestlan
= ((prcd
[0x10] == _ascebc
['V']) &&
1728 (prcd
[0x11] == _ascebc
['M']));
1731 static enum qeth_discipline_id
qeth_vm_detect_layer(struct qeth_card
*card
)
1733 enum qeth_discipline_id disc
= QETH_DISCIPLINE_UNDETERMINED
;
1734 struct diag26c_vnic_resp
*response
= NULL
;
1735 struct diag26c_vnic_req
*request
= NULL
;
1736 struct ccw_dev_id id
;
1740 QETH_DBF_TEXT(SETUP
, 2, "vmlayer");
1742 cpcmd("QUERY USERID", userid
, sizeof(userid
), &rc
);
1746 request
= kzalloc(sizeof(*request
), GFP_KERNEL
| GFP_DMA
);
1747 response
= kzalloc(sizeof(*response
), GFP_KERNEL
| GFP_DMA
);
1748 if (!request
|| !response
) {
1753 ccw_device_get_id(CARD_RDEV(card
), &id
);
1754 request
->resp_buf_len
= sizeof(*response
);
1755 request
->resp_version
= DIAG26C_VERSION6_VM65918
;
1756 request
->req_format
= DIAG26C_VNIC_INFO
;
1758 memcpy(&request
->sys_name
, userid
, 8);
1759 request
->devno
= id
.devno
;
1761 QETH_DBF_HEX(CTRL
, 2, request
, sizeof(*request
));
1762 rc
= diag26c(request
, response
, DIAG26C_PORT_VNIC
);
1763 QETH_DBF_HEX(CTRL
, 2, request
, sizeof(*request
));
1766 QETH_DBF_HEX(CTRL
, 2, response
, sizeof(*response
));
1768 if (request
->resp_buf_len
< sizeof(*response
) ||
1769 response
->version
!= request
->resp_version
) {
1774 if (response
->protocol
== VNIC_INFO_PROT_L2
)
1775 disc
= QETH_DISCIPLINE_LAYER2
;
1776 else if (response
->protocol
== VNIC_INFO_PROT_L3
)
1777 disc
= QETH_DISCIPLINE_LAYER3
;
1783 QETH_DBF_TEXT_(SETUP
, 2, "err%x", rc
);
1787 /* Determine whether the device requires a specific layer discipline */
1788 static enum qeth_discipline_id
qeth_enforce_discipline(struct qeth_card
*card
)
1790 enum qeth_discipline_id disc
= QETH_DISCIPLINE_UNDETERMINED
;
1792 if (card
->info
.type
== QETH_CARD_TYPE_OSM
||
1793 card
->info
.type
== QETH_CARD_TYPE_OSN
)
1794 disc
= QETH_DISCIPLINE_LAYER2
;
1795 else if (card
->info
.guestlan
)
1796 disc
= (card
->info
.type
== QETH_CARD_TYPE_IQD
) ?
1797 QETH_DISCIPLINE_LAYER3
:
1798 qeth_vm_detect_layer(card
);
1801 case QETH_DISCIPLINE_LAYER2
:
1802 QETH_DBF_TEXT(SETUP
, 3, "force l2");
1804 case QETH_DISCIPLINE_LAYER3
:
1805 QETH_DBF_TEXT(SETUP
, 3, "force l3");
1808 QETH_DBF_TEXT(SETUP
, 3, "force no");
1814 static void qeth_configure_blkt_default(struct qeth_card
*card
, char *prcd
)
1816 QETH_DBF_TEXT(SETUP
, 2, "cfgblkt");
1818 if (prcd
[74] == 0xF0 && prcd
[75] == 0xF0 &&
1819 prcd
[76] >= 0xF1 && prcd
[76] <= 0xF4) {
1820 card
->info
.blkt
.time_total
= 0;
1821 card
->info
.blkt
.inter_packet
= 0;
1822 card
->info
.blkt
.inter_packet_jumbo
= 0;
1824 card
->info
.blkt
.time_total
= 250;
1825 card
->info
.blkt
.inter_packet
= 5;
1826 card
->info
.blkt
.inter_packet_jumbo
= 15;
1830 static void qeth_init_tokens(struct qeth_card
*card
)
1832 card
->token
.issuer_rm_w
= 0x00010103UL
;
1833 card
->token
.cm_filter_w
= 0x00010108UL
;
1834 card
->token
.cm_connection_w
= 0x0001010aUL
;
1835 card
->token
.ulp_filter_w
= 0x0001010bUL
;
1836 card
->token
.ulp_connection_w
= 0x0001010dUL
;
1839 static void qeth_init_func_level(struct qeth_card
*card
)
1841 switch (card
->info
.type
) {
1842 case QETH_CARD_TYPE_IQD
:
1843 card
->info
.func_level
= QETH_IDX_FUNC_LEVEL_IQD
;
1845 case QETH_CARD_TYPE_OSD
:
1846 case QETH_CARD_TYPE_OSN
:
1847 card
->info
.func_level
= QETH_IDX_FUNC_LEVEL_OSD
;
1854 static int qeth_idx_activate_get_answer(struct qeth_channel
*channel
,
1855 void (*idx_reply_cb
)(struct qeth_channel
*,
1856 struct qeth_cmd_buffer
*))
1858 struct qeth_cmd_buffer
*iob
;
1859 unsigned long flags
;
1861 struct qeth_card
*card
;
1863 QETH_DBF_TEXT(SETUP
, 2, "idxanswr");
1864 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1865 iob
= qeth_get_buffer(channel
);
1868 iob
->callback
= idx_reply_cb
;
1869 memcpy(&channel
->ccw
, READ_CCW
, sizeof(struct ccw1
));
1870 channel
->ccw
.count
= QETH_BUFSIZE
;
1871 channel
->ccw
.cda
= (__u32
) __pa(iob
->data
);
1873 wait_event(card
->wait_q
,
1874 atomic_cmpxchg(&channel
->irq_pending
, 0, 1) == 0);
1875 QETH_DBF_TEXT(SETUP
, 6, "noirqpnd");
1876 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1877 rc
= ccw_device_start_timeout(channel
->ccwdev
, &channel
->ccw
,
1878 (addr_t
) iob
, 0, 0, QETH_TIMEOUT
);
1879 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1882 QETH_DBF_MESSAGE(2, "Error2 in activating channel rc=%d\n", rc
);
1883 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
1884 atomic_set(&channel
->irq_pending
, 0);
1885 wake_up(&card
->wait_q
);
1888 rc
= wait_event_interruptible_timeout(card
->wait_q
,
1889 channel
->state
== CH_STATE_UP
, QETH_TIMEOUT
);
1890 if (rc
== -ERESTARTSYS
)
1892 if (channel
->state
!= CH_STATE_UP
) {
1894 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
1900 static int qeth_idx_activate_channel(struct qeth_channel
*channel
,
1901 void (*idx_reply_cb
)(struct qeth_channel
*,
1902 struct qeth_cmd_buffer
*))
1904 struct qeth_card
*card
;
1905 struct qeth_cmd_buffer
*iob
;
1906 unsigned long flags
;
1910 struct ccw_dev_id temp_devid
;
1912 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1914 QETH_DBF_TEXT(SETUP
, 2, "idxactch");
1916 iob
= qeth_get_buffer(channel
);
1919 iob
->callback
= idx_reply_cb
;
1920 memcpy(&channel
->ccw
, WRITE_CCW
, sizeof(struct ccw1
));
1921 channel
->ccw
.count
= IDX_ACTIVATE_SIZE
;
1922 channel
->ccw
.cda
= (__u32
) __pa(iob
->data
);
1923 if (channel
== &card
->write
) {
1924 memcpy(iob
->data
, IDX_ACTIVATE_WRITE
, IDX_ACTIVATE_SIZE
);
1925 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob
->data
),
1926 &card
->seqno
.trans_hdr
, QETH_SEQ_NO_LENGTH
);
1927 card
->seqno
.trans_hdr
++;
1929 memcpy(iob
->data
, IDX_ACTIVATE_READ
, IDX_ACTIVATE_SIZE
);
1930 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob
->data
),
1931 &card
->seqno
.trans_hdr
, QETH_SEQ_NO_LENGTH
);
1933 tmp
= ((__u8
)card
->info
.portno
) | 0x80;
1934 memcpy(QETH_IDX_ACT_PNO(iob
->data
), &tmp
, 1);
1935 memcpy(QETH_IDX_ACT_ISSUER_RM_TOKEN(iob
->data
),
1936 &card
->token
.issuer_rm_w
, QETH_MPC_TOKEN_LENGTH
);
1937 memcpy(QETH_IDX_ACT_FUNC_LEVEL(iob
->data
),
1938 &card
->info
.func_level
, sizeof(__u16
));
1939 ccw_device_get_id(CARD_DDEV(card
), &temp_devid
);
1940 memcpy(QETH_IDX_ACT_QDIO_DEV_CUA(iob
->data
), &temp_devid
.devno
, 2);
1941 temp
= (card
->info
.cula
<< 8) + card
->info
.unit_addr2
;
1942 memcpy(QETH_IDX_ACT_QDIO_DEV_REALADDR(iob
->data
), &temp
, 2);
1944 wait_event(card
->wait_q
,
1945 atomic_cmpxchg(&channel
->irq_pending
, 0, 1) == 0);
1946 QETH_DBF_TEXT(SETUP
, 6, "noirqpnd");
1947 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1948 rc
= ccw_device_start_timeout(channel
->ccwdev
, &channel
->ccw
,
1949 (addr_t
) iob
, 0, 0, QETH_TIMEOUT
);
1950 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1953 QETH_DBF_MESSAGE(2, "Error1 in activating channel. rc=%d\n",
1955 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
1956 atomic_set(&channel
->irq_pending
, 0);
1957 wake_up(&card
->wait_q
);
1960 rc
= wait_event_interruptible_timeout(card
->wait_q
,
1961 channel
->state
== CH_STATE_ACTIVATING
, QETH_TIMEOUT
);
1962 if (rc
== -ERESTARTSYS
)
1964 if (channel
->state
!= CH_STATE_ACTIVATING
) {
1965 dev_warn(&channel
->ccwdev
->dev
, "The qeth device driver"
1966 " failed to recover an error on the device\n");
1967 QETH_DBF_MESSAGE(2, "%s IDX activate timed out\n",
1968 dev_name(&channel
->ccwdev
->dev
));
1969 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", -ETIME
);
1972 return qeth_idx_activate_get_answer(channel
, idx_reply_cb
);
1975 static int qeth_peer_func_level(int level
)
1977 if ((level
& 0xff) == 8)
1978 return (level
& 0xff) + 0x400;
1979 if (((level
>> 8) & 3) == 1)
1980 return (level
& 0xff) + 0x200;
1984 static void qeth_idx_write_cb(struct qeth_channel
*channel
,
1985 struct qeth_cmd_buffer
*iob
)
1987 struct qeth_card
*card
;
1990 QETH_DBF_TEXT(SETUP
, 2, "idxwrcb");
1992 if (channel
->state
== CH_STATE_DOWN
) {
1993 channel
->state
= CH_STATE_ACTIVATING
;
1996 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1998 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob
->data
))) {
1999 if (QETH_IDX_ACT_CAUSE_CODE(iob
->data
) == QETH_IDX_ACT_ERR_EXCL
)
2000 dev_err(&card
->write
.ccwdev
->dev
,
2001 "The adapter is used exclusively by another "
2004 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on write channel:"
2005 " negative reply\n",
2006 dev_name(&card
->write
.ccwdev
->dev
));
2009 memcpy(&temp
, QETH_IDX_ACT_FUNC_LEVEL(iob
->data
), 2);
2010 if ((temp
& ~0x0100) != qeth_peer_func_level(card
->info
.func_level
)) {
2011 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on write channel: "
2012 "function level mismatch (sent: 0x%x, received: "
2013 "0x%x)\n", dev_name(&card
->write
.ccwdev
->dev
),
2014 card
->info
.func_level
, temp
);
2017 channel
->state
= CH_STATE_UP
;
2019 qeth_release_buffer(channel
, iob
);
2022 static void qeth_idx_read_cb(struct qeth_channel
*channel
,
2023 struct qeth_cmd_buffer
*iob
)
2025 struct qeth_card
*card
;
2028 QETH_DBF_TEXT(SETUP
, 2, "idxrdcb");
2029 if (channel
->state
== CH_STATE_DOWN
) {
2030 channel
->state
= CH_STATE_ACTIVATING
;
2034 card
= CARD_FROM_CDEV(channel
->ccwdev
);
2035 if (qeth_check_idx_response(card
, iob
->data
))
2038 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob
->data
))) {
2039 switch (QETH_IDX_ACT_CAUSE_CODE(iob
->data
)) {
2040 case QETH_IDX_ACT_ERR_EXCL
:
2041 dev_err(&card
->write
.ccwdev
->dev
,
2042 "The adapter is used exclusively by another "
2045 case QETH_IDX_ACT_ERR_AUTH
:
2046 case QETH_IDX_ACT_ERR_AUTH_USER
:
2047 dev_err(&card
->read
.ccwdev
->dev
,
2048 "Setting the device online failed because of "
2049 "insufficient authorization\n");
2052 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on read channel:"
2053 " negative reply\n",
2054 dev_name(&card
->read
.ccwdev
->dev
));
2056 QETH_CARD_TEXT_(card
, 2, "idxread%c",
2057 QETH_IDX_ACT_CAUSE_CODE(iob
->data
));
2061 memcpy(&temp
, QETH_IDX_ACT_FUNC_LEVEL(iob
->data
), 2);
2062 if (temp
!= qeth_peer_func_level(card
->info
.func_level
)) {
2063 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on read channel: function "
2064 "level mismatch (sent: 0x%x, received: 0x%x)\n",
2065 dev_name(&card
->read
.ccwdev
->dev
),
2066 card
->info
.func_level
, temp
);
2069 memcpy(&card
->token
.issuer_rm_r
,
2070 QETH_IDX_ACT_ISSUER_RM_TOKEN(iob
->data
),
2071 QETH_MPC_TOKEN_LENGTH
);
2072 memcpy(&card
->info
.mcl_level
[0],
2073 QETH_IDX_REPLY_LEVEL(iob
->data
), QETH_MCL_LENGTH
);
2074 channel
->state
= CH_STATE_UP
;
2076 qeth_release_buffer(channel
, iob
);
2079 void qeth_prepare_control_data(struct qeth_card
*card
, int len
,
2080 struct qeth_cmd_buffer
*iob
)
2082 qeth_setup_ccw(&card
->write
, iob
->data
, len
);
2083 iob
->callback
= qeth_release_buffer
;
2085 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob
->data
),
2086 &card
->seqno
.trans_hdr
, QETH_SEQ_NO_LENGTH
);
2087 card
->seqno
.trans_hdr
++;
2088 memcpy(QETH_PDU_HEADER_SEQ_NO(iob
->data
),
2089 &card
->seqno
.pdu_hdr
, QETH_SEQ_NO_LENGTH
);
2090 card
->seqno
.pdu_hdr
++;
2091 memcpy(QETH_PDU_HEADER_ACK_SEQ_NO(iob
->data
),
2092 &card
->seqno
.pdu_hdr_ack
, QETH_SEQ_NO_LENGTH
);
2093 QETH_DBF_HEX(CTRL
, 2, iob
->data
, QETH_DBF_CTRL_LEN
);
2095 EXPORT_SYMBOL_GPL(qeth_prepare_control_data
);
2098 * qeth_send_control_data() - send control command to the card
2099 * @card: qeth_card structure pointer
2100 * @len: size of the command buffer
2101 * @iob: qeth_cmd_buffer pointer
2102 * @reply_cb: callback function pointer
2103 * @cb_card: pointer to the qeth_card structure
2104 * @cb_reply: pointer to the qeth_reply structure
2105 * @cb_cmd: pointer to the original iob for non-IPA
2106 * commands, or to the qeth_ipa_cmd structure
2107 * for the IPA commands.
2108 * @reply_param: private pointer passed to the callback
2110 * Returns the value of the `return_code' field of the response
2111 * block returned from the hardware, or other error indication.
2112 * Value of zero indicates successful execution of the command.
2114 * Callback function gets called one or more times, with cb_cmd
2115 * pointing to the response returned by the hardware. Callback
2116 * function must return non-zero if more reply blocks are expected,
2117 * and zero if the last or only reply block is received. Callback
2118 * function can get the value of the reply_param pointer from the
2119 * field 'param' of the structure qeth_reply.
2122 int qeth_send_control_data(struct qeth_card
*card
, int len
,
2123 struct qeth_cmd_buffer
*iob
,
2124 int (*reply_cb
)(struct qeth_card
*cb_card
,
2125 struct qeth_reply
*cb_reply
,
2126 unsigned long cb_cmd
),
2130 unsigned long flags
;
2131 struct qeth_reply
*reply
= NULL
;
2132 unsigned long timeout
, event_timeout
;
2133 struct qeth_ipa_cmd
*cmd
= NULL
;
2135 QETH_CARD_TEXT(card
, 2, "sendctl");
2137 if (card
->read_or_write_problem
) {
2138 qeth_release_buffer(iob
->channel
, iob
);
2141 reply
= qeth_alloc_reply(card
);
2145 reply
->callback
= reply_cb
;
2146 reply
->param
= reply_param
;
2148 init_waitqueue_head(&reply
->wait_q
);
2150 while (atomic_cmpxchg(&card
->write
.irq_pending
, 0, 1)) ;
2152 if (IS_IPA(iob
->data
)) {
2153 cmd
= __ipa_cmd(iob
);
2154 cmd
->hdr
.seqno
= card
->seqno
.ipa
++;
2155 reply
->seqno
= cmd
->hdr
.seqno
;
2156 event_timeout
= QETH_IPA_TIMEOUT
;
2158 reply
->seqno
= QETH_IDX_COMMAND_SEQNO
;
2159 event_timeout
= QETH_TIMEOUT
;
2161 qeth_prepare_control_data(card
, len
, iob
);
2163 spin_lock_irqsave(&card
->lock
, flags
);
2164 list_add_tail(&reply
->list
, &card
->cmd_waiter_list
);
2165 spin_unlock_irqrestore(&card
->lock
, flags
);
2167 timeout
= jiffies
+ event_timeout
;
2169 QETH_CARD_TEXT(card
, 6, "noirqpnd");
2170 spin_lock_irqsave(get_ccwdev_lock(card
->write
.ccwdev
), flags
);
2171 rc
= ccw_device_start_timeout(CARD_WDEV(card
), &card
->write
.ccw
,
2172 (addr_t
) iob
, 0, 0, event_timeout
);
2173 spin_unlock_irqrestore(get_ccwdev_lock(card
->write
.ccwdev
), flags
);
2175 QETH_DBF_MESSAGE(2, "%s qeth_send_control_data: "
2176 "ccw_device_start rc = %i\n",
2177 dev_name(&card
->write
.ccwdev
->dev
), rc
);
2178 QETH_CARD_TEXT_(card
, 2, " err%d", rc
);
2179 spin_lock_irqsave(&card
->lock
, flags
);
2180 list_del_init(&reply
->list
);
2181 qeth_put_reply(reply
);
2182 spin_unlock_irqrestore(&card
->lock
, flags
);
2183 qeth_release_buffer(iob
->channel
, iob
);
2184 atomic_set(&card
->write
.irq_pending
, 0);
2185 wake_up(&card
->wait_q
);
2189 /* we have only one long running ipassist, since we can ensure
2190 process context of this command we can sleep */
2191 if (cmd
&& cmd
->hdr
.command
== IPA_CMD_SETIP
&&
2192 cmd
->hdr
.prot_version
== QETH_PROT_IPV4
) {
2193 if (!wait_event_timeout(reply
->wait_q
,
2194 atomic_read(&reply
->received
), event_timeout
))
2197 while (!atomic_read(&reply
->received
)) {
2198 if (time_after(jiffies
, timeout
))
2205 qeth_put_reply(reply
);
2210 spin_lock_irqsave(&reply
->card
->lock
, flags
);
2211 list_del_init(&reply
->list
);
2212 spin_unlock_irqrestore(&reply
->card
->lock
, flags
);
2213 atomic_inc(&reply
->received
);
2215 qeth_put_reply(reply
);
2218 EXPORT_SYMBOL_GPL(qeth_send_control_data
);
2220 static int qeth_cm_enable_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
2223 struct qeth_cmd_buffer
*iob
;
2225 QETH_DBF_TEXT(SETUP
, 2, "cmenblcb");
2227 iob
= (struct qeth_cmd_buffer
*) data
;
2228 memcpy(&card
->token
.cm_filter_r
,
2229 QETH_CM_ENABLE_RESP_FILTER_TOKEN(iob
->data
),
2230 QETH_MPC_TOKEN_LENGTH
);
2231 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
2235 static int qeth_cm_enable(struct qeth_card
*card
)
2238 struct qeth_cmd_buffer
*iob
;
2240 QETH_DBF_TEXT(SETUP
, 2, "cmenable");
2242 iob
= qeth_wait_for_buffer(&card
->write
);
2243 memcpy(iob
->data
, CM_ENABLE
, CM_ENABLE_SIZE
);
2244 memcpy(QETH_CM_ENABLE_ISSUER_RM_TOKEN(iob
->data
),
2245 &card
->token
.issuer_rm_r
, QETH_MPC_TOKEN_LENGTH
);
2246 memcpy(QETH_CM_ENABLE_FILTER_TOKEN(iob
->data
),
2247 &card
->token
.cm_filter_w
, QETH_MPC_TOKEN_LENGTH
);
2249 rc
= qeth_send_control_data(card
, CM_ENABLE_SIZE
, iob
,
2250 qeth_cm_enable_cb
, NULL
);
2254 static int qeth_cm_setup_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
2258 struct qeth_cmd_buffer
*iob
;
2260 QETH_DBF_TEXT(SETUP
, 2, "cmsetpcb");
2262 iob
= (struct qeth_cmd_buffer
*) data
;
2263 memcpy(&card
->token
.cm_connection_r
,
2264 QETH_CM_SETUP_RESP_DEST_ADDR(iob
->data
),
2265 QETH_MPC_TOKEN_LENGTH
);
2266 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
2270 static int qeth_cm_setup(struct qeth_card
*card
)
2273 struct qeth_cmd_buffer
*iob
;
2275 QETH_DBF_TEXT(SETUP
, 2, "cmsetup");
2277 iob
= qeth_wait_for_buffer(&card
->write
);
2278 memcpy(iob
->data
, CM_SETUP
, CM_SETUP_SIZE
);
2279 memcpy(QETH_CM_SETUP_DEST_ADDR(iob
->data
),
2280 &card
->token
.issuer_rm_r
, QETH_MPC_TOKEN_LENGTH
);
2281 memcpy(QETH_CM_SETUP_CONNECTION_TOKEN(iob
->data
),
2282 &card
->token
.cm_connection_w
, QETH_MPC_TOKEN_LENGTH
);
2283 memcpy(QETH_CM_SETUP_FILTER_TOKEN(iob
->data
),
2284 &card
->token
.cm_filter_r
, QETH_MPC_TOKEN_LENGTH
);
2285 rc
= qeth_send_control_data(card
, CM_SETUP_SIZE
, iob
,
2286 qeth_cm_setup_cb
, NULL
);
2291 static int qeth_get_initial_mtu_for_card(struct qeth_card
*card
)
2293 switch (card
->info
.type
) {
2294 case QETH_CARD_TYPE_IQD
:
2295 return card
->info
.max_mtu
;
2296 case QETH_CARD_TYPE_OSD
:
2297 case QETH_CARD_TYPE_OSX
:
2298 if (!card
->options
.layer2
)
2299 return ETH_DATA_LEN
- 8; /* L3: allow for LLC + SNAP */
2302 return ETH_DATA_LEN
;
2306 static int qeth_get_mtu_outof_framesize(int framesize
)
2308 switch (framesize
) {
2322 static int qeth_mtu_is_valid(struct qeth_card
*card
, int mtu
)
2324 switch (card
->info
.type
) {
2325 case QETH_CARD_TYPE_OSD
:
2326 case QETH_CARD_TYPE_OSM
:
2327 case QETH_CARD_TYPE_OSX
:
2328 case QETH_CARD_TYPE_IQD
:
2329 return ((mtu
>= 576) &&
2330 (mtu
<= card
->info
.max_mtu
));
2331 case QETH_CARD_TYPE_OSN
:
2337 static int qeth_ulp_enable_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
2341 __u16 mtu
, framesize
;
2344 struct qeth_cmd_buffer
*iob
;
2346 QETH_DBF_TEXT(SETUP
, 2, "ulpenacb");
2348 iob
= (struct qeth_cmd_buffer
*) data
;
2349 memcpy(&card
->token
.ulp_filter_r
,
2350 QETH_ULP_ENABLE_RESP_FILTER_TOKEN(iob
->data
),
2351 QETH_MPC_TOKEN_LENGTH
);
2352 if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
2353 memcpy(&framesize
, QETH_ULP_ENABLE_RESP_MAX_MTU(iob
->data
), 2);
2354 mtu
= qeth_get_mtu_outof_framesize(framesize
);
2357 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
2360 if (card
->info
.initial_mtu
&& (card
->info
.initial_mtu
!= mtu
)) {
2361 /* frame size has changed */
2363 ((card
->dev
->mtu
== card
->info
.initial_mtu
) ||
2364 (card
->dev
->mtu
> mtu
)))
2365 card
->dev
->mtu
= mtu
;
2366 qeth_free_qdio_buffers(card
);
2368 card
->info
.initial_mtu
= mtu
;
2369 card
->info
.max_mtu
= mtu
;
2370 card
->qdio
.in_buf_size
= mtu
+ 2 * PAGE_SIZE
;
2372 card
->info
.max_mtu
= *(__u16
*)QETH_ULP_ENABLE_RESP_MAX_MTU(
2374 card
->info
.initial_mtu
= min(card
->info
.max_mtu
,
2375 qeth_get_initial_mtu_for_card(card
));
2376 card
->qdio
.in_buf_size
= QETH_IN_BUF_SIZE_DEFAULT
;
2379 memcpy(&len
, QETH_ULP_ENABLE_RESP_DIFINFO_LEN(iob
->data
), 2);
2380 if (len
>= QETH_MPC_DIFINFO_LEN_INDICATES_LINK_TYPE
) {
2382 QETH_ULP_ENABLE_RESP_LINK_TYPE(iob
->data
), 1);
2383 card
->info
.link_type
= link_type
;
2385 card
->info
.link_type
= 0;
2386 QETH_DBF_TEXT_(SETUP
, 2, "link%d", card
->info
.link_type
);
2387 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
2391 static int qeth_ulp_enable(struct qeth_card
*card
)
2395 struct qeth_cmd_buffer
*iob
;
2397 /*FIXME: trace view callbacks*/
2398 QETH_DBF_TEXT(SETUP
, 2, "ulpenabl");
2400 iob
= qeth_wait_for_buffer(&card
->write
);
2401 memcpy(iob
->data
, ULP_ENABLE
, ULP_ENABLE_SIZE
);
2403 *(QETH_ULP_ENABLE_LINKNUM(iob
->data
)) =
2404 (__u8
) card
->info
.portno
;
2405 if (card
->options
.layer2
)
2406 if (card
->info
.type
== QETH_CARD_TYPE_OSN
)
2407 prot_type
= QETH_PROT_OSN2
;
2409 prot_type
= QETH_PROT_LAYER2
;
2411 prot_type
= QETH_PROT_TCPIP
;
2413 memcpy(QETH_ULP_ENABLE_PROT_TYPE(iob
->data
), &prot_type
, 1);
2414 memcpy(QETH_ULP_ENABLE_DEST_ADDR(iob
->data
),
2415 &card
->token
.cm_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2416 memcpy(QETH_ULP_ENABLE_FILTER_TOKEN(iob
->data
),
2417 &card
->token
.ulp_filter_w
, QETH_MPC_TOKEN_LENGTH
);
2418 rc
= qeth_send_control_data(card
, ULP_ENABLE_SIZE
, iob
,
2419 qeth_ulp_enable_cb
, NULL
);
2424 static int qeth_ulp_setup_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
2427 struct qeth_cmd_buffer
*iob
;
2429 QETH_DBF_TEXT(SETUP
, 2, "ulpstpcb");
2431 iob
= (struct qeth_cmd_buffer
*) data
;
2432 memcpy(&card
->token
.ulp_connection_r
,
2433 QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob
->data
),
2434 QETH_MPC_TOKEN_LENGTH
);
2435 if (!strncmp("00S", QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob
->data
),
2437 QETH_DBF_TEXT(SETUP
, 2, "olmlimit");
2438 dev_err(&card
->gdev
->dev
, "A connection could not be "
2439 "established because of an OLM limit\n");
2442 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
2446 static int qeth_ulp_setup(struct qeth_card
*card
)
2450 struct qeth_cmd_buffer
*iob
;
2451 struct ccw_dev_id dev_id
;
2453 QETH_DBF_TEXT(SETUP
, 2, "ulpsetup");
2455 iob
= qeth_wait_for_buffer(&card
->write
);
2456 memcpy(iob
->data
, ULP_SETUP
, ULP_SETUP_SIZE
);
2458 memcpy(QETH_ULP_SETUP_DEST_ADDR(iob
->data
),
2459 &card
->token
.cm_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2460 memcpy(QETH_ULP_SETUP_CONNECTION_TOKEN(iob
->data
),
2461 &card
->token
.ulp_connection_w
, QETH_MPC_TOKEN_LENGTH
);
2462 memcpy(QETH_ULP_SETUP_FILTER_TOKEN(iob
->data
),
2463 &card
->token
.ulp_filter_r
, QETH_MPC_TOKEN_LENGTH
);
2465 ccw_device_get_id(CARD_DDEV(card
), &dev_id
);
2466 memcpy(QETH_ULP_SETUP_CUA(iob
->data
), &dev_id
.devno
, 2);
2467 temp
= (card
->info
.cula
<< 8) + card
->info
.unit_addr2
;
2468 memcpy(QETH_ULP_SETUP_REAL_DEVADDR(iob
->data
), &temp
, 2);
2469 rc
= qeth_send_control_data(card
, ULP_SETUP_SIZE
, iob
,
2470 qeth_ulp_setup_cb
, NULL
);
2474 static int qeth_init_qdio_out_buf(struct qeth_qdio_out_q
*q
, int bidx
)
2477 struct qeth_qdio_out_buffer
*newbuf
;
2480 newbuf
= kmem_cache_zalloc(qeth_qdio_outbuf_cache
, GFP_ATOMIC
);
2485 newbuf
->buffer
= q
->qdio_bufs
[bidx
];
2486 skb_queue_head_init(&newbuf
->skb_list
);
2487 lockdep_set_class(&newbuf
->skb_list
.lock
, &qdio_out_skb_queue_key
);
2490 newbuf
->next_pending
= q
->bufs
[bidx
];
2491 atomic_set(&newbuf
->state
, QETH_QDIO_BUF_EMPTY
);
2492 q
->bufs
[bidx
] = newbuf
;
2494 q
->bufstates
[bidx
].user
= newbuf
;
2495 QETH_CARD_TEXT_(q
->card
, 2, "nbs%d", bidx
);
2496 QETH_CARD_TEXT_(q
->card
, 2, "%lx", (long) newbuf
);
2497 QETH_CARD_TEXT_(q
->card
, 2, "%lx",
2498 (long) newbuf
->next_pending
);
2504 static void qeth_free_qdio_out_buf(struct qeth_qdio_out_q
*q
)
2509 qdio_free_buffers(q
->qdio_bufs
, QDIO_MAX_BUFFERS_PER_Q
);
2513 static struct qeth_qdio_out_q
*qeth_alloc_qdio_out_buf(void)
2515 struct qeth_qdio_out_q
*q
= kzalloc(sizeof(*q
), GFP_KERNEL
);
2520 if (qdio_alloc_buffers(q
->qdio_bufs
, QDIO_MAX_BUFFERS_PER_Q
)) {
2527 static int qeth_alloc_qdio_buffers(struct qeth_card
*card
)
2531 QETH_DBF_TEXT(SETUP
, 2, "allcqdbf");
2533 if (atomic_cmpxchg(&card
->qdio
.state
, QETH_QDIO_UNINITIALIZED
,
2534 QETH_QDIO_ALLOCATED
) != QETH_QDIO_UNINITIALIZED
)
2537 QETH_DBF_TEXT(SETUP
, 2, "inq");
2538 card
->qdio
.in_q
= qeth_alloc_qdio_queue();
2539 if (!card
->qdio
.in_q
)
2542 /* inbound buffer pool */
2543 if (qeth_alloc_buffer_pool(card
))
2548 kcalloc(card
->qdio
.no_out_queues
,
2549 sizeof(struct qeth_qdio_out_q
*),
2551 if (!card
->qdio
.out_qs
)
2553 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
2554 card
->qdio
.out_qs
[i
] = qeth_alloc_qdio_out_buf();
2555 if (!card
->qdio
.out_qs
[i
])
2557 QETH_DBF_TEXT_(SETUP
, 2, "outq %i", i
);
2558 QETH_DBF_HEX(SETUP
, 2, &card
->qdio
.out_qs
[i
], sizeof(void *));
2559 card
->qdio
.out_qs
[i
]->queue_no
= i
;
2560 /* give outbound qeth_qdio_buffers their qdio_buffers */
2561 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
) {
2562 WARN_ON(card
->qdio
.out_qs
[i
]->bufs
[j
] != NULL
);
2563 if (qeth_init_qdio_out_buf(card
->qdio
.out_qs
[i
], j
))
2564 goto out_freeoutqbufs
;
2569 if (qeth_alloc_cq(card
))
2577 kmem_cache_free(qeth_qdio_outbuf_cache
,
2578 card
->qdio
.out_qs
[i
]->bufs
[j
]);
2579 card
->qdio
.out_qs
[i
]->bufs
[j
] = NULL
;
2583 qeth_free_qdio_out_buf(card
->qdio
.out_qs
[--i
]);
2584 qeth_clear_outq_buffers(card
->qdio
.out_qs
[i
], 1);
2586 kfree(card
->qdio
.out_qs
);
2587 card
->qdio
.out_qs
= NULL
;
2589 qeth_free_buffer_pool(card
);
2591 qeth_free_qdio_queue(card
->qdio
.in_q
);
2592 card
->qdio
.in_q
= NULL
;
2594 atomic_set(&card
->qdio
.state
, QETH_QDIO_UNINITIALIZED
);
2598 static void qeth_free_qdio_buffers(struct qeth_card
*card
)
2602 if (atomic_xchg(&card
->qdio
.state
, QETH_QDIO_UNINITIALIZED
) ==
2603 QETH_QDIO_UNINITIALIZED
)
2607 cancel_delayed_work_sync(&card
->buffer_reclaim_work
);
2608 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
) {
2609 if (card
->qdio
.in_q
->bufs
[j
].rx_skb
)
2610 dev_kfree_skb_any(card
->qdio
.in_q
->bufs
[j
].rx_skb
);
2612 qeth_free_qdio_queue(card
->qdio
.in_q
);
2613 card
->qdio
.in_q
= NULL
;
2614 /* inbound buffer pool */
2615 qeth_free_buffer_pool(card
);
2616 /* free outbound qdio_qs */
2617 if (card
->qdio
.out_qs
) {
2618 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
2619 qeth_clear_outq_buffers(card
->qdio
.out_qs
[i
], 1);
2620 qeth_free_qdio_out_buf(card
->qdio
.out_qs
[i
]);
2622 kfree(card
->qdio
.out_qs
);
2623 card
->qdio
.out_qs
= NULL
;
2627 static void qeth_create_qib_param_field(struct qeth_card
*card
,
2631 param_field
[0] = _ascebc
['P'];
2632 param_field
[1] = _ascebc
['C'];
2633 param_field
[2] = _ascebc
['I'];
2634 param_field
[3] = _ascebc
['T'];
2635 *((unsigned int *) (¶m_field
[4])) = QETH_PCI_THRESHOLD_A(card
);
2636 *((unsigned int *) (¶m_field
[8])) = QETH_PCI_THRESHOLD_B(card
);
2637 *((unsigned int *) (¶m_field
[12])) = QETH_PCI_TIMER_VALUE(card
);
2640 static void qeth_create_qib_param_field_blkt(struct qeth_card
*card
,
2643 param_field
[16] = _ascebc
['B'];
2644 param_field
[17] = _ascebc
['L'];
2645 param_field
[18] = _ascebc
['K'];
2646 param_field
[19] = _ascebc
['T'];
2647 *((unsigned int *) (¶m_field
[20])) = card
->info
.blkt
.time_total
;
2648 *((unsigned int *) (¶m_field
[24])) = card
->info
.blkt
.inter_packet
;
2649 *((unsigned int *) (¶m_field
[28])) =
2650 card
->info
.blkt
.inter_packet_jumbo
;
2653 static int qeth_qdio_activate(struct qeth_card
*card
)
2655 QETH_DBF_TEXT(SETUP
, 3, "qdioact");
2656 return qdio_activate(CARD_DDEV(card
));
2659 static int qeth_dm_act(struct qeth_card
*card
)
2662 struct qeth_cmd_buffer
*iob
;
2664 QETH_DBF_TEXT(SETUP
, 2, "dmact");
2666 iob
= qeth_wait_for_buffer(&card
->write
);
2667 memcpy(iob
->data
, DM_ACT
, DM_ACT_SIZE
);
2669 memcpy(QETH_DM_ACT_DEST_ADDR(iob
->data
),
2670 &card
->token
.cm_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2671 memcpy(QETH_DM_ACT_CONNECTION_TOKEN(iob
->data
),
2672 &card
->token
.ulp_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2673 rc
= qeth_send_control_data(card
, DM_ACT_SIZE
, iob
, NULL
, NULL
);
2677 static int qeth_mpc_initialize(struct qeth_card
*card
)
2681 QETH_DBF_TEXT(SETUP
, 2, "mpcinit");
2683 rc
= qeth_issue_next_read(card
);
2685 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
2688 rc
= qeth_cm_enable(card
);
2690 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
2693 rc
= qeth_cm_setup(card
);
2695 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
2698 rc
= qeth_ulp_enable(card
);
2700 QETH_DBF_TEXT_(SETUP
, 2, "4err%d", rc
);
2703 rc
= qeth_ulp_setup(card
);
2705 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
2708 rc
= qeth_alloc_qdio_buffers(card
);
2710 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
2713 rc
= qeth_qdio_establish(card
);
2715 QETH_DBF_TEXT_(SETUP
, 2, "6err%d", rc
);
2716 qeth_free_qdio_buffers(card
);
2719 rc
= qeth_qdio_activate(card
);
2721 QETH_DBF_TEXT_(SETUP
, 2, "7err%d", rc
);
2724 rc
= qeth_dm_act(card
);
2726 QETH_DBF_TEXT_(SETUP
, 2, "8err%d", rc
);
2732 qeth_qdio_clear_card(card
, card
->info
.type
!= QETH_CARD_TYPE_IQD
);
2733 qdio_free(CARD_DDEV(card
));
2737 void qeth_print_status_message(struct qeth_card
*card
)
2739 switch (card
->info
.type
) {
2740 case QETH_CARD_TYPE_OSD
:
2741 case QETH_CARD_TYPE_OSM
:
2742 case QETH_CARD_TYPE_OSX
:
2743 /* VM will use a non-zero first character
2744 * to indicate a HiperSockets like reporting
2745 * of the level OSA sets the first character to zero
2747 if (!card
->info
.mcl_level
[0]) {
2748 sprintf(card
->info
.mcl_level
, "%02x%02x",
2749 card
->info
.mcl_level
[2],
2750 card
->info
.mcl_level
[3]);
2754 case QETH_CARD_TYPE_IQD
:
2755 if ((card
->info
.guestlan
) ||
2756 (card
->info
.mcl_level
[0] & 0x80)) {
2757 card
->info
.mcl_level
[0] = (char) _ebcasc
[(__u8
)
2758 card
->info
.mcl_level
[0]];
2759 card
->info
.mcl_level
[1] = (char) _ebcasc
[(__u8
)
2760 card
->info
.mcl_level
[1]];
2761 card
->info
.mcl_level
[2] = (char) _ebcasc
[(__u8
)
2762 card
->info
.mcl_level
[2]];
2763 card
->info
.mcl_level
[3] = (char) _ebcasc
[(__u8
)
2764 card
->info
.mcl_level
[3]];
2765 card
->info
.mcl_level
[QETH_MCL_LENGTH
] = 0;
2769 memset(&card
->info
.mcl_level
[0], 0, QETH_MCL_LENGTH
+ 1);
2771 dev_info(&card
->gdev
->dev
,
2772 "Device is a%s card%s%s%s\nwith link type %s.\n",
2773 qeth_get_cardname(card
),
2774 (card
->info
.mcl_level
[0]) ? " (level: " : "",
2775 (card
->info
.mcl_level
[0]) ? card
->info
.mcl_level
: "",
2776 (card
->info
.mcl_level
[0]) ? ")" : "",
2777 qeth_get_cardname_short(card
));
2779 EXPORT_SYMBOL_GPL(qeth_print_status_message
);
2781 static void qeth_initialize_working_pool_list(struct qeth_card
*card
)
2783 struct qeth_buffer_pool_entry
*entry
;
2785 QETH_CARD_TEXT(card
, 5, "inwrklst");
2787 list_for_each_entry(entry
,
2788 &card
->qdio
.init_pool
.entry_list
, init_list
) {
2789 qeth_put_buffer_pool_entry(card
, entry
);
2793 static struct qeth_buffer_pool_entry
*qeth_find_free_buffer_pool_entry(
2794 struct qeth_card
*card
)
2796 struct list_head
*plh
;
2797 struct qeth_buffer_pool_entry
*entry
;
2801 if (list_empty(&card
->qdio
.in_buf_pool
.entry_list
))
2804 list_for_each(plh
, &card
->qdio
.in_buf_pool
.entry_list
) {
2805 entry
= list_entry(plh
, struct qeth_buffer_pool_entry
, list
);
2807 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(card
); ++i
) {
2808 if (page_count(virt_to_page(entry
->elements
[i
])) > 1) {
2814 list_del_init(&entry
->list
);
2819 /* no free buffer in pool so take first one and swap pages */
2820 entry
= list_entry(card
->qdio
.in_buf_pool
.entry_list
.next
,
2821 struct qeth_buffer_pool_entry
, list
);
2822 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(card
); ++i
) {
2823 if (page_count(virt_to_page(entry
->elements
[i
])) > 1) {
2824 page
= alloc_page(GFP_ATOMIC
);
2828 free_page((unsigned long)entry
->elements
[i
]);
2829 entry
->elements
[i
] = page_address(page
);
2830 if (card
->options
.performance_stats
)
2831 card
->perf_stats
.sg_alloc_page_rx
++;
2835 list_del_init(&entry
->list
);
2839 static int qeth_init_input_buffer(struct qeth_card
*card
,
2840 struct qeth_qdio_buffer
*buf
)
2842 struct qeth_buffer_pool_entry
*pool_entry
;
2845 if ((card
->options
.cq
== QETH_CQ_ENABLED
) && (!buf
->rx_skb
)) {
2846 buf
->rx_skb
= netdev_alloc_skb(card
->dev
,
2847 QETH_RX_PULL_LEN
+ ETH_HLEN
);
2852 pool_entry
= qeth_find_free_buffer_pool_entry(card
);
2857 * since the buffer is accessed only from the input_tasklet
2858 * there shouldn't be a need to synchronize; also, since we use
2859 * the QETH_IN_BUF_REQUEUE_THRESHOLD we should never run out off
2863 buf
->pool_entry
= pool_entry
;
2864 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(card
); ++i
) {
2865 buf
->buffer
->element
[i
].length
= PAGE_SIZE
;
2866 buf
->buffer
->element
[i
].addr
= pool_entry
->elements
[i
];
2867 if (i
== QETH_MAX_BUFFER_ELEMENTS(card
) - 1)
2868 buf
->buffer
->element
[i
].eflags
= SBAL_EFLAGS_LAST_ENTRY
;
2870 buf
->buffer
->element
[i
].eflags
= 0;
2871 buf
->buffer
->element
[i
].sflags
= 0;
2876 int qeth_init_qdio_queues(struct qeth_card
*card
)
2881 QETH_DBF_TEXT(SETUP
, 2, "initqdqs");
2884 qdio_reset_buffers(card
->qdio
.in_q
->qdio_bufs
, QDIO_MAX_BUFFERS_PER_Q
);
2885 memset(&card
->rx
, 0, sizeof(struct qeth_rx
));
2886 qeth_initialize_working_pool_list(card
);
2887 /*give only as many buffers to hardware as we have buffer pool entries*/
2888 for (i
= 0; i
< card
->qdio
.in_buf_pool
.buf_count
- 1; ++i
)
2889 qeth_init_input_buffer(card
, &card
->qdio
.in_q
->bufs
[i
]);
2890 card
->qdio
.in_q
->next_buf_to_init
=
2891 card
->qdio
.in_buf_pool
.buf_count
- 1;
2892 rc
= do_QDIO(CARD_DDEV(card
), QDIO_FLAG_SYNC_INPUT
, 0, 0,
2893 card
->qdio
.in_buf_pool
.buf_count
- 1);
2895 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
2900 rc
= qeth_cq_init(card
);
2905 /* outbound queue */
2906 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
2907 qdio_reset_buffers(card
->qdio
.out_qs
[i
]->qdio_bufs
,
2908 QDIO_MAX_BUFFERS_PER_Q
);
2909 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
) {
2910 qeth_clear_output_buffer(card
->qdio
.out_qs
[i
],
2911 card
->qdio
.out_qs
[i
]->bufs
[j
],
2912 QETH_QDIO_BUF_EMPTY
);
2914 card
->qdio
.out_qs
[i
]->card
= card
;
2915 card
->qdio
.out_qs
[i
]->next_buf_to_fill
= 0;
2916 card
->qdio
.out_qs
[i
]->do_pack
= 0;
2917 atomic_set(&card
->qdio
.out_qs
[i
]->used_buffers
, 0);
2918 atomic_set(&card
->qdio
.out_qs
[i
]->set_pci_flags_count
, 0);
2919 atomic_set(&card
->qdio
.out_qs
[i
]->state
,
2920 QETH_OUT_Q_UNLOCKED
);
2924 EXPORT_SYMBOL_GPL(qeth_init_qdio_queues
);
2926 static __u8
qeth_get_ipa_adp_type(enum qeth_link_types link_type
)
2928 switch (link_type
) {
2929 case QETH_LINK_TYPE_HSTR
:
2936 static void qeth_fill_ipacmd_header(struct qeth_card
*card
,
2937 struct qeth_ipa_cmd
*cmd
, __u8 command
,
2938 enum qeth_prot_versions prot
)
2940 memset(cmd
, 0, sizeof(struct qeth_ipa_cmd
));
2941 cmd
->hdr
.command
= command
;
2942 cmd
->hdr
.initiator
= IPA_CMD_INITIATOR_HOST
;
2943 /* cmd->hdr.seqno is set by qeth_send_control_data() */
2944 cmd
->hdr
.adapter_type
= qeth_get_ipa_adp_type(card
->info
.link_type
);
2945 cmd
->hdr
.rel_adapter_no
= (__u8
) card
->info
.portno
;
2946 if (card
->options
.layer2
)
2947 cmd
->hdr
.prim_version_no
= 2;
2949 cmd
->hdr
.prim_version_no
= 1;
2950 cmd
->hdr
.param_count
= 1;
2951 cmd
->hdr
.prot_version
= prot
;
2952 cmd
->hdr
.ipa_supported
= 0;
2953 cmd
->hdr
.ipa_enabled
= 0;
2956 struct qeth_cmd_buffer
*qeth_get_ipacmd_buffer(struct qeth_card
*card
,
2957 enum qeth_ipa_cmds ipacmd
, enum qeth_prot_versions prot
)
2959 struct qeth_cmd_buffer
*iob
;
2961 iob
= qeth_get_buffer(&card
->write
);
2963 qeth_fill_ipacmd_header(card
, __ipa_cmd(iob
), ipacmd
, prot
);
2965 dev_warn(&card
->gdev
->dev
,
2966 "The qeth driver ran out of channel command buffers\n");
2967 QETH_DBF_MESSAGE(1, "%s The qeth driver ran out of channel command buffers",
2968 dev_name(&card
->gdev
->dev
));
2973 EXPORT_SYMBOL_GPL(qeth_get_ipacmd_buffer
);
2975 void qeth_prepare_ipa_cmd(struct qeth_card
*card
, struct qeth_cmd_buffer
*iob
,
2978 memcpy(iob
->data
, IPA_PDU_HEADER
, IPA_PDU_HEADER_SIZE
);
2979 memcpy(QETH_IPA_CMD_PROT_TYPE(iob
->data
), &prot_type
, 1);
2980 memcpy(QETH_IPA_CMD_DEST_ADDR(iob
->data
),
2981 &card
->token
.ulp_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2983 EXPORT_SYMBOL_GPL(qeth_prepare_ipa_cmd
);
2986 * qeth_send_ipa_cmd() - send an IPA command
2988 * See qeth_send_control_data() for explanation of the arguments.
2991 int qeth_send_ipa_cmd(struct qeth_card
*card
, struct qeth_cmd_buffer
*iob
,
2992 int (*reply_cb
)(struct qeth_card
*, struct qeth_reply
*,
2999 QETH_CARD_TEXT(card
, 4, "sendipa");
3001 if (card
->options
.layer2
)
3002 if (card
->info
.type
== QETH_CARD_TYPE_OSN
)
3003 prot_type
= QETH_PROT_OSN2
;
3005 prot_type
= QETH_PROT_LAYER2
;
3007 prot_type
= QETH_PROT_TCPIP
;
3008 qeth_prepare_ipa_cmd(card
, iob
, prot_type
);
3009 rc
= qeth_send_control_data(card
, IPA_CMD_LENGTH
,
3010 iob
, reply_cb
, reply_param
);
3012 qeth_clear_ipacmd_list(card
);
3013 qeth_schedule_recovery(card
);
3017 EXPORT_SYMBOL_GPL(qeth_send_ipa_cmd
);
3019 static int qeth_send_startlan(struct qeth_card
*card
)
3022 struct qeth_cmd_buffer
*iob
;
3024 QETH_DBF_TEXT(SETUP
, 2, "strtlan");
3026 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_STARTLAN
, 0);
3029 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
3033 static int qeth_setadpparms_inspect_rc(struct qeth_ipa_cmd
*cmd
)
3035 if (!cmd
->hdr
.return_code
)
3036 cmd
->hdr
.return_code
=
3037 cmd
->data
.setadapterparms
.hdr
.return_code
;
3038 return cmd
->hdr
.return_code
;
3041 static int qeth_query_setadapterparms_cb(struct qeth_card
*card
,
3042 struct qeth_reply
*reply
, unsigned long data
)
3044 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
3046 QETH_CARD_TEXT(card
, 3, "quyadpcb");
3047 if (qeth_setadpparms_inspect_rc(cmd
))
3050 if (cmd
->data
.setadapterparms
.data
.query_cmds_supp
.lan_type
& 0x7f) {
3051 card
->info
.link_type
=
3052 cmd
->data
.setadapterparms
.data
.query_cmds_supp
.lan_type
;
3053 QETH_DBF_TEXT_(SETUP
, 2, "lnk %d", card
->info
.link_type
);
3055 card
->options
.adp
.supported_funcs
=
3056 cmd
->data
.setadapterparms
.data
.query_cmds_supp
.supported_cmds
;
3060 static struct qeth_cmd_buffer
*qeth_get_adapter_cmd(struct qeth_card
*card
,
3061 __u32 command
, __u32 cmdlen
)
3063 struct qeth_cmd_buffer
*iob
;
3064 struct qeth_ipa_cmd
*cmd
;
3066 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SETADAPTERPARMS
,
3069 cmd
= __ipa_cmd(iob
);
3070 cmd
->data
.setadapterparms
.hdr
.cmdlength
= cmdlen
;
3071 cmd
->data
.setadapterparms
.hdr
.command_code
= command
;
3072 cmd
->data
.setadapterparms
.hdr
.used_total
= 1;
3073 cmd
->data
.setadapterparms
.hdr
.seq_no
= 1;
3079 int qeth_query_setadapterparms(struct qeth_card
*card
)
3082 struct qeth_cmd_buffer
*iob
;
3084 QETH_CARD_TEXT(card
, 3, "queryadp");
3085 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_QUERY_COMMANDS_SUPPORTED
,
3086 sizeof(struct qeth_ipacmd_setadpparms
));
3089 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_query_setadapterparms_cb
, NULL
);
3092 EXPORT_SYMBOL_GPL(qeth_query_setadapterparms
);
3094 static int qeth_query_ipassists_cb(struct qeth_card
*card
,
3095 struct qeth_reply
*reply
, unsigned long data
)
3097 struct qeth_ipa_cmd
*cmd
;
3099 QETH_DBF_TEXT(SETUP
, 2, "qipasscb");
3101 cmd
= (struct qeth_ipa_cmd
*) data
;
3103 switch (cmd
->hdr
.return_code
) {
3104 case IPA_RC_NOTSUPP
:
3105 case IPA_RC_L2_UNSUPPORTED_CMD
:
3106 QETH_DBF_TEXT(SETUP
, 2, "ipaunsup");
3107 card
->options
.ipa4
.supported_funcs
|= IPA_SETADAPTERPARMS
;
3108 card
->options
.ipa6
.supported_funcs
|= IPA_SETADAPTERPARMS
;
3111 if (cmd
->hdr
.return_code
) {
3112 QETH_DBF_MESSAGE(1, "%s IPA_CMD_QIPASSIST: Unhandled "
3114 dev_name(&card
->gdev
->dev
),
3115 cmd
->hdr
.return_code
);
3120 if (cmd
->hdr
.prot_version
== QETH_PROT_IPV4
) {
3121 card
->options
.ipa4
.supported_funcs
= cmd
->hdr
.ipa_supported
;
3122 card
->options
.ipa4
.enabled_funcs
= cmd
->hdr
.ipa_enabled
;
3123 } else if (cmd
->hdr
.prot_version
== QETH_PROT_IPV6
) {
3124 card
->options
.ipa6
.supported_funcs
= cmd
->hdr
.ipa_supported
;
3125 card
->options
.ipa6
.enabled_funcs
= cmd
->hdr
.ipa_enabled
;
3127 QETH_DBF_MESSAGE(1, "%s IPA_CMD_QIPASSIST: Flawed LIC detected"
3128 "\n", dev_name(&card
->gdev
->dev
));
3132 int qeth_query_ipassists(struct qeth_card
*card
, enum qeth_prot_versions prot
)
3135 struct qeth_cmd_buffer
*iob
;
3137 QETH_DBF_TEXT_(SETUP
, 2, "qipassi%i", prot
);
3138 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_QIPASSIST
, prot
);
3141 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_query_ipassists_cb
, NULL
);
3144 EXPORT_SYMBOL_GPL(qeth_query_ipassists
);
3146 static int qeth_query_switch_attributes_cb(struct qeth_card
*card
,
3147 struct qeth_reply
*reply
, unsigned long data
)
3149 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
3150 struct qeth_query_switch_attributes
*attrs
;
3151 struct qeth_switch_info
*sw_info
;
3153 QETH_CARD_TEXT(card
, 2, "qswiatcb");
3154 if (qeth_setadpparms_inspect_rc(cmd
))
3157 sw_info
= (struct qeth_switch_info
*)reply
->param
;
3158 attrs
= &cmd
->data
.setadapterparms
.data
.query_switch_attributes
;
3159 sw_info
->capabilities
= attrs
->capabilities
;
3160 sw_info
->settings
= attrs
->settings
;
3161 QETH_CARD_TEXT_(card
, 2, "%04x%04x", sw_info
->capabilities
,
3166 int qeth_query_switch_attributes(struct qeth_card
*card
,
3167 struct qeth_switch_info
*sw_info
)
3169 struct qeth_cmd_buffer
*iob
;
3171 QETH_CARD_TEXT(card
, 2, "qswiattr");
3172 if (!qeth_adp_supported(card
, IPA_SETADP_QUERY_SWITCH_ATTRIBUTES
))
3174 if (!netif_carrier_ok(card
->dev
))
3176 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_QUERY_SWITCH_ATTRIBUTES
,
3177 sizeof(struct qeth_ipacmd_setadpparms_hdr
));
3180 return qeth_send_ipa_cmd(card
, iob
,
3181 qeth_query_switch_attributes_cb
, sw_info
);
3183 EXPORT_SYMBOL_GPL(qeth_query_switch_attributes
);
3185 static int qeth_query_setdiagass_cb(struct qeth_card
*card
,
3186 struct qeth_reply
*reply
, unsigned long data
)
3188 struct qeth_ipa_cmd
*cmd
;
3191 cmd
= (struct qeth_ipa_cmd
*)data
;
3192 rc
= cmd
->hdr
.return_code
;
3194 QETH_CARD_TEXT_(card
, 2, "diagq:%x", rc
);
3196 card
->info
.diagass_support
= cmd
->data
.diagass
.ext
;
3200 static int qeth_query_setdiagass(struct qeth_card
*card
)
3202 struct qeth_cmd_buffer
*iob
;
3203 struct qeth_ipa_cmd
*cmd
;
3205 QETH_DBF_TEXT(SETUP
, 2, "qdiagass");
3206 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SET_DIAG_ASS
, 0);
3209 cmd
= __ipa_cmd(iob
);
3210 cmd
->data
.diagass
.subcmd_len
= 16;
3211 cmd
->data
.diagass
.subcmd
= QETH_DIAGS_CMD_QUERY
;
3212 return qeth_send_ipa_cmd(card
, iob
, qeth_query_setdiagass_cb
, NULL
);
3215 static void qeth_get_trap_id(struct qeth_card
*card
, struct qeth_trap_id
*tid
)
3217 unsigned long info
= get_zeroed_page(GFP_KERNEL
);
3218 struct sysinfo_2_2_2
*info222
= (struct sysinfo_2_2_2
*)info
;
3219 struct sysinfo_3_2_2
*info322
= (struct sysinfo_3_2_2
*)info
;
3220 struct ccw_dev_id ccwid
;
3223 tid
->chpid
= card
->info
.chpid
;
3224 ccw_device_get_id(CARD_RDEV(card
), &ccwid
);
3225 tid
->ssid
= ccwid
.ssid
;
3226 tid
->devno
= ccwid
.devno
;
3229 level
= stsi(NULL
, 0, 0, 0);
3230 if ((level
>= 2) && (stsi(info222
, 2, 2, 2) == 0))
3231 tid
->lparnr
= info222
->lpar_number
;
3232 if ((level
>= 3) && (stsi(info322
, 3, 2, 2) == 0)) {
3233 EBCASC(info322
->vm
[0].name
, sizeof(info322
->vm
[0].name
));
3234 memcpy(tid
->vmname
, info322
->vm
[0].name
, sizeof(tid
->vmname
));
3240 static int qeth_hw_trap_cb(struct qeth_card
*card
,
3241 struct qeth_reply
*reply
, unsigned long data
)
3243 struct qeth_ipa_cmd
*cmd
;
3246 cmd
= (struct qeth_ipa_cmd
*)data
;
3247 rc
= cmd
->hdr
.return_code
;
3249 QETH_CARD_TEXT_(card
, 2, "trapc:%x", rc
);
3253 int qeth_hw_trap(struct qeth_card
*card
, enum qeth_diags_trap_action action
)
3255 struct qeth_cmd_buffer
*iob
;
3256 struct qeth_ipa_cmd
*cmd
;
3258 QETH_DBF_TEXT(SETUP
, 2, "diagtrap");
3259 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SET_DIAG_ASS
, 0);
3262 cmd
= __ipa_cmd(iob
);
3263 cmd
->data
.diagass
.subcmd_len
= 80;
3264 cmd
->data
.diagass
.subcmd
= QETH_DIAGS_CMD_TRAP
;
3265 cmd
->data
.diagass
.type
= 1;
3266 cmd
->data
.diagass
.action
= action
;
3268 case QETH_DIAGS_TRAP_ARM
:
3269 cmd
->data
.diagass
.options
= 0x0003;
3270 cmd
->data
.diagass
.ext
= 0x00010000 +
3271 sizeof(struct qeth_trap_id
);
3272 qeth_get_trap_id(card
,
3273 (struct qeth_trap_id
*)cmd
->data
.diagass
.cdata
);
3275 case QETH_DIAGS_TRAP_DISARM
:
3276 cmd
->data
.diagass
.options
= 0x0001;
3278 case QETH_DIAGS_TRAP_CAPTURE
:
3281 return qeth_send_ipa_cmd(card
, iob
, qeth_hw_trap_cb
, NULL
);
3283 EXPORT_SYMBOL_GPL(qeth_hw_trap
);
3285 static int qeth_check_qdio_errors(struct qeth_card
*card
,
3286 struct qdio_buffer
*buf
,
3287 unsigned int qdio_error
,
3288 const char *dbftext
)
3291 QETH_CARD_TEXT(card
, 2, dbftext
);
3292 QETH_CARD_TEXT_(card
, 2, " F15=%02X",
3293 buf
->element
[15].sflags
);
3294 QETH_CARD_TEXT_(card
, 2, " F14=%02X",
3295 buf
->element
[14].sflags
);
3296 QETH_CARD_TEXT_(card
, 2, " qerr=%X", qdio_error
);
3297 if ((buf
->element
[15].sflags
) == 0x12) {
3298 card
->stats
.rx_dropped
++;
3306 static void qeth_queue_input_buffer(struct qeth_card
*card
, int index
)
3308 struct qeth_qdio_q
*queue
= card
->qdio
.in_q
;
3309 struct list_head
*lh
;
3315 count
= (index
< queue
->next_buf_to_init
)?
3316 card
->qdio
.in_buf_pool
.buf_count
-
3317 (queue
->next_buf_to_init
- index
) :
3318 card
->qdio
.in_buf_pool
.buf_count
-
3319 (queue
->next_buf_to_init
+ QDIO_MAX_BUFFERS_PER_Q
- index
);
3320 /* only requeue at a certain threshold to avoid SIGAs */
3321 if (count
>= QETH_IN_BUF_REQUEUE_THRESHOLD(card
)) {
3322 for (i
= queue
->next_buf_to_init
;
3323 i
< queue
->next_buf_to_init
+ count
; ++i
) {
3324 if (qeth_init_input_buffer(card
,
3325 &queue
->bufs
[i
% QDIO_MAX_BUFFERS_PER_Q
])) {
3332 if (newcount
< count
) {
3333 /* we are in memory shortage so we switch back to
3334 traditional skb allocation and drop packages */
3335 atomic_set(&card
->force_alloc_skb
, 3);
3338 atomic_add_unless(&card
->force_alloc_skb
, -1, 0);
3343 list_for_each(lh
, &card
->qdio
.in_buf_pool
.entry_list
)
3345 if (i
== card
->qdio
.in_buf_pool
.buf_count
) {
3346 QETH_CARD_TEXT(card
, 2, "qsarbw");
3347 card
->reclaim_index
= index
;
3348 schedule_delayed_work(
3349 &card
->buffer_reclaim_work
,
3350 QETH_RECLAIM_WORK_TIME
);
3356 * according to old code it should be avoided to requeue all
3357 * 128 buffers in order to benefit from PCI avoidance.
3358 * this function keeps at least one buffer (the buffer at
3359 * 'index') un-requeued -> this buffer is the first buffer that
3360 * will be requeued the next time
3362 if (card
->options
.performance_stats
) {
3363 card
->perf_stats
.inbound_do_qdio_cnt
++;
3364 card
->perf_stats
.inbound_do_qdio_start_time
=
3367 rc
= do_QDIO(CARD_DDEV(card
), QDIO_FLAG_SYNC_INPUT
, 0,
3368 queue
->next_buf_to_init
, count
);
3369 if (card
->options
.performance_stats
)
3370 card
->perf_stats
.inbound_do_qdio_time
+=
3372 card
->perf_stats
.inbound_do_qdio_start_time
;
3374 QETH_CARD_TEXT(card
, 2, "qinberr");
3376 queue
->next_buf_to_init
= (queue
->next_buf_to_init
+ count
) %
3377 QDIO_MAX_BUFFERS_PER_Q
;
3381 static void qeth_buffer_reclaim_work(struct work_struct
*work
)
3383 struct qeth_card
*card
= container_of(work
, struct qeth_card
,
3384 buffer_reclaim_work
.work
);
3386 QETH_CARD_TEXT_(card
, 2, "brw:%x", card
->reclaim_index
);
3387 qeth_queue_input_buffer(card
, card
->reclaim_index
);
3390 static void qeth_handle_send_error(struct qeth_card
*card
,
3391 struct qeth_qdio_out_buffer
*buffer
, unsigned int qdio_err
)
3393 int sbalf15
= buffer
->buffer
->element
[15].sflags
;
3395 QETH_CARD_TEXT(card
, 6, "hdsnderr");
3396 if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
3403 qeth_check_qdio_errors(card
, buffer
->buffer
, qdio_err
, "qouterr");
3408 if ((sbalf15
>= 15) && (sbalf15
<= 31))
3411 QETH_CARD_TEXT(card
, 1, "lnkfail");
3412 QETH_CARD_TEXT_(card
, 1, "%04x %02x",
3413 (u16
)qdio_err
, (u8
)sbalf15
);
3417 * qeth_prep_flush_pack_buffer - Prepares flushing of a packing buffer.
3418 * @queue: queue to check for packing buffer
3420 * Returns number of buffers that were prepared for flush.
3422 static int qeth_prep_flush_pack_buffer(struct qeth_qdio_out_q
*queue
)
3424 struct qeth_qdio_out_buffer
*buffer
;
3426 buffer
= queue
->bufs
[queue
->next_buf_to_fill
];
3427 if ((atomic_read(&buffer
->state
) == QETH_QDIO_BUF_EMPTY
) &&
3428 (buffer
->next_element_to_fill
> 0)) {
3429 /* it's a packing buffer */
3430 atomic_set(&buffer
->state
, QETH_QDIO_BUF_PRIMED
);
3431 queue
->next_buf_to_fill
=
3432 (queue
->next_buf_to_fill
+ 1) % QDIO_MAX_BUFFERS_PER_Q
;
3439 * Switched to packing state if the number of used buffers on a queue
3440 * reaches a certain limit.
3442 static void qeth_switch_to_packing_if_needed(struct qeth_qdio_out_q
*queue
)
3444 if (!queue
->do_pack
) {
3445 if (atomic_read(&queue
->used_buffers
)
3446 >= QETH_HIGH_WATERMARK_PACK
){
3447 /* switch non-PACKING -> PACKING */
3448 QETH_CARD_TEXT(queue
->card
, 6, "np->pack");
3449 if (queue
->card
->options
.performance_stats
)
3450 queue
->card
->perf_stats
.sc_dp_p
++;
3457 * Switches from packing to non-packing mode. If there is a packing
3458 * buffer on the queue this buffer will be prepared to be flushed.
3459 * In that case 1 is returned to inform the caller. If no buffer
3460 * has to be flushed, zero is returned.
3462 static int qeth_switch_to_nonpacking_if_needed(struct qeth_qdio_out_q
*queue
)
3464 if (queue
->do_pack
) {
3465 if (atomic_read(&queue
->used_buffers
)
3466 <= QETH_LOW_WATERMARK_PACK
) {
3467 /* switch PACKING -> non-PACKING */
3468 QETH_CARD_TEXT(queue
->card
, 6, "pack->np");
3469 if (queue
->card
->options
.performance_stats
)
3470 queue
->card
->perf_stats
.sc_p_dp
++;
3472 return qeth_prep_flush_pack_buffer(queue
);
3478 static void qeth_flush_buffers(struct qeth_qdio_out_q
*queue
, int index
,
3481 struct qeth_qdio_out_buffer
*buf
;
3484 unsigned int qdio_flags
;
3486 for (i
= index
; i
< index
+ count
; ++i
) {
3487 int bidx
= i
% QDIO_MAX_BUFFERS_PER_Q
;
3488 buf
= queue
->bufs
[bidx
];
3489 buf
->buffer
->element
[buf
->next_element_to_fill
- 1].eflags
|=
3490 SBAL_EFLAGS_LAST_ENTRY
;
3492 if (queue
->bufstates
)
3493 queue
->bufstates
[bidx
].user
= buf
;
3495 if (queue
->card
->info
.type
== QETH_CARD_TYPE_IQD
)
3498 if (!queue
->do_pack
) {
3499 if ((atomic_read(&queue
->used_buffers
) >=
3500 (QETH_HIGH_WATERMARK_PACK
-
3501 QETH_WATERMARK_PACK_FUZZ
)) &&
3502 !atomic_read(&queue
->set_pci_flags_count
)) {
3503 /* it's likely that we'll go to packing
3505 atomic_inc(&queue
->set_pci_flags_count
);
3506 buf
->buffer
->element
[0].sflags
|= SBAL_SFLAGS0_PCI_REQ
;
3509 if (!atomic_read(&queue
->set_pci_flags_count
)) {
3511 * there's no outstanding PCI any more, so we
3512 * have to request a PCI to be sure the the PCI
3513 * will wake at some time in the future then we
3514 * can flush packed buffers that might still be
3515 * hanging around, which can happen if no
3516 * further send was requested by the stack
3518 atomic_inc(&queue
->set_pci_flags_count
);
3519 buf
->buffer
->element
[0].sflags
|= SBAL_SFLAGS0_PCI_REQ
;
3524 netif_trans_update(queue
->card
->dev
);
3525 if (queue
->card
->options
.performance_stats
) {
3526 queue
->card
->perf_stats
.outbound_do_qdio_cnt
++;
3527 queue
->card
->perf_stats
.outbound_do_qdio_start_time
=
3530 qdio_flags
= QDIO_FLAG_SYNC_OUTPUT
;
3531 if (atomic_read(&queue
->set_pci_flags_count
))
3532 qdio_flags
|= QDIO_FLAG_PCI_OUT
;
3533 atomic_add(count
, &queue
->used_buffers
);
3535 rc
= do_QDIO(CARD_DDEV(queue
->card
), qdio_flags
,
3536 queue
->queue_no
, index
, count
);
3537 if (queue
->card
->options
.performance_stats
)
3538 queue
->card
->perf_stats
.outbound_do_qdio_time
+=
3540 queue
->card
->perf_stats
.outbound_do_qdio_start_time
;
3542 queue
->card
->stats
.tx_errors
+= count
;
3543 /* ignore temporary SIGA errors without busy condition */
3546 QETH_CARD_TEXT(queue
->card
, 2, "flushbuf");
3547 QETH_CARD_TEXT_(queue
->card
, 2, " q%d", queue
->queue_no
);
3548 QETH_CARD_TEXT_(queue
->card
, 2, " idx%d", index
);
3549 QETH_CARD_TEXT_(queue
->card
, 2, " c%d", count
);
3550 QETH_CARD_TEXT_(queue
->card
, 2, " err%d", rc
);
3552 /* this must not happen under normal circumstances. if it
3553 * happens something is really wrong -> recover */
3554 qeth_schedule_recovery(queue
->card
);
3557 if (queue
->card
->options
.performance_stats
)
3558 queue
->card
->perf_stats
.bufs_sent
+= count
;
3561 static void qeth_check_outbound_queue(struct qeth_qdio_out_q
*queue
)
3565 int q_was_packing
= 0;
3568 * check if weed have to switch to non-packing mode or if
3569 * we have to get a pci flag out on the queue
3571 if ((atomic_read(&queue
->used_buffers
) <= QETH_LOW_WATERMARK_PACK
) ||
3572 !atomic_read(&queue
->set_pci_flags_count
)) {
3573 if (atomic_xchg(&queue
->state
, QETH_OUT_Q_LOCKED_FLUSH
) ==
3574 QETH_OUT_Q_UNLOCKED
) {
3576 * If we get in here, there was no action in
3577 * do_send_packet. So, we check if there is a
3578 * packing buffer to be flushed here.
3580 netif_stop_queue(queue
->card
->dev
);
3581 index
= queue
->next_buf_to_fill
;
3582 q_was_packing
= queue
->do_pack
;
3583 /* queue->do_pack may change */
3585 flush_cnt
+= qeth_switch_to_nonpacking_if_needed(queue
);
3587 !atomic_read(&queue
->set_pci_flags_count
))
3588 flush_cnt
+= qeth_prep_flush_pack_buffer(queue
);
3589 if (queue
->card
->options
.performance_stats
&&
3591 queue
->card
->perf_stats
.bufs_sent_pack
+=
3594 qeth_flush_buffers(queue
, index
, flush_cnt
);
3595 atomic_set(&queue
->state
, QETH_OUT_Q_UNLOCKED
);
3600 static void qeth_qdio_start_poll(struct ccw_device
*ccwdev
, int queue
,
3601 unsigned long card_ptr
)
3603 struct qeth_card
*card
= (struct qeth_card
*)card_ptr
;
3605 if (card
->dev
&& (card
->dev
->flags
& IFF_UP
))
3606 napi_schedule(&card
->napi
);
3609 int qeth_configure_cq(struct qeth_card
*card
, enum qeth_cq cq
)
3613 if (card
->options
.cq
== QETH_CQ_NOTAVAILABLE
) {
3617 if (card
->options
.cq
== cq
) {
3622 if (card
->state
!= CARD_STATE_DOWN
&&
3623 card
->state
!= CARD_STATE_RECOVER
) {
3628 qeth_free_qdio_buffers(card
);
3629 card
->options
.cq
= cq
;
3636 EXPORT_SYMBOL_GPL(qeth_configure_cq
);
3639 static void qeth_qdio_cq_handler(struct qeth_card
*card
,
3640 unsigned int qdio_err
,
3641 unsigned int queue
, int first_element
, int count
) {
3642 struct qeth_qdio_q
*cq
= card
->qdio
.c_q
;
3646 if (!qeth_is_cq(card
, queue
))
3649 QETH_CARD_TEXT_(card
, 5, "qcqhe%d", first_element
);
3650 QETH_CARD_TEXT_(card
, 5, "qcqhc%d", count
);
3651 QETH_CARD_TEXT_(card
, 5, "qcqherr%d", qdio_err
);
3654 netif_stop_queue(card
->dev
);
3655 qeth_schedule_recovery(card
);
3659 if (card
->options
.performance_stats
) {
3660 card
->perf_stats
.cq_cnt
++;
3661 card
->perf_stats
.cq_start_time
= qeth_get_micros();
3664 for (i
= first_element
; i
< first_element
+ count
; ++i
) {
3665 int bidx
= i
% QDIO_MAX_BUFFERS_PER_Q
;
3666 struct qdio_buffer
*buffer
= cq
->qdio_bufs
[bidx
];
3670 while ((e
< QDIO_MAX_ELEMENTS_PER_BUFFER
) &&
3671 buffer
->element
[e
].addr
) {
3672 unsigned long phys_aob_addr
;
3674 phys_aob_addr
= (unsigned long) buffer
->element
[e
].addr
;
3675 qeth_qdio_handle_aob(card
, phys_aob_addr
);
3676 buffer
->element
[e
].addr
= NULL
;
3677 buffer
->element
[e
].eflags
= 0;
3678 buffer
->element
[e
].sflags
= 0;
3679 buffer
->element
[e
].length
= 0;
3684 buffer
->element
[15].eflags
= 0;
3685 buffer
->element
[15].sflags
= 0;
3687 rc
= do_QDIO(CARD_DDEV(card
), QDIO_FLAG_SYNC_INPUT
, queue
,
3688 card
->qdio
.c_q
->next_buf_to_init
,
3691 dev_warn(&card
->gdev
->dev
,
3692 "QDIO reported an error, rc=%i\n", rc
);
3693 QETH_CARD_TEXT(card
, 2, "qcqherr");
3695 card
->qdio
.c_q
->next_buf_to_init
= (card
->qdio
.c_q
->next_buf_to_init
3696 + count
) % QDIO_MAX_BUFFERS_PER_Q
;
3698 netif_wake_queue(card
->dev
);
3700 if (card
->options
.performance_stats
) {
3701 int delta_t
= qeth_get_micros();
3702 delta_t
-= card
->perf_stats
.cq_start_time
;
3703 card
->perf_stats
.cq_time
+= delta_t
;
3709 static void qeth_qdio_input_handler(struct ccw_device
*ccwdev
,
3710 unsigned int qdio_err
, int queue
,
3711 int first_elem
, int count
,
3712 unsigned long card_ptr
)
3714 struct qeth_card
*card
= (struct qeth_card
*)card_ptr
;
3716 QETH_CARD_TEXT_(card
, 2, "qihq%d", queue
);
3717 QETH_CARD_TEXT_(card
, 2, "qiec%d", qdio_err
);
3719 if (qeth_is_cq(card
, queue
))
3720 qeth_qdio_cq_handler(card
, qdio_err
, queue
, first_elem
, count
);
3722 qeth_schedule_recovery(card
);
3725 static void qeth_qdio_output_handler(struct ccw_device
*ccwdev
,
3726 unsigned int qdio_error
, int __queue
,
3727 int first_element
, int count
,
3728 unsigned long card_ptr
)
3730 struct qeth_card
*card
= (struct qeth_card
*) card_ptr
;
3731 struct qeth_qdio_out_q
*queue
= card
->qdio
.out_qs
[__queue
];
3732 struct qeth_qdio_out_buffer
*buffer
;
3735 QETH_CARD_TEXT(card
, 6, "qdouhdl");
3736 if (qdio_error
& QDIO_ERROR_FATAL
) {
3737 QETH_CARD_TEXT(card
, 2, "achkcond");
3738 netif_stop_queue(card
->dev
);
3739 qeth_schedule_recovery(card
);
3742 if (card
->options
.performance_stats
) {
3743 card
->perf_stats
.outbound_handler_cnt
++;
3744 card
->perf_stats
.outbound_handler_start_time
=
3747 for (i
= first_element
; i
< (first_element
+ count
); ++i
) {
3748 int bidx
= i
% QDIO_MAX_BUFFERS_PER_Q
;
3749 buffer
= queue
->bufs
[bidx
];
3750 qeth_handle_send_error(card
, buffer
, qdio_error
);
3752 if (queue
->bufstates
&&
3753 (queue
->bufstates
[bidx
].flags
&
3754 QDIO_OUTBUF_STATE_FLAG_PENDING
) != 0) {
3755 WARN_ON_ONCE(card
->options
.cq
!= QETH_CQ_ENABLED
);
3757 if (atomic_cmpxchg(&buffer
->state
,
3758 QETH_QDIO_BUF_PRIMED
,
3759 QETH_QDIO_BUF_PENDING
) ==
3760 QETH_QDIO_BUF_PRIMED
) {
3761 qeth_notify_skbs(queue
, buffer
,
3764 buffer
->aob
= queue
->bufstates
[bidx
].aob
;
3765 QETH_CARD_TEXT_(queue
->card
, 5, "pel%d", bidx
);
3766 QETH_CARD_TEXT(queue
->card
, 5, "aob");
3767 QETH_CARD_TEXT_(queue
->card
, 5, "%lx",
3768 virt_to_phys(buffer
->aob
));
3770 /* prepare the queue slot for re-use: */
3771 qeth_scrub_qdio_buffer(buffer
->buffer
,
3772 QETH_MAX_BUFFER_ELEMENTS(card
));
3773 if (qeth_init_qdio_out_buf(queue
, bidx
)) {
3774 QETH_CARD_TEXT(card
, 2, "outofbuf");
3775 qeth_schedule_recovery(card
);
3778 if (card
->options
.cq
== QETH_CQ_ENABLED
) {
3779 enum iucv_tx_notify n
;
3781 n
= qeth_compute_cq_notification(
3782 buffer
->buffer
->element
[15].sflags
, 0);
3783 qeth_notify_skbs(queue
, buffer
, n
);
3786 qeth_clear_output_buffer(queue
, buffer
,
3787 QETH_QDIO_BUF_EMPTY
);
3789 qeth_cleanup_handled_pending(queue
, bidx
, 0);
3791 atomic_sub(count
, &queue
->used_buffers
);
3792 /* check if we need to do something on this outbound queue */
3793 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
)
3794 qeth_check_outbound_queue(queue
);
3796 netif_wake_queue(queue
->card
->dev
);
3797 if (card
->options
.performance_stats
)
3798 card
->perf_stats
.outbound_handler_time
+= qeth_get_micros() -
3799 card
->perf_stats
.outbound_handler_start_time
;
3802 /* We cannot use outbound queue 3 for unicast packets on HiperSockets */
3803 static inline int qeth_cut_iqd_prio(struct qeth_card
*card
, int queue_num
)
3805 if ((card
->info
.type
== QETH_CARD_TYPE_IQD
) && (queue_num
== 3))
3811 * Note: Function assumes that we have 4 outbound queues.
3813 int qeth_get_priority_queue(struct qeth_card
*card
, struct sk_buff
*skb
,
3814 int ipv
, int cast_type
)
3819 if (cast_type
&& card
->info
.is_multicast_different
)
3820 return card
->info
.is_multicast_different
&
3821 (card
->qdio
.no_out_queues
- 1);
3823 switch (card
->qdio
.do_prio_queueing
) {
3824 case QETH_PRIO_Q_ING_TOS
:
3825 case QETH_PRIO_Q_ING_PREC
:
3828 tos
= ipv4_get_dsfield(ip_hdr(skb
));
3831 tos
= ipv6_get_dsfield(ipv6_hdr(skb
));
3834 return card
->qdio
.default_out_queue
;
3836 if (card
->qdio
.do_prio_queueing
== QETH_PRIO_Q_ING_PREC
)
3837 return qeth_cut_iqd_prio(card
, ~tos
>> 6 & 3);
3838 if (tos
& IPTOS_MINCOST
)
3839 return qeth_cut_iqd_prio(card
, 3);
3840 if (tos
& IPTOS_RELIABILITY
)
3842 if (tos
& IPTOS_THROUGHPUT
)
3844 if (tos
& IPTOS_LOWDELAY
)
3847 case QETH_PRIO_Q_ING_SKB
:
3848 if (skb
->priority
> 5)
3850 return qeth_cut_iqd_prio(card
, ~skb
->priority
>> 1 & 3);
3851 case QETH_PRIO_Q_ING_VLAN
:
3852 tci
= &((struct ethhdr
*)skb
->data
)->h_proto
;
3853 if (be16_to_cpu(*tci
) == ETH_P_8021Q
)
3854 return qeth_cut_iqd_prio(card
,
3855 ~be16_to_cpu(*(tci
+ 1)) >> (VLAN_PRIO_SHIFT
+ 1) & 3);
3860 return card
->qdio
.default_out_queue
;
3862 EXPORT_SYMBOL_GPL(qeth_get_priority_queue
);
3865 * qeth_get_elements_for_frags() - find number of SBALEs for skb frags.
3868 * Returns the number of pages, and thus QDIO buffer elements, needed to cover
3869 * fragmented part of the SKB. Returns zero for linear SKB.
3871 int qeth_get_elements_for_frags(struct sk_buff
*skb
)
3873 int cnt
, elements
= 0;
3875 for (cnt
= 0; cnt
< skb_shinfo(skb
)->nr_frags
; cnt
++) {
3876 struct skb_frag_struct
*frag
= &skb_shinfo(skb
)->frags
[cnt
];
3878 elements
+= qeth_get_elements_for_range(
3879 (addr_t
)skb_frag_address(frag
),
3880 (addr_t
)skb_frag_address(frag
) + skb_frag_size(frag
));
3884 EXPORT_SYMBOL_GPL(qeth_get_elements_for_frags
);
3887 * qeth_get_elements_no() - find number of SBALEs for skb data, inc. frags.
3888 * @card: qeth card structure, to check max. elems.
3890 * @extra_elems: extra elems needed, to check against max.
3891 * @data_offset: range starts at skb->data + data_offset
3893 * Returns the number of pages, and thus QDIO buffer elements, needed to cover
3894 * skb data, including linear part and fragments. Checks if the result plus
3895 * extra_elems fits under the limit for the card. Returns 0 if it does not.
3896 * Note: extra_elems is not included in the returned result.
3898 int qeth_get_elements_no(struct qeth_card
*card
,
3899 struct sk_buff
*skb
, int extra_elems
, int data_offset
)
3901 addr_t end
= (addr_t
)skb
->data
+ skb_headlen(skb
);
3902 int elements
= qeth_get_elements_for_frags(skb
);
3903 addr_t start
= (addr_t
)skb
->data
+ data_offset
;
3906 elements
+= qeth_get_elements_for_range(start
, end
);
3908 if ((elements
+ extra_elems
) > QETH_MAX_BUFFER_ELEMENTS(card
)) {
3909 QETH_DBF_MESSAGE(2, "Invalid size of IP packet "
3910 "(Number=%d / Length=%d). Discarded.\n",
3911 elements
+ extra_elems
, skb
->len
);
3916 EXPORT_SYMBOL_GPL(qeth_get_elements_no
);
3918 int qeth_hdr_chk_and_bounce(struct sk_buff
*skb
, struct qeth_hdr
**hdr
, int len
)
3920 int hroom
, inpage
, rest
;
3922 if (((unsigned long)skb
->data
& PAGE_MASK
) !=
3923 (((unsigned long)skb
->data
+ len
- 1) & PAGE_MASK
)) {
3924 hroom
= skb_headroom(skb
);
3925 inpage
= PAGE_SIZE
- ((unsigned long) skb
->data
% PAGE_SIZE
);
3926 rest
= len
- inpage
;
3929 memmove(skb
->data
- rest
, skb
->data
, skb_headlen(skb
));
3932 *hdr
= (struct qeth_hdr
*)skb
->data
;
3933 QETH_DBF_MESSAGE(2, "skb bounce len: %d rest: %d\n", len
, rest
);
3937 EXPORT_SYMBOL_GPL(qeth_hdr_chk_and_bounce
);
3940 * qeth_push_hdr() - push a qeth_hdr onto an skb.
3941 * @skb: skb that the qeth_hdr should be pushed onto.
3942 * @hdr: double pointer to a qeth_hdr. When returning with >= 0,
3943 * it contains a valid pointer to a qeth_hdr.
3944 * @len: length of the hdr that needs to be pushed on.
3946 * Returns the pushed length. If the header can't be pushed on
3947 * (eg. because it would cross a page boundary), it is allocated from
3948 * the cache instead and 0 is returned.
3949 * Error to create the hdr is indicated by returning with < 0.
3951 int qeth_push_hdr(struct sk_buff
*skb
, struct qeth_hdr
**hdr
, unsigned int len
)
3953 if (skb_headroom(skb
) >= len
&&
3954 qeth_get_elements_for_range((addr_t
)skb
->data
- len
,
3955 (addr_t
)skb
->data
) == 1) {
3956 *hdr
= skb_push(skb
, len
);
3960 *hdr
= kmem_cache_alloc(qeth_core_header_cache
, GFP_ATOMIC
);
3965 EXPORT_SYMBOL_GPL(qeth_push_hdr
);
3967 static void __qeth_fill_buffer(struct sk_buff
*skb
,
3968 struct qeth_qdio_out_buffer
*buf
,
3969 bool is_first_elem
, unsigned int offset
)
3971 struct qdio_buffer
*buffer
= buf
->buffer
;
3972 int element
= buf
->next_element_to_fill
;
3973 int length
= skb_headlen(skb
) - offset
;
3974 char *data
= skb
->data
+ offset
;
3975 int length_here
, cnt
;
3977 /* map linear part into buffer element(s) */
3978 while (length
> 0) {
3979 /* length_here is the remaining amount of data in this page */
3980 length_here
= PAGE_SIZE
- ((unsigned long) data
% PAGE_SIZE
);
3981 if (length
< length_here
)
3982 length_here
= length
;
3984 buffer
->element
[element
].addr
= data
;
3985 buffer
->element
[element
].length
= length_here
;
3986 length
-= length_here
;
3987 if (is_first_elem
) {
3988 is_first_elem
= false;
3989 if (length
|| skb_is_nonlinear(skb
))
3990 /* skb needs additional elements */
3991 buffer
->element
[element
].eflags
=
3992 SBAL_EFLAGS_FIRST_FRAG
;
3994 buffer
->element
[element
].eflags
= 0;
3996 buffer
->element
[element
].eflags
=
3997 SBAL_EFLAGS_MIDDLE_FRAG
;
3999 data
+= length_here
;
4003 /* map page frags into buffer element(s) */
4004 for (cnt
= 0; cnt
< skb_shinfo(skb
)->nr_frags
; cnt
++) {
4005 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[cnt
];
4007 data
= skb_frag_address(frag
);
4008 length
= skb_frag_size(frag
);
4009 while (length
> 0) {
4010 length_here
= PAGE_SIZE
-
4011 ((unsigned long) data
% PAGE_SIZE
);
4012 if (length
< length_here
)
4013 length_here
= length
;
4015 buffer
->element
[element
].addr
= data
;
4016 buffer
->element
[element
].length
= length_here
;
4017 buffer
->element
[element
].eflags
=
4018 SBAL_EFLAGS_MIDDLE_FRAG
;
4019 length
-= length_here
;
4020 data
+= length_here
;
4025 if (buffer
->element
[element
- 1].eflags
)
4026 buffer
->element
[element
- 1].eflags
= SBAL_EFLAGS_LAST_FRAG
;
4027 buf
->next_element_to_fill
= element
;
4031 * qeth_fill_buffer() - map skb into an output buffer
4032 * @queue: QDIO queue to submit the buffer on
4033 * @buf: buffer to transport the skb
4034 * @skb: skb to map into the buffer
4035 * @hdr: qeth_hdr for this skb. Either at skb->data, or allocated
4036 * from qeth_core_header_cache.
4037 * @offset: when mapping the skb, start at skb->data + offset
4038 * @hd_len: if > 0, build a dedicated header element of this size
4040 static int qeth_fill_buffer(struct qeth_qdio_out_q
*queue
,
4041 struct qeth_qdio_out_buffer
*buf
,
4042 struct sk_buff
*skb
, struct qeth_hdr
*hdr
,
4043 unsigned int offset
, unsigned int hd_len
)
4045 struct qdio_buffer
*buffer
= buf
->buffer
;
4046 bool is_first_elem
= true;
4049 refcount_inc(&skb
->users
);
4050 skb_queue_tail(&buf
->skb_list
, skb
);
4052 /* build dedicated header element */
4054 int element
= buf
->next_element_to_fill
;
4055 is_first_elem
= false;
4057 buffer
->element
[element
].addr
= hdr
;
4058 buffer
->element
[element
].length
= hd_len
;
4059 buffer
->element
[element
].eflags
= SBAL_EFLAGS_FIRST_FRAG
;
4060 /* remember to free cache-allocated qeth_hdr: */
4061 buf
->is_header
[element
] = ((void *)hdr
!= skb
->data
);
4062 buf
->next_element_to_fill
++;
4065 __qeth_fill_buffer(skb
, buf
, is_first_elem
, offset
);
4067 if (!queue
->do_pack
) {
4068 QETH_CARD_TEXT(queue
->card
, 6, "fillbfnp");
4069 /* set state to PRIMED -> will be flushed */
4070 atomic_set(&buf
->state
, QETH_QDIO_BUF_PRIMED
);
4073 QETH_CARD_TEXT(queue
->card
, 6, "fillbfpa");
4074 if (queue
->card
->options
.performance_stats
)
4075 queue
->card
->perf_stats
.skbs_sent_pack
++;
4076 if (buf
->next_element_to_fill
>=
4077 QETH_MAX_BUFFER_ELEMENTS(queue
->card
)) {
4079 * packed buffer if full -> set state PRIMED
4080 * -> will be flushed
4082 atomic_set(&buf
->state
, QETH_QDIO_BUF_PRIMED
);
4089 int qeth_do_send_packet_fast(struct qeth_qdio_out_q
*queue
, struct sk_buff
*skb
,
4090 struct qeth_hdr
*hdr
, unsigned int offset
,
4091 unsigned int hd_len
)
4093 int index
= queue
->next_buf_to_fill
;
4094 struct qeth_qdio_out_buffer
*buffer
= queue
->bufs
[index
];
4097 * check if buffer is empty to make sure that we do not 'overtake'
4098 * ourselves and try to fill a buffer that is already primed
4100 if (atomic_read(&buffer
->state
) != QETH_QDIO_BUF_EMPTY
)
4102 queue
->next_buf_to_fill
= (index
+ 1) % QDIO_MAX_BUFFERS_PER_Q
;
4103 qeth_fill_buffer(queue
, buffer
, skb
, hdr
, offset
, hd_len
);
4104 qeth_flush_buffers(queue
, index
, 1);
4107 EXPORT_SYMBOL_GPL(qeth_do_send_packet_fast
);
4109 int qeth_do_send_packet(struct qeth_card
*card
, struct qeth_qdio_out_q
*queue
,
4110 struct sk_buff
*skb
, struct qeth_hdr
*hdr
,
4111 unsigned int offset
, unsigned int hd_len
,
4112 int elements_needed
)
4114 struct qeth_qdio_out_buffer
*buffer
;
4116 int flush_count
= 0;
4121 /* spin until we get the queue ... */
4122 while (atomic_cmpxchg(&queue
->state
, QETH_OUT_Q_UNLOCKED
,
4123 QETH_OUT_Q_LOCKED
) != QETH_OUT_Q_UNLOCKED
);
4124 start_index
= queue
->next_buf_to_fill
;
4125 buffer
= queue
->bufs
[queue
->next_buf_to_fill
];
4127 * check if buffer is empty to make sure that we do not 'overtake'
4128 * ourselves and try to fill a buffer that is already primed
4130 if (atomic_read(&buffer
->state
) != QETH_QDIO_BUF_EMPTY
) {
4131 atomic_set(&queue
->state
, QETH_OUT_Q_UNLOCKED
);
4134 /* check if we need to switch packing state of this queue */
4135 qeth_switch_to_packing_if_needed(queue
);
4136 if (queue
->do_pack
) {
4138 /* does packet fit in current buffer? */
4139 if ((QETH_MAX_BUFFER_ELEMENTS(card
) -
4140 buffer
->next_element_to_fill
) < elements_needed
) {
4141 /* ... no -> set state PRIMED */
4142 atomic_set(&buffer
->state
, QETH_QDIO_BUF_PRIMED
);
4144 queue
->next_buf_to_fill
=
4145 (queue
->next_buf_to_fill
+ 1) %
4146 QDIO_MAX_BUFFERS_PER_Q
;
4147 buffer
= queue
->bufs
[queue
->next_buf_to_fill
];
4148 /* we did a step forward, so check buffer state
4150 if (atomic_read(&buffer
->state
) !=
4151 QETH_QDIO_BUF_EMPTY
) {
4152 qeth_flush_buffers(queue
, start_index
,
4154 atomic_set(&queue
->state
,
4155 QETH_OUT_Q_UNLOCKED
);
4161 tmp
= qeth_fill_buffer(queue
, buffer
, skb
, hdr
, offset
, hd_len
);
4162 queue
->next_buf_to_fill
= (queue
->next_buf_to_fill
+ tmp
) %
4163 QDIO_MAX_BUFFERS_PER_Q
;
4166 qeth_flush_buffers(queue
, start_index
, flush_count
);
4167 else if (!atomic_read(&queue
->set_pci_flags_count
))
4168 atomic_xchg(&queue
->state
, QETH_OUT_Q_LOCKED_FLUSH
);
4170 * queue->state will go from LOCKED -> UNLOCKED or from
4171 * LOCKED_FLUSH -> LOCKED if output_handler wanted to 'notify' us
4172 * (switch packing state or flush buffer to get another pci flag out).
4173 * In that case we will enter this loop
4175 while (atomic_dec_return(&queue
->state
)) {
4176 start_index
= queue
->next_buf_to_fill
;
4177 /* check if we can go back to non-packing state */
4178 tmp
= qeth_switch_to_nonpacking_if_needed(queue
);
4180 * check if we need to flush a packing buffer to get a pci
4181 * flag out on the queue
4183 if (!tmp
&& !atomic_read(&queue
->set_pci_flags_count
))
4184 tmp
= qeth_prep_flush_pack_buffer(queue
);
4186 qeth_flush_buffers(queue
, start_index
, tmp
);
4191 /* at this point the queue is UNLOCKED again */
4192 if (queue
->card
->options
.performance_stats
&& do_pack
)
4193 queue
->card
->perf_stats
.bufs_sent_pack
+= flush_count
;
4197 EXPORT_SYMBOL_GPL(qeth_do_send_packet
);
4199 static int qeth_setadp_promisc_mode_cb(struct qeth_card
*card
,
4200 struct qeth_reply
*reply
, unsigned long data
)
4202 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
4203 struct qeth_ipacmd_setadpparms
*setparms
;
4205 QETH_CARD_TEXT(card
, 4, "prmadpcb");
4207 setparms
= &(cmd
->data
.setadapterparms
);
4208 if (qeth_setadpparms_inspect_rc(cmd
)) {
4209 QETH_CARD_TEXT_(card
, 4, "prmrc%x", cmd
->hdr
.return_code
);
4210 setparms
->data
.mode
= SET_PROMISC_MODE_OFF
;
4212 card
->info
.promisc_mode
= setparms
->data
.mode
;
4216 void qeth_setadp_promisc_mode(struct qeth_card
*card
)
4218 enum qeth_ipa_promisc_modes mode
;
4219 struct net_device
*dev
= card
->dev
;
4220 struct qeth_cmd_buffer
*iob
;
4221 struct qeth_ipa_cmd
*cmd
;
4223 QETH_CARD_TEXT(card
, 4, "setprom");
4225 if (((dev
->flags
& IFF_PROMISC
) &&
4226 (card
->info
.promisc_mode
== SET_PROMISC_MODE_ON
)) ||
4227 (!(dev
->flags
& IFF_PROMISC
) &&
4228 (card
->info
.promisc_mode
== SET_PROMISC_MODE_OFF
)))
4230 mode
= SET_PROMISC_MODE_OFF
;
4231 if (dev
->flags
& IFF_PROMISC
)
4232 mode
= SET_PROMISC_MODE_ON
;
4233 QETH_CARD_TEXT_(card
, 4, "mode:%x", mode
);
4235 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_SET_PROMISC_MODE
,
4236 sizeof(struct qeth_ipacmd_setadpparms_hdr
) + 8);
4239 cmd
= __ipa_cmd(iob
);
4240 cmd
->data
.setadapterparms
.data
.mode
= mode
;
4241 qeth_send_ipa_cmd(card
, iob
, qeth_setadp_promisc_mode_cb
, NULL
);
4243 EXPORT_SYMBOL_GPL(qeth_setadp_promisc_mode
);
4245 int qeth_change_mtu(struct net_device
*dev
, int new_mtu
)
4247 struct qeth_card
*card
;
4250 card
= dev
->ml_priv
;
4252 QETH_CARD_TEXT(card
, 4, "chgmtu");
4253 sprintf(dbf_text
, "%8x", new_mtu
);
4254 QETH_CARD_TEXT(card
, 4, dbf_text
);
4256 if (!qeth_mtu_is_valid(card
, new_mtu
))
4261 EXPORT_SYMBOL_GPL(qeth_change_mtu
);
4263 struct net_device_stats
*qeth_get_stats(struct net_device
*dev
)
4265 struct qeth_card
*card
;
4267 card
= dev
->ml_priv
;
4269 QETH_CARD_TEXT(card
, 5, "getstat");
4271 return &card
->stats
;
4273 EXPORT_SYMBOL_GPL(qeth_get_stats
);
4275 static int qeth_setadpparms_change_macaddr_cb(struct qeth_card
*card
,
4276 struct qeth_reply
*reply
, unsigned long data
)
4278 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
4280 QETH_CARD_TEXT(card
, 4, "chgmaccb");
4281 if (qeth_setadpparms_inspect_rc(cmd
))
4284 if (!card
->options
.layer2
||
4285 !(card
->info
.mac_bits
& QETH_LAYER2_MAC_READ
)) {
4286 ether_addr_copy(card
->dev
->dev_addr
,
4287 cmd
->data
.setadapterparms
.data
.change_addr
.addr
);
4288 card
->info
.mac_bits
|= QETH_LAYER2_MAC_READ
;
4293 int qeth_setadpparms_change_macaddr(struct qeth_card
*card
)
4296 struct qeth_cmd_buffer
*iob
;
4297 struct qeth_ipa_cmd
*cmd
;
4299 QETH_CARD_TEXT(card
, 4, "chgmac");
4301 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_ALTER_MAC_ADDRESS
,
4302 sizeof(struct qeth_ipacmd_setadpparms_hdr
) +
4303 sizeof(struct qeth_change_addr
));
4306 cmd
= __ipa_cmd(iob
);
4307 cmd
->data
.setadapterparms
.data
.change_addr
.cmd
= CHANGE_ADDR_READ_MAC
;
4308 cmd
->data
.setadapterparms
.data
.change_addr
.addr_size
= ETH_ALEN
;
4309 ether_addr_copy(cmd
->data
.setadapterparms
.data
.change_addr
.addr
,
4310 card
->dev
->dev_addr
);
4311 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_setadpparms_change_macaddr_cb
,
4315 EXPORT_SYMBOL_GPL(qeth_setadpparms_change_macaddr
);
4317 static int qeth_setadpparms_set_access_ctrl_cb(struct qeth_card
*card
,
4318 struct qeth_reply
*reply
, unsigned long data
)
4320 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
4321 struct qeth_set_access_ctrl
*access_ctrl_req
;
4322 int fallback
= *(int *)reply
->param
;
4324 QETH_CARD_TEXT(card
, 4, "setaccb");
4325 if (cmd
->hdr
.return_code
)
4327 qeth_setadpparms_inspect_rc(cmd
);
4329 access_ctrl_req
= &cmd
->data
.setadapterparms
.data
.set_access_ctrl
;
4330 QETH_DBF_TEXT_(SETUP
, 2, "setaccb");
4331 QETH_DBF_TEXT_(SETUP
, 2, "%s", card
->gdev
->dev
.kobj
.name
);
4332 QETH_DBF_TEXT_(SETUP
, 2, "rc=%d",
4333 cmd
->data
.setadapterparms
.hdr
.return_code
);
4334 if (cmd
->data
.setadapterparms
.hdr
.return_code
!=
4335 SET_ACCESS_CTRL_RC_SUCCESS
)
4336 QETH_DBF_MESSAGE(3, "ERR:SET_ACCESS_CTRL(%s,%d)==%d\n",
4337 card
->gdev
->dev
.kobj
.name
,
4338 access_ctrl_req
->subcmd_code
,
4339 cmd
->data
.setadapterparms
.hdr
.return_code
);
4340 switch (cmd
->data
.setadapterparms
.hdr
.return_code
) {
4341 case SET_ACCESS_CTRL_RC_SUCCESS
:
4342 if (card
->options
.isolation
== ISOLATION_MODE_NONE
) {
4343 dev_info(&card
->gdev
->dev
,
4344 "QDIO data connection isolation is deactivated\n");
4346 dev_info(&card
->gdev
->dev
,
4347 "QDIO data connection isolation is activated\n");
4350 case SET_ACCESS_CTRL_RC_ALREADY_NOT_ISOLATED
:
4351 QETH_DBF_MESSAGE(2, "%s QDIO data connection isolation already "
4352 "deactivated\n", dev_name(&card
->gdev
->dev
));
4354 card
->options
.isolation
= card
->options
.prev_isolation
;
4356 case SET_ACCESS_CTRL_RC_ALREADY_ISOLATED
:
4357 QETH_DBF_MESSAGE(2, "%s QDIO data connection isolation already"
4358 " activated\n", dev_name(&card
->gdev
->dev
));
4360 card
->options
.isolation
= card
->options
.prev_isolation
;
4362 case SET_ACCESS_CTRL_RC_NOT_SUPPORTED
:
4363 dev_err(&card
->gdev
->dev
, "Adapter does not "
4364 "support QDIO data connection isolation\n");
4366 case SET_ACCESS_CTRL_RC_NONE_SHARED_ADAPTER
:
4367 dev_err(&card
->gdev
->dev
,
4368 "Adapter is dedicated. "
4369 "QDIO data connection isolation not supported\n");
4371 card
->options
.isolation
= card
->options
.prev_isolation
;
4373 case SET_ACCESS_CTRL_RC_ACTIVE_CHECKSUM_OFF
:
4374 dev_err(&card
->gdev
->dev
,
4375 "TSO does not permit QDIO data connection isolation\n");
4377 card
->options
.isolation
= card
->options
.prev_isolation
;
4379 case SET_ACCESS_CTRL_RC_REFLREL_UNSUPPORTED
:
4380 dev_err(&card
->gdev
->dev
, "The adjacent switch port does not "
4381 "support reflective relay mode\n");
4383 card
->options
.isolation
= card
->options
.prev_isolation
;
4385 case SET_ACCESS_CTRL_RC_REFLREL_FAILED
:
4386 dev_err(&card
->gdev
->dev
, "The reflective relay mode cannot be "
4387 "enabled at the adjacent switch port");
4389 card
->options
.isolation
= card
->options
.prev_isolation
;
4391 case SET_ACCESS_CTRL_RC_REFLREL_DEACT_FAILED
:
4392 dev_warn(&card
->gdev
->dev
, "Turning off reflective relay mode "
4393 "at the adjacent switch failed\n");
4396 /* this should never happen */
4398 card
->options
.isolation
= card
->options
.prev_isolation
;
4404 static int qeth_setadpparms_set_access_ctrl(struct qeth_card
*card
,
4405 enum qeth_ipa_isolation_modes isolation
, int fallback
)
4408 struct qeth_cmd_buffer
*iob
;
4409 struct qeth_ipa_cmd
*cmd
;
4410 struct qeth_set_access_ctrl
*access_ctrl_req
;
4412 QETH_CARD_TEXT(card
, 4, "setacctl");
4414 QETH_DBF_TEXT_(SETUP
, 2, "setacctl");
4415 QETH_DBF_TEXT_(SETUP
, 2, "%s", card
->gdev
->dev
.kobj
.name
);
4417 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_SET_ACCESS_CONTROL
,
4418 sizeof(struct qeth_ipacmd_setadpparms_hdr
) +
4419 sizeof(struct qeth_set_access_ctrl
));
4422 cmd
= __ipa_cmd(iob
);
4423 access_ctrl_req
= &cmd
->data
.setadapterparms
.data
.set_access_ctrl
;
4424 access_ctrl_req
->subcmd_code
= isolation
;
4426 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_setadpparms_set_access_ctrl_cb
,
4428 QETH_DBF_TEXT_(SETUP
, 2, "rc=%d", rc
);
4432 int qeth_set_access_ctrl_online(struct qeth_card
*card
, int fallback
)
4436 QETH_CARD_TEXT(card
, 4, "setactlo");
4438 if ((card
->info
.type
== QETH_CARD_TYPE_OSD
||
4439 card
->info
.type
== QETH_CARD_TYPE_OSX
) &&
4440 qeth_adp_supported(card
, IPA_SETADP_SET_ACCESS_CONTROL
)) {
4441 rc
= qeth_setadpparms_set_access_ctrl(card
,
4442 card
->options
.isolation
, fallback
);
4445 "IPA(SET_ACCESS_CTRL,%s,%d) sent failed\n",
4446 card
->gdev
->dev
.kobj
.name
,
4450 } else if (card
->options
.isolation
!= ISOLATION_MODE_NONE
) {
4451 card
->options
.isolation
= ISOLATION_MODE_NONE
;
4453 dev_err(&card
->gdev
->dev
, "Adapter does not "
4454 "support QDIO data connection isolation\n");
4459 EXPORT_SYMBOL_GPL(qeth_set_access_ctrl_online
);
4461 void qeth_tx_timeout(struct net_device
*dev
)
4463 struct qeth_card
*card
;
4465 card
= dev
->ml_priv
;
4466 QETH_CARD_TEXT(card
, 4, "txtimeo");
4467 card
->stats
.tx_errors
++;
4468 qeth_schedule_recovery(card
);
4470 EXPORT_SYMBOL_GPL(qeth_tx_timeout
);
4472 static int qeth_mdio_read(struct net_device
*dev
, int phy_id
, int regnum
)
4474 struct qeth_card
*card
= dev
->ml_priv
;
4478 case MII_BMCR
: /* Basic mode control register */
4480 if ((card
->info
.link_type
!= QETH_LINK_TYPE_GBIT_ETH
) &&
4481 (card
->info
.link_type
!= QETH_LINK_TYPE_OSN
) &&
4482 (card
->info
.link_type
!= QETH_LINK_TYPE_10GBIT_ETH
))
4483 rc
|= BMCR_SPEED100
;
4485 case MII_BMSR
: /* Basic mode status register */
4486 rc
= BMSR_ERCAP
| BMSR_ANEGCOMPLETE
| BMSR_LSTATUS
|
4487 BMSR_10HALF
| BMSR_10FULL
| BMSR_100HALF
| BMSR_100FULL
|
4490 case MII_PHYSID1
: /* PHYS ID 1 */
4491 rc
= (dev
->dev_addr
[0] << 16) | (dev
->dev_addr
[1] << 8) |
4493 rc
= (rc
>> 5) & 0xFFFF;
4495 case MII_PHYSID2
: /* PHYS ID 2 */
4496 rc
= (dev
->dev_addr
[2] << 10) & 0xFFFF;
4498 case MII_ADVERTISE
: /* Advertisement control reg */
4501 case MII_LPA
: /* Link partner ability reg */
4502 rc
= LPA_10HALF
| LPA_10FULL
| LPA_100HALF
| LPA_100FULL
|
4503 LPA_100BASE4
| LPA_LPACK
;
4505 case MII_EXPANSION
: /* Expansion register */
4507 case MII_DCOUNTER
: /* disconnect counter */
4509 case MII_FCSCOUNTER
: /* false carrier counter */
4511 case MII_NWAYTEST
: /* N-way auto-neg test register */
4513 case MII_RERRCOUNTER
: /* rx error counter */
4514 rc
= card
->stats
.rx_errors
;
4516 case MII_SREVISION
: /* silicon revision */
4518 case MII_RESV1
: /* reserved 1 */
4520 case MII_LBRERROR
: /* loopback, rx, bypass error */
4522 case MII_PHYADDR
: /* physical address */
4524 case MII_RESV2
: /* reserved 2 */
4526 case MII_TPISTATUS
: /* TPI status for 10mbps */
4528 case MII_NCONFIG
: /* network interface config */
4536 static int qeth_send_ipa_snmp_cmd(struct qeth_card
*card
,
4537 struct qeth_cmd_buffer
*iob
, int len
,
4538 int (*reply_cb
)(struct qeth_card
*, struct qeth_reply
*,
4544 QETH_CARD_TEXT(card
, 4, "sendsnmp");
4546 memcpy(iob
->data
, IPA_PDU_HEADER
, IPA_PDU_HEADER_SIZE
);
4547 memcpy(QETH_IPA_CMD_DEST_ADDR(iob
->data
),
4548 &card
->token
.ulp_connection_r
, QETH_MPC_TOKEN_LENGTH
);
4549 /* adjust PDU length fields in IPA_PDU_HEADER */
4550 s1
= (u32
) IPA_PDU_HEADER_SIZE
+ len
;
4552 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob
->data
), &s1
, 2);
4553 memcpy(QETH_IPA_PDU_LEN_PDU1(iob
->data
), &s2
, 2);
4554 memcpy(QETH_IPA_PDU_LEN_PDU2(iob
->data
), &s2
, 2);
4555 memcpy(QETH_IPA_PDU_LEN_PDU3(iob
->data
), &s2
, 2);
4556 return qeth_send_control_data(card
, IPA_PDU_HEADER_SIZE
+ len
, iob
,
4557 reply_cb
, reply_param
);
4560 static int qeth_snmp_command_cb(struct qeth_card
*card
,
4561 struct qeth_reply
*reply
, unsigned long sdata
)
4563 struct qeth_ipa_cmd
*cmd
;
4564 struct qeth_arp_query_info
*qinfo
;
4565 struct qeth_snmp_cmd
*snmp
;
4566 unsigned char *data
;
4569 QETH_CARD_TEXT(card
, 3, "snpcmdcb");
4571 cmd
= (struct qeth_ipa_cmd
*) sdata
;
4572 data
= (unsigned char *)((char *)cmd
- reply
->offset
);
4573 qinfo
= (struct qeth_arp_query_info
*) reply
->param
;
4574 snmp
= &cmd
->data
.setadapterparms
.data
.snmp
;
4576 if (cmd
->hdr
.return_code
) {
4577 QETH_CARD_TEXT_(card
, 4, "scer1%x", cmd
->hdr
.return_code
);
4580 if (cmd
->data
.setadapterparms
.hdr
.return_code
) {
4581 cmd
->hdr
.return_code
=
4582 cmd
->data
.setadapterparms
.hdr
.return_code
;
4583 QETH_CARD_TEXT_(card
, 4, "scer2%x", cmd
->hdr
.return_code
);
4586 data_len
= *((__u16
*)QETH_IPA_PDU_LEN_PDU1(data
));
4587 if (cmd
->data
.setadapterparms
.hdr
.seq_no
== 1)
4588 data_len
-= (__u16
)((char *)&snmp
->data
- (char *)cmd
);
4590 data_len
-= (__u16
)((char *)&snmp
->request
- (char *)cmd
);
4592 /* check if there is enough room in userspace */
4593 if ((qinfo
->udata_len
- qinfo
->udata_offset
) < data_len
) {
4594 QETH_CARD_TEXT_(card
, 4, "scer3%i", -ENOMEM
);
4595 cmd
->hdr
.return_code
= IPA_RC_ENOMEM
;
4598 QETH_CARD_TEXT_(card
, 4, "snore%i",
4599 cmd
->data
.setadapterparms
.hdr
.used_total
);
4600 QETH_CARD_TEXT_(card
, 4, "sseqn%i",
4601 cmd
->data
.setadapterparms
.hdr
.seq_no
);
4602 /*copy entries to user buffer*/
4603 if (cmd
->data
.setadapterparms
.hdr
.seq_no
== 1) {
4604 memcpy(qinfo
->udata
+ qinfo
->udata_offset
,
4606 data_len
+ offsetof(struct qeth_snmp_cmd
, data
));
4607 qinfo
->udata_offset
+= offsetof(struct qeth_snmp_cmd
, data
);
4609 memcpy(qinfo
->udata
+ qinfo
->udata_offset
,
4610 (char *)&snmp
->request
, data_len
);
4612 qinfo
->udata_offset
+= data_len
;
4613 /* check if all replies received ... */
4614 QETH_CARD_TEXT_(card
, 4, "srtot%i",
4615 cmd
->data
.setadapterparms
.hdr
.used_total
);
4616 QETH_CARD_TEXT_(card
, 4, "srseq%i",
4617 cmd
->data
.setadapterparms
.hdr
.seq_no
);
4618 if (cmd
->data
.setadapterparms
.hdr
.seq_no
<
4619 cmd
->data
.setadapterparms
.hdr
.used_total
)
4624 static int qeth_snmp_command(struct qeth_card
*card
, char __user
*udata
)
4626 struct qeth_cmd_buffer
*iob
;
4627 struct qeth_ipa_cmd
*cmd
;
4628 struct qeth_snmp_ureq
*ureq
;
4629 unsigned int req_len
;
4630 struct qeth_arp_query_info qinfo
= {0, };
4633 QETH_CARD_TEXT(card
, 3, "snmpcmd");
4635 if (card
->info
.guestlan
)
4638 if ((!qeth_adp_supported(card
, IPA_SETADP_SET_SNMP_CONTROL
)) &&
4639 (!card
->options
.layer2
)) {
4642 /* skip 4 bytes (data_len struct member) to get req_len */
4643 if (copy_from_user(&req_len
, udata
+ sizeof(int), sizeof(int)))
4645 if (req_len
> (QETH_BUFSIZE
- IPA_PDU_HEADER_SIZE
-
4646 sizeof(struct qeth_ipacmd_hdr
) -
4647 sizeof(struct qeth_ipacmd_setadpparms_hdr
)))
4649 ureq
= memdup_user(udata
, req_len
+ sizeof(struct qeth_snmp_ureq_hdr
));
4651 QETH_CARD_TEXT(card
, 2, "snmpnome");
4652 return PTR_ERR(ureq
);
4654 qinfo
.udata_len
= ureq
->hdr
.data_len
;
4655 qinfo
.udata
= kzalloc(qinfo
.udata_len
, GFP_KERNEL
);
4660 qinfo
.udata_offset
= sizeof(struct qeth_snmp_ureq_hdr
);
4662 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_SET_SNMP_CONTROL
,
4663 QETH_SNMP_SETADP_CMDLENGTH
+ req_len
);
4668 cmd
= __ipa_cmd(iob
);
4669 memcpy(&cmd
->data
.setadapterparms
.data
.snmp
, &ureq
->cmd
, req_len
);
4670 rc
= qeth_send_ipa_snmp_cmd(card
, iob
, QETH_SETADP_BASE_LEN
+ req_len
,
4671 qeth_snmp_command_cb
, (void *)&qinfo
);
4673 QETH_DBF_MESSAGE(2, "SNMP command failed on %s: (0x%x)\n",
4674 QETH_CARD_IFNAME(card
), rc
);
4676 if (copy_to_user(udata
, qinfo
.udata
, qinfo
.udata_len
))
4685 static int qeth_setadpparms_query_oat_cb(struct qeth_card
*card
,
4686 struct qeth_reply
*reply
, unsigned long data
)
4688 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*)data
;
4689 struct qeth_qoat_priv
*priv
;
4693 QETH_CARD_TEXT(card
, 3, "qoatcb");
4694 if (qeth_setadpparms_inspect_rc(cmd
))
4697 priv
= (struct qeth_qoat_priv
*)reply
->param
;
4698 resdatalen
= cmd
->data
.setadapterparms
.hdr
.cmdlength
;
4699 resdata
= (char *)data
+ 28;
4701 if (resdatalen
> (priv
->buffer_len
- priv
->response_len
)) {
4702 cmd
->hdr
.return_code
= IPA_RC_FFFF
;
4706 memcpy((priv
->buffer
+ priv
->response_len
), resdata
,
4708 priv
->response_len
+= resdatalen
;
4710 if (cmd
->data
.setadapterparms
.hdr
.seq_no
<
4711 cmd
->data
.setadapterparms
.hdr
.used_total
)
4716 static int qeth_query_oat_command(struct qeth_card
*card
, char __user
*udata
)
4719 struct qeth_cmd_buffer
*iob
;
4720 struct qeth_ipa_cmd
*cmd
;
4721 struct qeth_query_oat
*oat_req
;
4722 struct qeth_query_oat_data oat_data
;
4723 struct qeth_qoat_priv priv
;
4726 QETH_CARD_TEXT(card
, 3, "qoatcmd");
4728 if (!qeth_adp_supported(card
, IPA_SETADP_QUERY_OAT
)) {
4733 if (copy_from_user(&oat_data
, udata
,
4734 sizeof(struct qeth_query_oat_data
))) {
4739 priv
.buffer_len
= oat_data
.buffer_len
;
4740 priv
.response_len
= 0;
4741 priv
.buffer
= kzalloc(oat_data
.buffer_len
, GFP_KERNEL
);
4747 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_QUERY_OAT
,
4748 sizeof(struct qeth_ipacmd_setadpparms_hdr
) +
4749 sizeof(struct qeth_query_oat
));
4754 cmd
= __ipa_cmd(iob
);
4755 oat_req
= &cmd
->data
.setadapterparms
.data
.query_oat
;
4756 oat_req
->subcmd_code
= oat_data
.command
;
4758 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_setadpparms_query_oat_cb
,
4761 if (is_compat_task())
4762 tmp
= compat_ptr(oat_data
.ptr
);
4764 tmp
= (void __user
*)(unsigned long)oat_data
.ptr
;
4766 if (copy_to_user(tmp
, priv
.buffer
,
4767 priv
.response_len
)) {
4772 oat_data
.response_len
= priv
.response_len
;
4774 if (copy_to_user(udata
, &oat_data
,
4775 sizeof(struct qeth_query_oat_data
)))
4778 if (rc
== IPA_RC_FFFF
)
4787 static int qeth_query_card_info_cb(struct qeth_card
*card
,
4788 struct qeth_reply
*reply
, unsigned long data
)
4790 struct carrier_info
*carrier_info
= (struct carrier_info
*)reply
->param
;
4791 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*)data
;
4792 struct qeth_query_card_info
*card_info
;
4794 QETH_CARD_TEXT(card
, 2, "qcrdincb");
4795 if (qeth_setadpparms_inspect_rc(cmd
))
4798 card_info
= &cmd
->data
.setadapterparms
.data
.card_info
;
4799 carrier_info
->card_type
= card_info
->card_type
;
4800 carrier_info
->port_mode
= card_info
->port_mode
;
4801 carrier_info
->port_speed
= card_info
->port_speed
;
4805 static int qeth_query_card_info(struct qeth_card
*card
,
4806 struct carrier_info
*carrier_info
)
4808 struct qeth_cmd_buffer
*iob
;
4810 QETH_CARD_TEXT(card
, 2, "qcrdinfo");
4811 if (!qeth_adp_supported(card
, IPA_SETADP_QUERY_CARD_INFO
))
4813 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_QUERY_CARD_INFO
,
4814 sizeof(struct qeth_ipacmd_setadpparms_hdr
));
4817 return qeth_send_ipa_cmd(card
, iob
, qeth_query_card_info_cb
,
4818 (void *)carrier_info
);
4822 * qeth_vm_request_mac() - Request a hypervisor-managed MAC address
4823 * @card: pointer to a qeth_card
4826 * 0, if a MAC address has been set for the card's netdevice
4827 * a return code, for various error conditions
4829 int qeth_vm_request_mac(struct qeth_card
*card
)
4831 struct diag26c_mac_resp
*response
;
4832 struct diag26c_mac_req
*request
;
4833 struct ccw_dev_id id
;
4836 QETH_DBF_TEXT(SETUP
, 2, "vmreqmac");
4841 request
= kzalloc(sizeof(*request
), GFP_KERNEL
| GFP_DMA
);
4842 response
= kzalloc(sizeof(*response
), GFP_KERNEL
| GFP_DMA
);
4843 if (!request
|| !response
) {
4848 ccw_device_get_id(CARD_DDEV(card
), &id
);
4849 request
->resp_buf_len
= sizeof(*response
);
4850 request
->resp_version
= DIAG26C_VERSION2
;
4851 request
->op_code
= DIAG26C_GET_MAC
;
4852 request
->devno
= id
.devno
;
4854 QETH_DBF_HEX(CTRL
, 2, request
, sizeof(*request
));
4855 rc
= diag26c(request
, response
, DIAG26C_MAC_SERVICES
);
4856 QETH_DBF_HEX(CTRL
, 2, request
, sizeof(*request
));
4859 QETH_DBF_HEX(CTRL
, 2, response
, sizeof(*response
));
4861 if (request
->resp_buf_len
< sizeof(*response
) ||
4862 response
->version
!= request
->resp_version
) {
4864 QETH_DBF_TEXT(SETUP
, 2, "badresp");
4865 QETH_DBF_HEX(SETUP
, 2, &request
->resp_buf_len
,
4866 sizeof(request
->resp_buf_len
));
4867 } else if (!is_valid_ether_addr(response
->mac
)) {
4869 QETH_DBF_TEXT(SETUP
, 2, "badmac");
4870 QETH_DBF_HEX(SETUP
, 2, response
->mac
, ETH_ALEN
);
4872 ether_addr_copy(card
->dev
->dev_addr
, response
->mac
);
4880 EXPORT_SYMBOL_GPL(qeth_vm_request_mac
);
4882 static int qeth_get_qdio_q_format(struct qeth_card
*card
)
4884 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
4885 return QDIO_IQDIO_QFMT
;
4887 return QDIO_QETH_QFMT
;
4890 static void qeth_determine_capabilities(struct qeth_card
*card
)
4895 struct ccw_device
*ddev
;
4896 int ddev_offline
= 0;
4898 QETH_DBF_TEXT(SETUP
, 2, "detcapab");
4899 ddev
= CARD_DDEV(card
);
4900 if (!ddev
->online
) {
4902 rc
= ccw_device_set_online(ddev
);
4904 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
4909 rc
= qeth_read_conf_data(card
, (void **) &prcd
, &length
);
4911 QETH_DBF_MESSAGE(2, "%s qeth_read_conf_data returned %i\n",
4912 dev_name(&card
->gdev
->dev
), rc
);
4913 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
4916 qeth_configure_unitaddr(card
, prcd
);
4918 qeth_configure_blkt_default(card
, prcd
);
4921 rc
= qdio_get_ssqd_desc(ddev
, &card
->ssqd
);
4923 QETH_DBF_TEXT_(SETUP
, 2, "6err%d", rc
);
4925 QETH_DBF_TEXT_(SETUP
, 2, "qfmt%d", card
->ssqd
.qfmt
);
4926 QETH_DBF_TEXT_(SETUP
, 2, "ac1:%02x", card
->ssqd
.qdioac1
);
4927 QETH_DBF_TEXT_(SETUP
, 2, "ac2:%04x", card
->ssqd
.qdioac2
);
4928 QETH_DBF_TEXT_(SETUP
, 2, "ac3:%04x", card
->ssqd
.qdioac3
);
4929 QETH_DBF_TEXT_(SETUP
, 2, "icnt%d", card
->ssqd
.icnt
);
4930 if (!((card
->ssqd
.qfmt
!= QDIO_IQDIO_QFMT
) ||
4931 ((card
->ssqd
.qdioac1
& CHSC_AC1_INITIATE_INPUTQ
) == 0) ||
4932 ((card
->ssqd
.qdioac3
& CHSC_AC3_FORMAT2_CQ_AVAILABLE
) == 0))) {
4933 dev_info(&card
->gdev
->dev
,
4934 "Completion Queueing supported\n");
4936 card
->options
.cq
= QETH_CQ_NOTAVAILABLE
;
4941 if (ddev_offline
== 1)
4942 ccw_device_set_offline(ddev
);
4947 static void qeth_qdio_establish_cq(struct qeth_card
*card
,
4948 struct qdio_buffer
**in_sbal_ptrs
,
4949 void (**queue_start_poll
)
4950 (struct ccw_device
*, int,
4955 if (card
->options
.cq
== QETH_CQ_ENABLED
) {
4956 int offset
= QDIO_MAX_BUFFERS_PER_Q
*
4957 (card
->qdio
.no_in_queues
- 1);
4958 for (i
= 0; i
< QDIO_MAX_BUFFERS_PER_Q
; ++i
) {
4959 in_sbal_ptrs
[offset
+ i
] = (struct qdio_buffer
*)
4960 virt_to_phys(card
->qdio
.c_q
->bufs
[i
].buffer
);
4963 queue_start_poll
[card
->qdio
.no_in_queues
- 1] = NULL
;
4967 static int qeth_qdio_establish(struct qeth_card
*card
)
4969 struct qdio_initialize init_data
;
4970 char *qib_param_field
;
4971 struct qdio_buffer
**in_sbal_ptrs
;
4972 void (**queue_start_poll
) (struct ccw_device
*, int, unsigned long);
4973 struct qdio_buffer
**out_sbal_ptrs
;
4977 QETH_DBF_TEXT(SETUP
, 2, "qdioest");
4979 qib_param_field
= kzalloc(QDIO_MAX_BUFFERS_PER_Q
,
4981 if (!qib_param_field
) {
4983 goto out_free_nothing
;
4986 qeth_create_qib_param_field(card
, qib_param_field
);
4987 qeth_create_qib_param_field_blkt(card
, qib_param_field
);
4989 in_sbal_ptrs
= kcalloc(card
->qdio
.no_in_queues
* QDIO_MAX_BUFFERS_PER_Q
,
4992 if (!in_sbal_ptrs
) {
4994 goto out_free_qib_param
;
4996 for (i
= 0; i
< QDIO_MAX_BUFFERS_PER_Q
; ++i
) {
4997 in_sbal_ptrs
[i
] = (struct qdio_buffer
*)
4998 virt_to_phys(card
->qdio
.in_q
->bufs
[i
].buffer
);
5001 queue_start_poll
= kcalloc(card
->qdio
.no_in_queues
, sizeof(void *),
5003 if (!queue_start_poll
) {
5005 goto out_free_in_sbals
;
5007 for (i
= 0; i
< card
->qdio
.no_in_queues
; ++i
)
5008 queue_start_poll
[i
] = qeth_qdio_start_poll
;
5010 qeth_qdio_establish_cq(card
, in_sbal_ptrs
, queue_start_poll
);
5013 kcalloc(card
->qdio
.no_out_queues
* QDIO_MAX_BUFFERS_PER_Q
,
5016 if (!out_sbal_ptrs
) {
5018 goto out_free_queue_start_poll
;
5020 for (i
= 0, k
= 0; i
< card
->qdio
.no_out_queues
; ++i
)
5021 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
, ++k
) {
5022 out_sbal_ptrs
[k
] = (struct qdio_buffer
*)virt_to_phys(
5023 card
->qdio
.out_qs
[i
]->bufs
[j
]->buffer
);
5026 memset(&init_data
, 0, sizeof(struct qdio_initialize
));
5027 init_data
.cdev
= CARD_DDEV(card
);
5028 init_data
.q_format
= qeth_get_qdio_q_format(card
);
5029 init_data
.qib_param_field_format
= 0;
5030 init_data
.qib_param_field
= qib_param_field
;
5031 init_data
.no_input_qs
= card
->qdio
.no_in_queues
;
5032 init_data
.no_output_qs
= card
->qdio
.no_out_queues
;
5033 init_data
.input_handler
= qeth_qdio_input_handler
;
5034 init_data
.output_handler
= qeth_qdio_output_handler
;
5035 init_data
.queue_start_poll_array
= queue_start_poll
;
5036 init_data
.int_parm
= (unsigned long) card
;
5037 init_data
.input_sbal_addr_array
= (void **) in_sbal_ptrs
;
5038 init_data
.output_sbal_addr_array
= (void **) out_sbal_ptrs
;
5039 init_data
.output_sbal_state_array
= card
->qdio
.out_bufstates
;
5040 init_data
.scan_threshold
=
5041 (card
->info
.type
== QETH_CARD_TYPE_IQD
) ? 1 : 32;
5043 if (atomic_cmpxchg(&card
->qdio
.state
, QETH_QDIO_ALLOCATED
,
5044 QETH_QDIO_ESTABLISHED
) == QETH_QDIO_ALLOCATED
) {
5045 rc
= qdio_allocate(&init_data
);
5047 atomic_set(&card
->qdio
.state
, QETH_QDIO_ALLOCATED
);
5050 rc
= qdio_establish(&init_data
);
5052 atomic_set(&card
->qdio
.state
, QETH_QDIO_ALLOCATED
);
5053 qdio_free(CARD_DDEV(card
));
5057 switch (card
->options
.cq
) {
5058 case QETH_CQ_ENABLED
:
5059 dev_info(&card
->gdev
->dev
, "Completion Queue support enabled");
5061 case QETH_CQ_DISABLED
:
5062 dev_info(&card
->gdev
->dev
, "Completion Queue support disabled");
5068 kfree(out_sbal_ptrs
);
5069 out_free_queue_start_poll
:
5070 kfree(queue_start_poll
);
5072 kfree(in_sbal_ptrs
);
5074 kfree(qib_param_field
);
5079 static void qeth_core_free_card(struct qeth_card
*card
)
5082 QETH_DBF_TEXT(SETUP
, 2, "freecrd");
5083 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
5084 qeth_clean_channel(&card
->read
);
5085 qeth_clean_channel(&card
->write
);
5086 qeth_free_qdio_buffers(card
);
5087 unregister_service_level(&card
->qeth_service_level
);
5091 void qeth_trace_features(struct qeth_card
*card
)
5093 QETH_CARD_TEXT(card
, 2, "features");
5094 QETH_CARD_HEX(card
, 2, &card
->options
.ipa4
, sizeof(card
->options
.ipa4
));
5095 QETH_CARD_HEX(card
, 2, &card
->options
.ipa6
, sizeof(card
->options
.ipa6
));
5096 QETH_CARD_HEX(card
, 2, &card
->options
.adp
, sizeof(card
->options
.adp
));
5097 QETH_CARD_HEX(card
, 2, &card
->info
.diagass_support
,
5098 sizeof(card
->info
.diagass_support
));
5100 EXPORT_SYMBOL_GPL(qeth_trace_features
);
5102 static struct ccw_device_id qeth_ids
[] = {
5103 {CCW_DEVICE_DEVTYPE(0x1731, 0x01, 0x1732, 0x01),
5104 .driver_info
= QETH_CARD_TYPE_OSD
},
5105 {CCW_DEVICE_DEVTYPE(0x1731, 0x05, 0x1732, 0x05),
5106 .driver_info
= QETH_CARD_TYPE_IQD
},
5107 {CCW_DEVICE_DEVTYPE(0x1731, 0x06, 0x1732, 0x06),
5108 .driver_info
= QETH_CARD_TYPE_OSN
},
5109 {CCW_DEVICE_DEVTYPE(0x1731, 0x02, 0x1732, 0x03),
5110 .driver_info
= QETH_CARD_TYPE_OSM
},
5111 {CCW_DEVICE_DEVTYPE(0x1731, 0x02, 0x1732, 0x02),
5112 .driver_info
= QETH_CARD_TYPE_OSX
},
5115 MODULE_DEVICE_TABLE(ccw
, qeth_ids
);
5117 static struct ccw_driver qeth_ccw_driver
= {
5119 .owner
= THIS_MODULE
,
5123 .probe
= ccwgroup_probe_ccwdev
,
5124 .remove
= ccwgroup_remove_ccwdev
,
5127 int qeth_core_hardsetup_card(struct qeth_card
*card
)
5132 QETH_DBF_TEXT(SETUP
, 2, "hrdsetup");
5133 atomic_set(&card
->force_alloc_skb
, 0);
5134 qeth_update_from_chp_desc(card
);
5137 QETH_DBF_MESSAGE(2, "%s Retrying to do IDX activates.\n",
5138 dev_name(&card
->gdev
->dev
));
5139 rc
= qeth_qdio_clear_card(card
, card
->info
.type
!= QETH_CARD_TYPE_IQD
);
5140 ccw_device_set_offline(CARD_DDEV(card
));
5141 ccw_device_set_offline(CARD_WDEV(card
));
5142 ccw_device_set_offline(CARD_RDEV(card
));
5143 qdio_free(CARD_DDEV(card
));
5144 rc
= ccw_device_set_online(CARD_RDEV(card
));
5147 rc
= ccw_device_set_online(CARD_WDEV(card
));
5150 rc
= ccw_device_set_online(CARD_DDEV(card
));
5154 if (rc
== -ERESTARTSYS
) {
5155 QETH_DBF_TEXT(SETUP
, 2, "break1");
5158 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
5164 qeth_determine_capabilities(card
);
5165 qeth_init_tokens(card
);
5166 qeth_init_func_level(card
);
5167 rc
= qeth_idx_activate_channel(&card
->read
, qeth_idx_read_cb
);
5168 if (rc
== -ERESTARTSYS
) {
5169 QETH_DBF_TEXT(SETUP
, 2, "break2");
5172 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
5178 rc
= qeth_idx_activate_channel(&card
->write
, qeth_idx_write_cb
);
5179 if (rc
== -ERESTARTSYS
) {
5180 QETH_DBF_TEXT(SETUP
, 2, "break3");
5183 QETH_DBF_TEXT_(SETUP
, 2, "4err%d", rc
);
5189 card
->read_or_write_problem
= 0;
5190 rc
= qeth_mpc_initialize(card
);
5192 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
5196 rc
= qeth_send_startlan(card
);
5198 QETH_DBF_TEXT_(SETUP
, 2, "6err%d", rc
);
5199 if (rc
== IPA_RC_LAN_OFFLINE
) {
5200 dev_warn(&card
->gdev
->dev
,
5201 "The LAN is offline\n");
5202 card
->lan_online
= 0;
5208 card
->lan_online
= 1;
5210 card
->options
.ipa4
.supported_funcs
= 0;
5211 card
->options
.ipa6
.supported_funcs
= 0;
5212 card
->options
.adp
.supported_funcs
= 0;
5213 card
->options
.sbp
.supported_funcs
= 0;
5214 card
->info
.diagass_support
= 0;
5215 rc
= qeth_query_ipassists(card
, QETH_PROT_IPV4
);
5218 if (qeth_is_supported(card
, IPA_IPV6
)) {
5219 rc
= qeth_query_ipassists(card
, QETH_PROT_IPV6
);
5223 if (qeth_is_supported(card
, IPA_SETADAPTERPARMS
)) {
5224 rc
= qeth_query_setadapterparms(card
);
5226 QETH_DBF_TEXT_(SETUP
, 2, "7err%d", rc
);
5230 if (qeth_adp_supported(card
, IPA_SETADP_SET_DIAG_ASSIST
)) {
5231 rc
= qeth_query_setdiagass(card
);
5233 QETH_DBF_TEXT_(SETUP
, 2, "8err%d", rc
);
5239 dev_warn(&card
->gdev
->dev
, "The qeth device driver failed to recover "
5240 "an error on the device\n");
5241 QETH_DBF_MESSAGE(2, "%s Initialization in hardsetup failed! rc=%d\n",
5242 dev_name(&card
->gdev
->dev
), rc
);
5245 EXPORT_SYMBOL_GPL(qeth_core_hardsetup_card
);
5247 static void qeth_create_skb_frag(struct qdio_buffer_element
*element
,
5248 struct sk_buff
*skb
, int offset
, int data_len
)
5250 struct page
*page
= virt_to_page(element
->addr
);
5251 unsigned int next_frag
;
5253 /* first fill the linear space */
5255 unsigned int linear
= min(data_len
, skb_tailroom(skb
));
5257 skb_put_data(skb
, element
->addr
+ offset
, linear
);
5262 /* fall through to add page frag for remaining data */
5265 next_frag
= skb_shinfo(skb
)->nr_frags
;
5267 skb_add_rx_frag(skb
, next_frag
, page
, offset
, data_len
, data_len
);
5270 static inline int qeth_is_last_sbale(struct qdio_buffer_element
*sbale
)
5272 return (sbale
->eflags
& SBAL_EFLAGS_LAST_ENTRY
);
5275 struct sk_buff
*qeth_core_get_next_skb(struct qeth_card
*card
,
5276 struct qeth_qdio_buffer
*qethbuffer
,
5277 struct qdio_buffer_element
**__element
, int *__offset
,
5278 struct qeth_hdr
**hdr
)
5280 struct qdio_buffer_element
*element
= *__element
;
5281 struct qdio_buffer
*buffer
= qethbuffer
->buffer
;
5282 int offset
= *__offset
;
5283 struct sk_buff
*skb
;
5290 /* qeth_hdr must not cross element boundaries */
5291 while (element
->length
< offset
+ sizeof(struct qeth_hdr
)) {
5292 if (qeth_is_last_sbale(element
))
5297 *hdr
= element
->addr
+ offset
;
5299 offset
+= sizeof(struct qeth_hdr
);
5300 switch ((*hdr
)->hdr
.l2
.id
) {
5301 case QETH_HEADER_TYPE_LAYER2
:
5302 skb_len
= (*hdr
)->hdr
.l2
.pkt_length
;
5304 case QETH_HEADER_TYPE_LAYER3
:
5305 skb_len
= (*hdr
)->hdr
.l3
.length
;
5306 headroom
= ETH_HLEN
;
5308 case QETH_HEADER_TYPE_OSN
:
5309 skb_len
= (*hdr
)->hdr
.osn
.pdu_length
;
5310 headroom
= sizeof(struct qeth_hdr
);
5319 if (((skb_len
>= card
->options
.rx_sg_cb
) &&
5320 (!(card
->info
.type
== QETH_CARD_TYPE_OSN
)) &&
5321 (!atomic_read(&card
->force_alloc_skb
))) ||
5322 (card
->options
.cq
== QETH_CQ_ENABLED
))
5325 if (use_rx_sg
&& qethbuffer
->rx_skb
) {
5326 /* QETH_CQ_ENABLED only: */
5327 skb
= qethbuffer
->rx_skb
;
5328 qethbuffer
->rx_skb
= NULL
;
5330 unsigned int linear
= (use_rx_sg
) ? QETH_RX_PULL_LEN
: skb_len
;
5332 skb
= napi_alloc_skb(&card
->napi
, linear
+ headroom
);
5337 skb_reserve(skb
, headroom
);
5339 data_ptr
= element
->addr
+ offset
;
5341 data_len
= min(skb_len
, (int)(element
->length
- offset
));
5344 qeth_create_skb_frag(element
, skb
, offset
,
5347 skb_put_data(skb
, data_ptr
, data_len
);
5349 skb_len
-= data_len
;
5351 if (qeth_is_last_sbale(element
)) {
5352 QETH_CARD_TEXT(card
, 4, "unexeob");
5353 QETH_CARD_HEX(card
, 2, buffer
, sizeof(void *));
5354 dev_kfree_skb_any(skb
);
5355 card
->stats
.rx_errors
++;
5360 data_ptr
= element
->addr
;
5365 *__element
= element
;
5367 if (use_rx_sg
&& card
->options
.performance_stats
) {
5368 card
->perf_stats
.sg_skbs_rx
++;
5369 card
->perf_stats
.sg_frags_rx
+= skb_shinfo(skb
)->nr_frags
;
5373 if (net_ratelimit()) {
5374 QETH_CARD_TEXT(card
, 2, "noskbmem");
5376 card
->stats
.rx_dropped
++;
5379 EXPORT_SYMBOL_GPL(qeth_core_get_next_skb
);
5381 int qeth_poll(struct napi_struct
*napi
, int budget
)
5383 struct qeth_card
*card
= container_of(napi
, struct qeth_card
, napi
);
5385 struct qeth_qdio_buffer
*buffer
;
5387 int new_budget
= budget
;
5389 if (card
->options
.performance_stats
) {
5390 card
->perf_stats
.inbound_cnt
++;
5391 card
->perf_stats
.inbound_start_time
= qeth_get_micros();
5395 if (!card
->rx
.b_count
) {
5396 card
->rx
.qdio_err
= 0;
5397 card
->rx
.b_count
= qdio_get_next_buffers(
5398 card
->data
.ccwdev
, 0, &card
->rx
.b_index
,
5399 &card
->rx
.qdio_err
);
5400 if (card
->rx
.b_count
<= 0) {
5401 card
->rx
.b_count
= 0;
5404 card
->rx
.b_element
=
5405 &card
->qdio
.in_q
->bufs
[card
->rx
.b_index
]
5406 .buffer
->element
[0];
5407 card
->rx
.e_offset
= 0;
5410 while (card
->rx
.b_count
) {
5411 buffer
= &card
->qdio
.in_q
->bufs
[card
->rx
.b_index
];
5412 if (!(card
->rx
.qdio_err
&&
5413 qeth_check_qdio_errors(card
, buffer
->buffer
,
5414 card
->rx
.qdio_err
, "qinerr")))
5416 card
->discipline
->process_rx_buffer(
5417 card
, new_budget
, &done
);
5422 if (card
->options
.performance_stats
)
5423 card
->perf_stats
.bufs_rec
++;
5424 qeth_put_buffer_pool_entry(card
,
5425 buffer
->pool_entry
);
5426 qeth_queue_input_buffer(card
, card
->rx
.b_index
);
5428 if (card
->rx
.b_count
) {
5430 (card
->rx
.b_index
+ 1) %
5431 QDIO_MAX_BUFFERS_PER_Q
;
5432 card
->rx
.b_element
=
5434 ->bufs
[card
->rx
.b_index
]
5435 .buffer
->element
[0];
5436 card
->rx
.e_offset
= 0;
5440 if (work_done
>= budget
)
5443 new_budget
= budget
- work_done
;
5447 napi_complete_done(napi
, work_done
);
5448 if (qdio_start_irq(card
->data
.ccwdev
, 0))
5449 napi_schedule(&card
->napi
);
5451 if (card
->options
.performance_stats
)
5452 card
->perf_stats
.inbound_time
+= qeth_get_micros() -
5453 card
->perf_stats
.inbound_start_time
;
5456 EXPORT_SYMBOL_GPL(qeth_poll
);
5458 static int qeth_setassparms_inspect_rc(struct qeth_ipa_cmd
*cmd
)
5460 if (!cmd
->hdr
.return_code
)
5461 cmd
->hdr
.return_code
= cmd
->data
.setassparms
.hdr
.return_code
;
5462 return cmd
->hdr
.return_code
;
5465 int qeth_setassparms_cb(struct qeth_card
*card
,
5466 struct qeth_reply
*reply
, unsigned long data
)
5468 struct qeth_ipa_cmd
*cmd
;
5470 QETH_CARD_TEXT(card
, 4, "defadpcb");
5472 cmd
= (struct qeth_ipa_cmd
*) data
;
5473 if (cmd
->hdr
.return_code
== 0) {
5474 cmd
->hdr
.return_code
= cmd
->data
.setassparms
.hdr
.return_code
;
5475 if (cmd
->hdr
.prot_version
== QETH_PROT_IPV4
)
5476 card
->options
.ipa4
.enabled_funcs
= cmd
->hdr
.ipa_enabled
;
5477 if (cmd
->hdr
.prot_version
== QETH_PROT_IPV6
)
5478 card
->options
.ipa6
.enabled_funcs
= cmd
->hdr
.ipa_enabled
;
5482 EXPORT_SYMBOL_GPL(qeth_setassparms_cb
);
5484 struct qeth_cmd_buffer
*qeth_get_setassparms_cmd(struct qeth_card
*card
,
5485 enum qeth_ipa_funcs ipa_func
,
5486 __u16 cmd_code
, __u16 len
,
5487 enum qeth_prot_versions prot
)
5489 struct qeth_cmd_buffer
*iob
;
5490 struct qeth_ipa_cmd
*cmd
;
5492 QETH_CARD_TEXT(card
, 4, "getasscm");
5493 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SETASSPARMS
, prot
);
5496 cmd
= __ipa_cmd(iob
);
5497 cmd
->data
.setassparms
.hdr
.assist_no
= ipa_func
;
5498 cmd
->data
.setassparms
.hdr
.length
= 8 + len
;
5499 cmd
->data
.setassparms
.hdr
.command_code
= cmd_code
;
5500 cmd
->data
.setassparms
.hdr
.return_code
= 0;
5501 cmd
->data
.setassparms
.hdr
.seq_no
= 0;
5506 EXPORT_SYMBOL_GPL(qeth_get_setassparms_cmd
);
5508 int qeth_send_setassparms(struct qeth_card
*card
,
5509 struct qeth_cmd_buffer
*iob
, __u16 len
, long data
,
5510 int (*reply_cb
)(struct qeth_card
*,
5511 struct qeth_reply
*, unsigned long),
5515 struct qeth_ipa_cmd
*cmd
;
5517 QETH_CARD_TEXT(card
, 4, "sendassp");
5519 cmd
= __ipa_cmd(iob
);
5520 if (len
<= sizeof(__u32
))
5521 cmd
->data
.setassparms
.data
.flags_32bit
= (__u32
) data
;
5522 else /* (len > sizeof(__u32)) */
5523 memcpy(&cmd
->data
.setassparms
.data
, (void *) data
, len
);
5525 rc
= qeth_send_ipa_cmd(card
, iob
, reply_cb
, reply_param
);
5528 EXPORT_SYMBOL_GPL(qeth_send_setassparms
);
5530 int qeth_send_simple_setassparms_prot(struct qeth_card
*card
,
5531 enum qeth_ipa_funcs ipa_func
,
5532 u16 cmd_code
, long data
,
5533 enum qeth_prot_versions prot
)
5537 struct qeth_cmd_buffer
*iob
;
5539 QETH_CARD_TEXT_(card
, 4, "simassp%i", prot
);
5541 length
= sizeof(__u32
);
5542 iob
= qeth_get_setassparms_cmd(card
, ipa_func
, cmd_code
, length
, prot
);
5545 rc
= qeth_send_setassparms(card
, iob
, length
, data
,
5546 qeth_setassparms_cb
, NULL
);
5549 EXPORT_SYMBOL_GPL(qeth_send_simple_setassparms_prot
);
5551 static void qeth_unregister_dbf_views(void)
5554 for (x
= 0; x
< QETH_DBF_INFOS
; x
++) {
5555 debug_unregister(qeth_dbf
[x
].id
);
5556 qeth_dbf
[x
].id
= NULL
;
5560 void qeth_dbf_longtext(debug_info_t
*id
, int level
, char *fmt
, ...)
5562 char dbf_txt_buf
[32];
5565 if (!debug_level_enabled(id
, level
))
5567 va_start(args
, fmt
);
5568 vsnprintf(dbf_txt_buf
, sizeof(dbf_txt_buf
), fmt
, args
);
5570 debug_text_event(id
, level
, dbf_txt_buf
);
5572 EXPORT_SYMBOL_GPL(qeth_dbf_longtext
);
5574 static int qeth_register_dbf_views(void)
5579 for (x
= 0; x
< QETH_DBF_INFOS
; x
++) {
5580 /* register the areas */
5581 qeth_dbf
[x
].id
= debug_register(qeth_dbf
[x
].name
,
5585 if (qeth_dbf
[x
].id
== NULL
) {
5586 qeth_unregister_dbf_views();
5590 /* register a view */
5591 ret
= debug_register_view(qeth_dbf
[x
].id
, qeth_dbf
[x
].view
);
5593 qeth_unregister_dbf_views();
5597 /* set a passing level */
5598 debug_set_level(qeth_dbf
[x
].id
, qeth_dbf
[x
].level
);
5604 int qeth_core_load_discipline(struct qeth_card
*card
,
5605 enum qeth_discipline_id discipline
)
5609 mutex_lock(&qeth_mod_mutex
);
5610 switch (discipline
) {
5611 case QETH_DISCIPLINE_LAYER3
:
5612 card
->discipline
= try_then_request_module(
5613 symbol_get(qeth_l3_discipline
), "qeth_l3");
5615 case QETH_DISCIPLINE_LAYER2
:
5616 card
->discipline
= try_then_request_module(
5617 symbol_get(qeth_l2_discipline
), "qeth_l2");
5623 if (!card
->discipline
) {
5624 dev_err(&card
->gdev
->dev
, "There is no kernel module to "
5625 "support discipline %d\n", discipline
);
5628 mutex_unlock(&qeth_mod_mutex
);
5632 void qeth_core_free_discipline(struct qeth_card
*card
)
5634 if (card
->options
.layer2
)
5635 symbol_put(qeth_l2_discipline
);
5637 symbol_put(qeth_l3_discipline
);
5638 card
->discipline
= NULL
;
5641 const struct device_type qeth_generic_devtype
= {
5642 .name
= "qeth_generic",
5643 .groups
= qeth_generic_attr_groups
,
5645 EXPORT_SYMBOL_GPL(qeth_generic_devtype
);
5647 static const struct device_type qeth_osn_devtype
= {
5649 .groups
= qeth_osn_attr_groups
,
5652 #define DBF_NAME_LEN 20
5654 struct qeth_dbf_entry
{
5655 char dbf_name
[DBF_NAME_LEN
];
5656 debug_info_t
*dbf_info
;
5657 struct list_head dbf_list
;
5660 static LIST_HEAD(qeth_dbf_list
);
5661 static DEFINE_MUTEX(qeth_dbf_list_mutex
);
5663 static debug_info_t
*qeth_get_dbf_entry(char *name
)
5665 struct qeth_dbf_entry
*entry
;
5666 debug_info_t
*rc
= NULL
;
5668 mutex_lock(&qeth_dbf_list_mutex
);
5669 list_for_each_entry(entry
, &qeth_dbf_list
, dbf_list
) {
5670 if (strcmp(entry
->dbf_name
, name
) == 0) {
5671 rc
= entry
->dbf_info
;
5675 mutex_unlock(&qeth_dbf_list_mutex
);
5679 static int qeth_add_dbf_entry(struct qeth_card
*card
, char *name
)
5681 struct qeth_dbf_entry
*new_entry
;
5683 card
->debug
= debug_register(name
, 2, 1, 8);
5685 QETH_DBF_TEXT_(SETUP
, 2, "%s", "qcdbf");
5688 if (debug_register_view(card
->debug
, &debug_hex_ascii_view
))
5690 new_entry
= kzalloc(sizeof(struct qeth_dbf_entry
), GFP_KERNEL
);
5693 strncpy(new_entry
->dbf_name
, name
, DBF_NAME_LEN
);
5694 new_entry
->dbf_info
= card
->debug
;
5695 mutex_lock(&qeth_dbf_list_mutex
);
5696 list_add(&new_entry
->dbf_list
, &qeth_dbf_list
);
5697 mutex_unlock(&qeth_dbf_list_mutex
);
5702 debug_unregister(card
->debug
);
5707 static void qeth_clear_dbf_list(void)
5709 struct qeth_dbf_entry
*entry
, *tmp
;
5711 mutex_lock(&qeth_dbf_list_mutex
);
5712 list_for_each_entry_safe(entry
, tmp
, &qeth_dbf_list
, dbf_list
) {
5713 list_del(&entry
->dbf_list
);
5714 debug_unregister(entry
->dbf_info
);
5717 mutex_unlock(&qeth_dbf_list_mutex
);
5720 static int qeth_core_probe_device(struct ccwgroup_device
*gdev
)
5722 struct qeth_card
*card
;
5725 enum qeth_discipline_id enforced_disc
;
5726 unsigned long flags
;
5727 char dbf_name
[DBF_NAME_LEN
];
5729 QETH_DBF_TEXT(SETUP
, 2, "probedev");
5732 if (!get_device(dev
))
5735 QETH_DBF_TEXT_(SETUP
, 2, "%s", dev_name(&gdev
->dev
));
5737 card
= qeth_alloc_card();
5739 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", -ENOMEM
);
5744 snprintf(dbf_name
, sizeof(dbf_name
), "qeth_card_%s",
5745 dev_name(&gdev
->dev
));
5746 card
->debug
= qeth_get_dbf_entry(dbf_name
);
5748 rc
= qeth_add_dbf_entry(card
, dbf_name
);
5753 card
->read
.ccwdev
= gdev
->cdev
[0];
5754 card
->write
.ccwdev
= gdev
->cdev
[1];
5755 card
->data
.ccwdev
= gdev
->cdev
[2];
5756 dev_set_drvdata(&gdev
->dev
, card
);
5758 gdev
->cdev
[0]->handler
= qeth_irq
;
5759 gdev
->cdev
[1]->handler
= qeth_irq
;
5760 gdev
->cdev
[2]->handler
= qeth_irq
;
5762 qeth_determine_card_type(card
);
5763 rc
= qeth_setup_card(card
);
5765 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
5769 qeth_determine_capabilities(card
);
5770 enforced_disc
= qeth_enforce_discipline(card
);
5771 switch (enforced_disc
) {
5772 case QETH_DISCIPLINE_UNDETERMINED
:
5773 gdev
->dev
.type
= &qeth_generic_devtype
;
5776 card
->info
.layer_enforced
= true;
5777 rc
= qeth_core_load_discipline(card
, enforced_disc
);
5781 gdev
->dev
.type
= (card
->info
.type
!= QETH_CARD_TYPE_OSN
)
5782 ? card
->discipline
->devtype
5783 : &qeth_osn_devtype
;
5784 rc
= card
->discipline
->setup(card
->gdev
);
5790 write_lock_irqsave(&qeth_core_card_list
.rwlock
, flags
);
5791 list_add_tail(&card
->list
, &qeth_core_card_list
.list
);
5792 write_unlock_irqrestore(&qeth_core_card_list
.rwlock
, flags
);
5796 qeth_core_free_discipline(card
);
5798 qeth_core_free_card(card
);
5804 static void qeth_core_remove_device(struct ccwgroup_device
*gdev
)
5806 unsigned long flags
;
5807 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5809 QETH_DBF_TEXT(SETUP
, 2, "removedv");
5811 if (card
->discipline
) {
5812 card
->discipline
->remove(gdev
);
5813 qeth_core_free_discipline(card
);
5816 write_lock_irqsave(&qeth_core_card_list
.rwlock
, flags
);
5817 list_del(&card
->list
);
5818 write_unlock_irqrestore(&qeth_core_card_list
.rwlock
, flags
);
5819 qeth_core_free_card(card
);
5820 dev_set_drvdata(&gdev
->dev
, NULL
);
5821 put_device(&gdev
->dev
);
5825 static int qeth_core_set_online(struct ccwgroup_device
*gdev
)
5827 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5829 enum qeth_discipline_id def_discipline
;
5831 if (!card
->discipline
) {
5832 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
5833 def_discipline
= QETH_DISCIPLINE_LAYER3
;
5835 def_discipline
= QETH_DISCIPLINE_LAYER2
;
5836 rc
= qeth_core_load_discipline(card
, def_discipline
);
5839 rc
= card
->discipline
->setup(card
->gdev
);
5841 qeth_core_free_discipline(card
);
5845 rc
= card
->discipline
->set_online(gdev
);
5850 static int qeth_core_set_offline(struct ccwgroup_device
*gdev
)
5852 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5853 return card
->discipline
->set_offline(gdev
);
5856 static void qeth_core_shutdown(struct ccwgroup_device
*gdev
)
5858 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5859 qeth_set_allowed_threads(card
, 0, 1);
5860 if ((gdev
->state
== CCWGROUP_ONLINE
) && card
->info
.hwtrap
)
5861 qeth_hw_trap(card
, QETH_DIAGS_TRAP_DISARM
);
5862 qeth_qdio_clear_card(card
, 0);
5863 qeth_clear_qdio_buffers(card
);
5864 qdio_free(CARD_DDEV(card
));
5867 static int qeth_core_freeze(struct ccwgroup_device
*gdev
)
5869 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5870 if (card
->discipline
&& card
->discipline
->freeze
)
5871 return card
->discipline
->freeze(gdev
);
5875 static int qeth_core_thaw(struct ccwgroup_device
*gdev
)
5877 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5878 if (card
->discipline
&& card
->discipline
->thaw
)
5879 return card
->discipline
->thaw(gdev
);
5883 static int qeth_core_restore(struct ccwgroup_device
*gdev
)
5885 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5886 if (card
->discipline
&& card
->discipline
->restore
)
5887 return card
->discipline
->restore(gdev
);
5891 static struct ccwgroup_driver qeth_core_ccwgroup_driver
= {
5893 .owner
= THIS_MODULE
,
5896 .ccw_driver
= &qeth_ccw_driver
,
5897 .setup
= qeth_core_probe_device
,
5898 .remove
= qeth_core_remove_device
,
5899 .set_online
= qeth_core_set_online
,
5900 .set_offline
= qeth_core_set_offline
,
5901 .shutdown
= qeth_core_shutdown
,
5904 .freeze
= qeth_core_freeze
,
5905 .thaw
= qeth_core_thaw
,
5906 .restore
= qeth_core_restore
,
5909 static ssize_t
group_store(struct device_driver
*ddrv
, const char *buf
,
5914 err
= ccwgroup_create_dev(qeth_core_root_dev
,
5915 &qeth_core_ccwgroup_driver
, 3, buf
);
5917 return err
? err
: count
;
5919 static DRIVER_ATTR_WO(group
);
5921 static struct attribute
*qeth_drv_attrs
[] = {
5922 &driver_attr_group
.attr
,
5925 static struct attribute_group qeth_drv_attr_group
= {
5926 .attrs
= qeth_drv_attrs
,
5928 static const struct attribute_group
*qeth_drv_attr_groups
[] = {
5929 &qeth_drv_attr_group
,
5933 int qeth_do_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
5935 struct qeth_card
*card
= dev
->ml_priv
;
5936 struct mii_ioctl_data
*mii_data
;
5942 if (!qeth_card_hw_is_reachable(card
))
5945 if (card
->info
.type
== QETH_CARD_TYPE_OSN
)
5949 case SIOC_QETH_ADP_SET_SNMP_CONTROL
:
5950 rc
= qeth_snmp_command(card
, rq
->ifr_ifru
.ifru_data
);
5952 case SIOC_QETH_GET_CARD_TYPE
:
5953 if ((card
->info
.type
== QETH_CARD_TYPE_OSD
||
5954 card
->info
.type
== QETH_CARD_TYPE_OSM
||
5955 card
->info
.type
== QETH_CARD_TYPE_OSX
) &&
5956 !card
->info
.guestlan
)
5961 mii_data
= if_mii(rq
);
5962 mii_data
->phy_id
= 0;
5965 mii_data
= if_mii(rq
);
5966 if (mii_data
->phy_id
!= 0)
5969 mii_data
->val_out
= qeth_mdio_read(dev
,
5970 mii_data
->phy_id
, mii_data
->reg_num
);
5972 case SIOC_QETH_QUERY_OAT
:
5973 rc
= qeth_query_oat_command(card
, rq
->ifr_ifru
.ifru_data
);
5976 if (card
->discipline
->do_ioctl
)
5977 rc
= card
->discipline
->do_ioctl(dev
, rq
, cmd
);
5982 QETH_CARD_TEXT_(card
, 2, "ioce%x", rc
);
5985 EXPORT_SYMBOL_GPL(qeth_do_ioctl
);
5988 const char str
[ETH_GSTRING_LEN
];
5989 } qeth_ethtool_stats_keys
[] = {
5994 {"tx skbs no packing"},
5995 {"tx buffers no packing"},
5996 {"tx skbs packing"},
5997 {"tx buffers packing"},
6000 /* 10 */{"rx sg skbs"},
6002 {"rx sg page allocs"},
6003 {"tx large kbytes"},
6005 {"tx pk state ch n->p"},
6006 {"tx pk state ch p->n"},
6007 {"tx pk watermark low"},
6008 {"tx pk watermark high"},
6009 {"queue 0 buffer usage"},
6010 /* 20 */{"queue 1 buffer usage"},
6011 {"queue 2 buffer usage"},
6012 {"queue 3 buffer usage"},
6015 {"rx do_QDIO time"},
6016 {"rx do_QDIO count"},
6017 {"tx handler time"},
6018 {"tx handler count"},
6020 /* 30 */{"tx count"},
6021 {"tx do_QDIO time"},
6022 {"tx do_QDIO count"},
6026 {"cq handler count"},
6027 {"cq handler time"},
6031 int qeth_core_get_sset_count(struct net_device
*dev
, int stringset
)
6033 switch (stringset
) {
6035 return (sizeof(qeth_ethtool_stats_keys
) / ETH_GSTRING_LEN
);
6040 EXPORT_SYMBOL_GPL(qeth_core_get_sset_count
);
6042 void qeth_core_get_ethtool_stats(struct net_device
*dev
,
6043 struct ethtool_stats
*stats
, u64
*data
)
6045 struct qeth_card
*card
= dev
->ml_priv
;
6046 data
[0] = card
->stats
.rx_packets
-
6047 card
->perf_stats
.initial_rx_packets
;
6048 data
[1] = card
->perf_stats
.bufs_rec
;
6049 data
[2] = card
->stats
.tx_packets
-
6050 card
->perf_stats
.initial_tx_packets
;
6051 data
[3] = card
->perf_stats
.bufs_sent
;
6052 data
[4] = card
->stats
.tx_packets
- card
->perf_stats
.initial_tx_packets
6053 - card
->perf_stats
.skbs_sent_pack
;
6054 data
[5] = card
->perf_stats
.bufs_sent
- card
->perf_stats
.bufs_sent_pack
;
6055 data
[6] = card
->perf_stats
.skbs_sent_pack
;
6056 data
[7] = card
->perf_stats
.bufs_sent_pack
;
6057 data
[8] = card
->perf_stats
.sg_skbs_sent
;
6058 data
[9] = card
->perf_stats
.sg_frags_sent
;
6059 data
[10] = card
->perf_stats
.sg_skbs_rx
;
6060 data
[11] = card
->perf_stats
.sg_frags_rx
;
6061 data
[12] = card
->perf_stats
.sg_alloc_page_rx
;
6062 data
[13] = (card
->perf_stats
.large_send_bytes
>> 10);
6063 data
[14] = card
->perf_stats
.large_send_cnt
;
6064 data
[15] = card
->perf_stats
.sc_dp_p
;
6065 data
[16] = card
->perf_stats
.sc_p_dp
;
6066 data
[17] = QETH_LOW_WATERMARK_PACK
;
6067 data
[18] = QETH_HIGH_WATERMARK_PACK
;
6068 data
[19] = atomic_read(&card
->qdio
.out_qs
[0]->used_buffers
);
6069 data
[20] = (card
->qdio
.no_out_queues
> 1) ?
6070 atomic_read(&card
->qdio
.out_qs
[1]->used_buffers
) : 0;
6071 data
[21] = (card
->qdio
.no_out_queues
> 2) ?
6072 atomic_read(&card
->qdio
.out_qs
[2]->used_buffers
) : 0;
6073 data
[22] = (card
->qdio
.no_out_queues
> 3) ?
6074 atomic_read(&card
->qdio
.out_qs
[3]->used_buffers
) : 0;
6075 data
[23] = card
->perf_stats
.inbound_time
;
6076 data
[24] = card
->perf_stats
.inbound_cnt
;
6077 data
[25] = card
->perf_stats
.inbound_do_qdio_time
;
6078 data
[26] = card
->perf_stats
.inbound_do_qdio_cnt
;
6079 data
[27] = card
->perf_stats
.outbound_handler_time
;
6080 data
[28] = card
->perf_stats
.outbound_handler_cnt
;
6081 data
[29] = card
->perf_stats
.outbound_time
;
6082 data
[30] = card
->perf_stats
.outbound_cnt
;
6083 data
[31] = card
->perf_stats
.outbound_do_qdio_time
;
6084 data
[32] = card
->perf_stats
.outbound_do_qdio_cnt
;
6085 data
[33] = card
->perf_stats
.tx_csum
;
6086 data
[34] = card
->perf_stats
.tx_lin
;
6087 data
[35] = card
->perf_stats
.tx_linfail
;
6088 data
[36] = card
->perf_stats
.cq_cnt
;
6089 data
[37] = card
->perf_stats
.cq_time
;
6090 data
[38] = card
->perf_stats
.rx_csum
;
6092 EXPORT_SYMBOL_GPL(qeth_core_get_ethtool_stats
);
6094 void qeth_core_get_strings(struct net_device
*dev
, u32 stringset
, u8
*data
)
6096 switch (stringset
) {
6098 memcpy(data
, &qeth_ethtool_stats_keys
,
6099 sizeof(qeth_ethtool_stats_keys
));
6106 EXPORT_SYMBOL_GPL(qeth_core_get_strings
);
6108 void qeth_core_get_drvinfo(struct net_device
*dev
,
6109 struct ethtool_drvinfo
*info
)
6111 struct qeth_card
*card
= dev
->ml_priv
;
6113 strlcpy(info
->driver
, card
->options
.layer2
? "qeth_l2" : "qeth_l3",
6114 sizeof(info
->driver
));
6115 strlcpy(info
->version
, "1.0", sizeof(info
->version
));
6116 strlcpy(info
->fw_version
, card
->info
.mcl_level
,
6117 sizeof(info
->fw_version
));
6118 snprintf(info
->bus_info
, sizeof(info
->bus_info
), "%s/%s/%s",
6119 CARD_RDEV_ID(card
), CARD_WDEV_ID(card
), CARD_DDEV_ID(card
));
6121 EXPORT_SYMBOL_GPL(qeth_core_get_drvinfo
);
6123 /* Helper function to fill 'advertising' and 'supported' which are the same. */
6124 /* Autoneg and full-duplex are supported and advertised unconditionally. */
6125 /* Always advertise and support all speeds up to specified, and only one */
6126 /* specified port type. */
6127 static void qeth_set_cmd_adv_sup(struct ethtool_link_ksettings
*cmd
,
6128 int maxspeed
, int porttype
)
6130 ethtool_link_ksettings_zero_link_mode(cmd
, supported
);
6131 ethtool_link_ksettings_zero_link_mode(cmd
, advertising
);
6132 ethtool_link_ksettings_zero_link_mode(cmd
, lp_advertising
);
6134 ethtool_link_ksettings_add_link_mode(cmd
, supported
, Autoneg
);
6135 ethtool_link_ksettings_add_link_mode(cmd
, advertising
, Autoneg
);
6139 ethtool_link_ksettings_add_link_mode(cmd
, supported
, TP
);
6140 ethtool_link_ksettings_add_link_mode(cmd
, advertising
, TP
);
6143 ethtool_link_ksettings_add_link_mode(cmd
, supported
, FIBRE
);
6144 ethtool_link_ksettings_add_link_mode(cmd
, advertising
, FIBRE
);
6147 ethtool_link_ksettings_add_link_mode(cmd
, supported
, TP
);
6148 ethtool_link_ksettings_add_link_mode(cmd
, advertising
, TP
);
6152 /* fallthrough from high to low, to select all legal speeds: */
6155 ethtool_link_ksettings_add_link_mode(cmd
, supported
,
6157 ethtool_link_ksettings_add_link_mode(cmd
, advertising
,
6160 ethtool_link_ksettings_add_link_mode(cmd
, supported
,
6162 ethtool_link_ksettings_add_link_mode(cmd
, advertising
,
6164 ethtool_link_ksettings_add_link_mode(cmd
, supported
,
6166 ethtool_link_ksettings_add_link_mode(cmd
, advertising
,
6169 ethtool_link_ksettings_add_link_mode(cmd
, supported
,
6171 ethtool_link_ksettings_add_link_mode(cmd
, advertising
,
6173 ethtool_link_ksettings_add_link_mode(cmd
, supported
,
6175 ethtool_link_ksettings_add_link_mode(cmd
, advertising
,
6178 ethtool_link_ksettings_add_link_mode(cmd
, supported
,
6180 ethtool_link_ksettings_add_link_mode(cmd
, advertising
,
6182 ethtool_link_ksettings_add_link_mode(cmd
, supported
,
6184 ethtool_link_ksettings_add_link_mode(cmd
, advertising
,
6186 /* end fallthrough */
6189 ethtool_link_ksettings_add_link_mode(cmd
, supported
,
6191 ethtool_link_ksettings_add_link_mode(cmd
, advertising
,
6193 ethtool_link_ksettings_add_link_mode(cmd
, supported
,
6195 ethtool_link_ksettings_add_link_mode(cmd
, advertising
,
6201 int qeth_core_ethtool_get_link_ksettings(struct net_device
*netdev
,
6202 struct ethtool_link_ksettings
*cmd
)
6204 struct qeth_card
*card
= netdev
->ml_priv
;
6205 enum qeth_link_types link_type
;
6206 struct carrier_info carrier_info
;
6209 if ((card
->info
.type
== QETH_CARD_TYPE_IQD
) || (card
->info
.guestlan
))
6210 link_type
= QETH_LINK_TYPE_10GBIT_ETH
;
6212 link_type
= card
->info
.link_type
;
6214 cmd
->base
.duplex
= DUPLEX_FULL
;
6215 cmd
->base
.autoneg
= AUTONEG_ENABLE
;
6216 cmd
->base
.phy_address
= 0;
6217 cmd
->base
.mdio_support
= 0;
6218 cmd
->base
.eth_tp_mdix
= ETH_TP_MDI_INVALID
;
6219 cmd
->base
.eth_tp_mdix_ctrl
= ETH_TP_MDI_INVALID
;
6221 switch (link_type
) {
6222 case QETH_LINK_TYPE_FAST_ETH
:
6223 case QETH_LINK_TYPE_LANE_ETH100
:
6224 cmd
->base
.speed
= SPEED_100
;
6225 cmd
->base
.port
= PORT_TP
;
6227 case QETH_LINK_TYPE_GBIT_ETH
:
6228 case QETH_LINK_TYPE_LANE_ETH1000
:
6229 cmd
->base
.speed
= SPEED_1000
;
6230 cmd
->base
.port
= PORT_FIBRE
;
6232 case QETH_LINK_TYPE_10GBIT_ETH
:
6233 cmd
->base
.speed
= SPEED_10000
;
6234 cmd
->base
.port
= PORT_FIBRE
;
6237 cmd
->base
.speed
= SPEED_10
;
6238 cmd
->base
.port
= PORT_TP
;
6240 qeth_set_cmd_adv_sup(cmd
, cmd
->base
.speed
, cmd
->base
.port
);
6242 /* Check if we can obtain more accurate information. */
6243 /* If QUERY_CARD_INFO command is not supported or fails, */
6244 /* just return the heuristics that was filled above. */
6245 if (!qeth_card_hw_is_reachable(card
))
6247 rc
= qeth_query_card_info(card
, &carrier_info
);
6248 if (rc
== -EOPNOTSUPP
) /* for old hardware, return heuristic */
6250 if (rc
) /* report error from the hardware operation */
6252 /* on success, fill in the information got from the hardware */
6255 "card info: card_type=0x%02x, port_mode=0x%04x, port_speed=0x%08x\n",
6256 carrier_info
.card_type
,
6257 carrier_info
.port_mode
,
6258 carrier_info
.port_speed
);
6260 /* Update attributes for which we've obtained more authoritative */
6261 /* information, leave the rest the way they where filled above. */
6262 switch (carrier_info
.card_type
) {
6263 case CARD_INFO_TYPE_1G_COPPER_A
:
6264 case CARD_INFO_TYPE_1G_COPPER_B
:
6265 cmd
->base
.port
= PORT_TP
;
6266 qeth_set_cmd_adv_sup(cmd
, SPEED_1000
, cmd
->base
.port
);
6268 case CARD_INFO_TYPE_1G_FIBRE_A
:
6269 case CARD_INFO_TYPE_1G_FIBRE_B
:
6270 cmd
->base
.port
= PORT_FIBRE
;
6271 qeth_set_cmd_adv_sup(cmd
, SPEED_1000
, cmd
->base
.port
);
6273 case CARD_INFO_TYPE_10G_FIBRE_A
:
6274 case CARD_INFO_TYPE_10G_FIBRE_B
:
6275 cmd
->base
.port
= PORT_FIBRE
;
6276 qeth_set_cmd_adv_sup(cmd
, SPEED_10000
, cmd
->base
.port
);
6280 switch (carrier_info
.port_mode
) {
6281 case CARD_INFO_PORTM_FULLDUPLEX
:
6282 cmd
->base
.duplex
= DUPLEX_FULL
;
6284 case CARD_INFO_PORTM_HALFDUPLEX
:
6285 cmd
->base
.duplex
= DUPLEX_HALF
;
6289 switch (carrier_info
.port_speed
) {
6290 case CARD_INFO_PORTS_10M
:
6291 cmd
->base
.speed
= SPEED_10
;
6293 case CARD_INFO_PORTS_100M
:
6294 cmd
->base
.speed
= SPEED_100
;
6296 case CARD_INFO_PORTS_1G
:
6297 cmd
->base
.speed
= SPEED_1000
;
6299 case CARD_INFO_PORTS_10G
:
6300 cmd
->base
.speed
= SPEED_10000
;
6306 EXPORT_SYMBOL_GPL(qeth_core_ethtool_get_link_ksettings
);
6308 /* Callback to handle checksum offload command reply from OSA card.
6309 * Verify that required features have been enabled on the card.
6310 * Return error in hdr->return_code as this value is checked by caller.
6312 * Always returns zero to indicate no further messages from the OSA card.
6314 static int qeth_ipa_checksum_run_cmd_cb(struct qeth_card
*card
,
6315 struct qeth_reply
*reply
,
6318 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
6319 struct qeth_checksum_cmd
*chksum_cb
=
6320 (struct qeth_checksum_cmd
*)reply
->param
;
6322 QETH_CARD_TEXT(card
, 4, "chkdoccb");
6323 if (qeth_setassparms_inspect_rc(cmd
))
6326 memset(chksum_cb
, 0, sizeof(*chksum_cb
));
6327 if (cmd
->data
.setassparms
.hdr
.command_code
== IPA_CMD_ASS_START
) {
6328 chksum_cb
->supported
=
6329 cmd
->data
.setassparms
.data
.chksum
.supported
;
6330 QETH_CARD_TEXT_(card
, 3, "strt:%x", chksum_cb
->supported
);
6332 if (cmd
->data
.setassparms
.hdr
.command_code
== IPA_CMD_ASS_ENABLE
) {
6333 chksum_cb
->supported
=
6334 cmd
->data
.setassparms
.data
.chksum
.supported
;
6335 chksum_cb
->enabled
=
6336 cmd
->data
.setassparms
.data
.chksum
.enabled
;
6337 QETH_CARD_TEXT_(card
, 3, "supp:%x", chksum_cb
->supported
);
6338 QETH_CARD_TEXT_(card
, 3, "enab:%x", chksum_cb
->enabled
);
6343 /* Send command to OSA card and check results. */
6344 static int qeth_ipa_checksum_run_cmd(struct qeth_card
*card
,
6345 enum qeth_ipa_funcs ipa_func
,
6346 __u16 cmd_code
, long data
,
6347 struct qeth_checksum_cmd
*chksum_cb
,
6348 enum qeth_prot_versions prot
)
6350 struct qeth_cmd_buffer
*iob
;
6353 QETH_CARD_TEXT(card
, 4, "chkdocmd");
6354 iob
= qeth_get_setassparms_cmd(card
, ipa_func
, cmd_code
,
6355 sizeof(__u32
), prot
);
6357 rc
= qeth_send_setassparms(card
, iob
, sizeof(__u32
), data
,
6358 qeth_ipa_checksum_run_cmd_cb
,
6363 static int qeth_send_checksum_on(struct qeth_card
*card
, int cstype
,
6364 enum qeth_prot_versions prot
)
6366 u32 required_features
= QETH_IPA_CHECKSUM_UDP
| QETH_IPA_CHECKSUM_TCP
;
6367 struct qeth_checksum_cmd chksum_cb
;
6370 if (prot
== QETH_PROT_IPV4
)
6371 required_features
|= QETH_IPA_CHECKSUM_IP_HDR
;
6372 rc
= qeth_ipa_checksum_run_cmd(card
, cstype
, IPA_CMD_ASS_START
, 0,
6375 if ((required_features
& chksum_cb
.supported
) !=
6378 else if (!(QETH_IPA_CHECKSUM_LP2LP
& chksum_cb
.supported
) &&
6379 cstype
== IPA_INBOUND_CHECKSUM
)
6380 dev_warn(&card
->gdev
->dev
,
6381 "Hardware checksumming is performed only if %s and its peer use different OSA Express 3 ports\n",
6382 QETH_CARD_IFNAME(card
));
6385 qeth_send_simple_setassparms_prot(card
, cstype
,
6386 IPA_CMD_ASS_STOP
, 0, prot
);
6387 dev_warn(&card
->gdev
->dev
,
6388 "Starting HW IPv%d checksumming for %s failed, using SW checksumming\n",
6389 prot
, QETH_CARD_IFNAME(card
));
6392 rc
= qeth_ipa_checksum_run_cmd(card
, cstype
, IPA_CMD_ASS_ENABLE
,
6393 chksum_cb
.supported
, &chksum_cb
,
6396 if ((required_features
& chksum_cb
.enabled
) !=
6401 qeth_send_simple_setassparms_prot(card
, cstype
,
6402 IPA_CMD_ASS_STOP
, 0, prot
);
6403 dev_warn(&card
->gdev
->dev
,
6404 "Enabling HW IPv%d checksumming for %s failed, using SW checksumming\n",
6405 prot
, QETH_CARD_IFNAME(card
));
6409 dev_info(&card
->gdev
->dev
, "HW Checksumming (%sbound IPv%d) enabled\n",
6410 cstype
== IPA_INBOUND_CHECKSUM
? "in" : "out", prot
);
6414 static int qeth_set_ipa_csum(struct qeth_card
*card
, bool on
, int cstype
,
6415 enum qeth_prot_versions prot
)
6417 int rc
= (on
) ? qeth_send_checksum_on(card
, cstype
, prot
)
6418 : qeth_send_simple_setassparms_prot(card
, cstype
,
6419 IPA_CMD_ASS_STOP
, 0,
6421 return rc
? -EIO
: 0;
6424 static int qeth_set_ipa_tso(struct qeth_card
*card
, int on
)
6428 QETH_CARD_TEXT(card
, 3, "sttso");
6431 rc
= qeth_send_simple_setassparms(card
, IPA_OUTBOUND_TSO
,
6432 IPA_CMD_ASS_START
, 0);
6434 dev_warn(&card
->gdev
->dev
,
6435 "Starting outbound TCP segmentation offload for %s failed\n",
6436 QETH_CARD_IFNAME(card
));
6439 dev_info(&card
->gdev
->dev
, "Outbound TSO enabled\n");
6441 rc
= qeth_send_simple_setassparms(card
, IPA_OUTBOUND_TSO
,
6442 IPA_CMD_ASS_STOP
, 0);
6447 static int qeth_set_ipa_rx_csum(struct qeth_card
*card
, bool on
)
6449 int rc_ipv4
= (on
) ? -EOPNOTSUPP
: 0;
6452 if (qeth_is_supported(card
, IPA_INBOUND_CHECKSUM
))
6453 rc_ipv4
= qeth_set_ipa_csum(card
, on
, IPA_INBOUND_CHECKSUM
,
6455 if (!qeth_is_supported6(card
, IPA_INBOUND_CHECKSUM_V6
))
6456 /* no/one Offload Assist available, so the rc is trivial */
6459 rc_ipv6
= qeth_set_ipa_csum(card
, on
, IPA_INBOUND_CHECKSUM
,
6463 /* enable: success if any Assist is active */
6464 return (rc_ipv6
) ? rc_ipv4
: 0;
6466 /* disable: failure if any Assist is still active */
6467 return (rc_ipv6
) ? rc_ipv6
: rc_ipv4
;
6470 #define QETH_HW_FEATURES (NETIF_F_RXCSUM | NETIF_F_IP_CSUM | NETIF_F_TSO | \
6473 * qeth_enable_hw_features() - (Re-)Enable HW functions for device features
6474 * @dev: a net_device
6476 void qeth_enable_hw_features(struct net_device
*dev
)
6478 struct qeth_card
*card
= dev
->ml_priv
;
6479 netdev_features_t features
;
6482 features
= dev
->features
;
6483 /* force-off any feature that needs an IPA sequence.
6484 * netdev_update_features() will restart them.
6486 dev
->features
&= ~QETH_HW_FEATURES
;
6487 netdev_update_features(dev
);
6488 if (features
!= dev
->features
)
6489 dev_warn(&card
->gdev
->dev
,
6490 "Device recovery failed to restore all offload features\n");
6493 EXPORT_SYMBOL_GPL(qeth_enable_hw_features
);
6495 int qeth_set_features(struct net_device
*dev
, netdev_features_t features
)
6497 struct qeth_card
*card
= dev
->ml_priv
;
6498 netdev_features_t changed
= dev
->features
^ features
;
6501 QETH_DBF_TEXT(SETUP
, 2, "setfeat");
6502 QETH_DBF_HEX(SETUP
, 2, &features
, sizeof(features
));
6504 if ((changed
& NETIF_F_IP_CSUM
)) {
6505 rc
= qeth_set_ipa_csum(card
, features
& NETIF_F_IP_CSUM
,
6506 IPA_OUTBOUND_CHECKSUM
, QETH_PROT_IPV4
);
6508 changed
^= NETIF_F_IP_CSUM
;
6510 if (changed
& NETIF_F_IPV6_CSUM
) {
6511 rc
= qeth_set_ipa_csum(card
, features
& NETIF_F_IPV6_CSUM
,
6512 IPA_OUTBOUND_CHECKSUM
, QETH_PROT_IPV6
);
6514 changed
^= NETIF_F_IPV6_CSUM
;
6516 if (changed
& NETIF_F_RXCSUM
) {
6517 rc
= qeth_set_ipa_rx_csum(card
, features
& NETIF_F_RXCSUM
);
6519 changed
^= NETIF_F_RXCSUM
;
6521 if ((changed
& NETIF_F_TSO
)) {
6522 rc
= qeth_set_ipa_tso(card
, features
& NETIF_F_TSO
? 1 : 0);
6524 changed
^= NETIF_F_TSO
;
6527 /* everything changed successfully? */
6528 if ((dev
->features
^ features
) == changed
)
6530 /* something went wrong. save changed features and return error */
6531 dev
->features
^= changed
;
6534 EXPORT_SYMBOL_GPL(qeth_set_features
);
6536 netdev_features_t
qeth_fix_features(struct net_device
*dev
,
6537 netdev_features_t features
)
6539 struct qeth_card
*card
= dev
->ml_priv
;
6541 QETH_DBF_TEXT(SETUP
, 2, "fixfeat");
6542 if (!qeth_is_supported(card
, IPA_OUTBOUND_CHECKSUM
))
6543 features
&= ~NETIF_F_IP_CSUM
;
6544 if (!qeth_is_supported6(card
, IPA_OUTBOUND_CHECKSUM_V6
))
6545 features
&= ~NETIF_F_IPV6_CSUM
;
6546 if (!qeth_is_supported(card
, IPA_INBOUND_CHECKSUM
) &&
6547 !qeth_is_supported6(card
, IPA_INBOUND_CHECKSUM_V6
))
6548 features
&= ~NETIF_F_RXCSUM
;
6549 if (!qeth_is_supported(card
, IPA_OUTBOUND_TSO
))
6550 features
&= ~NETIF_F_TSO
;
6551 /* if the card isn't up, remove features that require hw changes */
6552 if (card
->state
== CARD_STATE_DOWN
||
6553 card
->state
== CARD_STATE_RECOVER
)
6554 features
&= ~QETH_HW_FEATURES
;
6555 QETH_DBF_HEX(SETUP
, 2, &features
, sizeof(features
));
6558 EXPORT_SYMBOL_GPL(qeth_fix_features
);
6560 netdev_features_t
qeth_features_check(struct sk_buff
*skb
,
6561 struct net_device
*dev
,
6562 netdev_features_t features
)
6564 /* GSO segmentation builds skbs with
6565 * a (small) linear part for the headers, and
6566 * page frags for the data.
6567 * Compared to a linear skb, the header-only part consumes an
6568 * additional buffer element. This reduces buffer utilization, and
6569 * hurts throughput. So compress small segments into one element.
6571 if (netif_needs_gso(skb
, features
)) {
6572 /* match skb_segment(): */
6573 unsigned int doffset
= skb
->data
- skb_mac_header(skb
);
6574 unsigned int hsize
= skb_shinfo(skb
)->gso_size
;
6575 unsigned int hroom
= skb_headroom(skb
);
6577 /* linearize only if resulting skb allocations are order-0: */
6578 if (SKB_DATA_ALIGN(hroom
+ doffset
+ hsize
) <= SKB_MAX_HEAD(0))
6579 features
&= ~NETIF_F_SG
;
6582 return vlan_features_check(skb
, features
);
6584 EXPORT_SYMBOL_GPL(qeth_features_check
);
6586 static int __init
qeth_core_init(void)
6590 pr_info("loading core functions\n");
6591 INIT_LIST_HEAD(&qeth_core_card_list
.list
);
6592 INIT_LIST_HEAD(&qeth_dbf_list
);
6593 rwlock_init(&qeth_core_card_list
.rwlock
);
6594 mutex_init(&qeth_mod_mutex
);
6596 qeth_wq
= create_singlethread_workqueue("qeth_wq");
6602 rc
= qeth_register_dbf_views();
6605 qeth_core_root_dev
= root_device_register("qeth");
6606 rc
= PTR_ERR_OR_ZERO(qeth_core_root_dev
);
6609 qeth_core_header_cache
= kmem_cache_create("qeth_hdr",
6610 sizeof(struct qeth_hdr
) + ETH_HLEN
, 64, 0, NULL
);
6611 if (!qeth_core_header_cache
) {
6615 qeth_qdio_outbuf_cache
= kmem_cache_create("qeth_buf",
6616 sizeof(struct qeth_qdio_out_buffer
), 0, 0, NULL
);
6617 if (!qeth_qdio_outbuf_cache
) {
6621 rc
= ccw_driver_register(&qeth_ccw_driver
);
6624 qeth_core_ccwgroup_driver
.driver
.groups
= qeth_drv_attr_groups
;
6625 rc
= ccwgroup_driver_register(&qeth_core_ccwgroup_driver
);
6632 ccw_driver_unregister(&qeth_ccw_driver
);
6634 kmem_cache_destroy(qeth_qdio_outbuf_cache
);
6636 kmem_cache_destroy(qeth_core_header_cache
);
6638 root_device_unregister(qeth_core_root_dev
);
6640 qeth_unregister_dbf_views();
6642 destroy_workqueue(qeth_wq
);
6644 pr_err("Initializing the qeth device driver failed\n");
6648 static void __exit
qeth_core_exit(void)
6650 qeth_clear_dbf_list();
6651 destroy_workqueue(qeth_wq
);
6652 ccwgroup_driver_unregister(&qeth_core_ccwgroup_driver
);
6653 ccw_driver_unregister(&qeth_ccw_driver
);
6654 kmem_cache_destroy(qeth_qdio_outbuf_cache
);
6655 kmem_cache_destroy(qeth_core_header_cache
);
6656 root_device_unregister(qeth_core_root_dev
);
6657 qeth_unregister_dbf_views();
6658 pr_info("core functions removed\n");
6661 module_init(qeth_core_init
);
6662 module_exit(qeth_core_exit
);
6663 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
6664 MODULE_DESCRIPTION("qeth core functions");
6665 MODULE_LICENSE("GPL");