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/module.h>
14 #include <linux/moduleparam.h>
15 #include <linux/string.h>
16 #include <linux/errno.h>
17 #include <linux/kernel.h>
19 #include <linux/tcp.h>
20 #include <linux/mii.h>
21 #include <linux/kthread.h>
22 #include <linux/slab.h>
23 #include <linux/if_vlan.h>
24 #include <linux/netdevice.h>
25 #include <linux/netdev_features.h>
26 #include <linux/skbuff.h>
28 #include <net/iucv/af_iucv.h>
29 #include <net/dsfield.h>
31 #include <asm/ebcdic.h>
32 #include <asm/chpid.h>
34 #include <asm/sysinfo.h>
35 #include <asm/compat.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 void qeth_clear_output_buffer(struct qeth_qdio_out_q
*queue
,
77 struct qeth_qdio_out_buffer
*buf
,
78 enum qeth_qdio_buffer_states newbufstate
);
79 static int qeth_init_qdio_out_buf(struct qeth_qdio_out_q
*, int);
81 struct workqueue_struct
*qeth_wq
;
82 EXPORT_SYMBOL_GPL(qeth_wq
);
84 int qeth_card_hw_is_reachable(struct qeth_card
*card
)
86 return (card
->state
== CARD_STATE_SOFTSETUP
) ||
87 (card
->state
== CARD_STATE_UP
);
89 EXPORT_SYMBOL_GPL(qeth_card_hw_is_reachable
);
91 static void qeth_close_dev_handler(struct work_struct
*work
)
93 struct qeth_card
*card
;
95 card
= container_of(work
, struct qeth_card
, close_dev_work
);
96 QETH_CARD_TEXT(card
, 2, "cldevhdl");
100 ccwgroup_set_offline(card
->gdev
);
103 void qeth_close_dev(struct qeth_card
*card
)
105 QETH_CARD_TEXT(card
, 2, "cldevsubm");
106 queue_work(qeth_wq
, &card
->close_dev_work
);
108 EXPORT_SYMBOL_GPL(qeth_close_dev
);
110 static const char *qeth_get_cardname(struct qeth_card
*card
)
112 if (card
->info
.guestlan
) {
113 switch (card
->info
.type
) {
114 case QETH_CARD_TYPE_OSD
:
115 return " Virtual NIC QDIO";
116 case QETH_CARD_TYPE_IQD
:
117 return " Virtual NIC Hiper";
118 case QETH_CARD_TYPE_OSM
:
119 return " Virtual NIC QDIO - OSM";
120 case QETH_CARD_TYPE_OSX
:
121 return " Virtual NIC QDIO - OSX";
126 switch (card
->info
.type
) {
127 case QETH_CARD_TYPE_OSD
:
128 return " OSD Express";
129 case QETH_CARD_TYPE_IQD
:
130 return " HiperSockets";
131 case QETH_CARD_TYPE_OSN
:
133 case QETH_CARD_TYPE_OSM
:
135 case QETH_CARD_TYPE_OSX
:
144 /* max length to be returned: 14 */
145 const char *qeth_get_cardname_short(struct qeth_card
*card
)
147 if (card
->info
.guestlan
) {
148 switch (card
->info
.type
) {
149 case QETH_CARD_TYPE_OSD
:
150 return "Virt.NIC QDIO";
151 case QETH_CARD_TYPE_IQD
:
152 return "Virt.NIC Hiper";
153 case QETH_CARD_TYPE_OSM
:
154 return "Virt.NIC OSM";
155 case QETH_CARD_TYPE_OSX
:
156 return "Virt.NIC OSX";
161 switch (card
->info
.type
) {
162 case QETH_CARD_TYPE_OSD
:
163 switch (card
->info
.link_type
) {
164 case QETH_LINK_TYPE_FAST_ETH
:
166 case QETH_LINK_TYPE_HSTR
:
168 case QETH_LINK_TYPE_GBIT_ETH
:
170 case QETH_LINK_TYPE_10GBIT_ETH
:
172 case QETH_LINK_TYPE_LANE_ETH100
:
173 return "OSD_FE_LANE";
174 case QETH_LINK_TYPE_LANE_TR
:
175 return "OSD_TR_LANE";
176 case QETH_LINK_TYPE_LANE_ETH1000
:
177 return "OSD_GbE_LANE";
178 case QETH_LINK_TYPE_LANE
:
179 return "OSD_ATM_LANE";
181 return "OSD_Express";
183 case QETH_CARD_TYPE_IQD
:
184 return "HiperSockets";
185 case QETH_CARD_TYPE_OSN
:
187 case QETH_CARD_TYPE_OSM
:
189 case QETH_CARD_TYPE_OSX
:
198 void qeth_set_recovery_task(struct qeth_card
*card
)
200 card
->recovery_task
= current
;
202 EXPORT_SYMBOL_GPL(qeth_set_recovery_task
);
204 void qeth_clear_recovery_task(struct qeth_card
*card
)
206 card
->recovery_task
= NULL
;
208 EXPORT_SYMBOL_GPL(qeth_clear_recovery_task
);
210 static bool qeth_is_recovery_task(const struct qeth_card
*card
)
212 return card
->recovery_task
== current
;
215 void qeth_set_allowed_threads(struct qeth_card
*card
, unsigned long threads
,
216 int clear_start_mask
)
220 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
221 card
->thread_allowed_mask
= threads
;
222 if (clear_start_mask
)
223 card
->thread_start_mask
&= threads
;
224 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
225 wake_up(&card
->wait_q
);
227 EXPORT_SYMBOL_GPL(qeth_set_allowed_threads
);
229 int qeth_threads_running(struct qeth_card
*card
, unsigned long threads
)
234 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
235 rc
= (card
->thread_running_mask
& threads
);
236 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
239 EXPORT_SYMBOL_GPL(qeth_threads_running
);
241 int qeth_wait_for_threads(struct qeth_card
*card
, unsigned long threads
)
243 if (qeth_is_recovery_task(card
))
245 return wait_event_interruptible(card
->wait_q
,
246 qeth_threads_running(card
, threads
) == 0);
248 EXPORT_SYMBOL_GPL(qeth_wait_for_threads
);
250 void qeth_clear_working_pool_list(struct qeth_card
*card
)
252 struct qeth_buffer_pool_entry
*pool_entry
, *tmp
;
254 QETH_CARD_TEXT(card
, 5, "clwrklst");
255 list_for_each_entry_safe(pool_entry
, tmp
,
256 &card
->qdio
.in_buf_pool
.entry_list
, list
){
257 list_del(&pool_entry
->list
);
260 EXPORT_SYMBOL_GPL(qeth_clear_working_pool_list
);
262 static int qeth_alloc_buffer_pool(struct qeth_card
*card
)
264 struct qeth_buffer_pool_entry
*pool_entry
;
268 QETH_CARD_TEXT(card
, 5, "alocpool");
269 for (i
= 0; i
< card
->qdio
.init_pool
.buf_count
; ++i
) {
270 pool_entry
= kzalloc(sizeof(*pool_entry
), GFP_KERNEL
);
272 qeth_free_buffer_pool(card
);
275 for (j
= 0; j
< QETH_MAX_BUFFER_ELEMENTS(card
); ++j
) {
276 ptr
= (void *) __get_free_page(GFP_KERNEL
);
279 free_page((unsigned long)
280 pool_entry
->elements
[--j
]);
282 qeth_free_buffer_pool(card
);
285 pool_entry
->elements
[j
] = ptr
;
287 list_add(&pool_entry
->init_list
,
288 &card
->qdio
.init_pool
.entry_list
);
293 int qeth_realloc_buffer_pool(struct qeth_card
*card
, int bufcnt
)
295 QETH_CARD_TEXT(card
, 2, "realcbp");
297 if ((card
->state
!= CARD_STATE_DOWN
) &&
298 (card
->state
!= CARD_STATE_RECOVER
))
301 /* TODO: steel/add buffers from/to a running card's buffer pool (?) */
302 qeth_clear_working_pool_list(card
);
303 qeth_free_buffer_pool(card
);
304 card
->qdio
.in_buf_pool
.buf_count
= bufcnt
;
305 card
->qdio
.init_pool
.buf_count
= bufcnt
;
306 return qeth_alloc_buffer_pool(card
);
308 EXPORT_SYMBOL_GPL(qeth_realloc_buffer_pool
);
310 static void qeth_free_qdio_queue(struct qeth_qdio_q
*q
)
315 qdio_free_buffers(q
->qdio_bufs
, QDIO_MAX_BUFFERS_PER_Q
);
319 static struct qeth_qdio_q
*qeth_alloc_qdio_queue(void)
321 struct qeth_qdio_q
*q
= kzalloc(sizeof(*q
), GFP_KERNEL
);
327 if (qdio_alloc_buffers(q
->qdio_bufs
, QDIO_MAX_BUFFERS_PER_Q
)) {
332 for (i
= 0; i
< QDIO_MAX_BUFFERS_PER_Q
; ++i
)
333 q
->bufs
[i
].buffer
= q
->qdio_bufs
[i
];
335 QETH_DBF_HEX(SETUP
, 2, &q
, sizeof(void *));
339 static int qeth_cq_init(struct qeth_card
*card
)
343 if (card
->options
.cq
== QETH_CQ_ENABLED
) {
344 QETH_DBF_TEXT(SETUP
, 2, "cqinit");
345 qdio_reset_buffers(card
->qdio
.c_q
->qdio_bufs
,
346 QDIO_MAX_BUFFERS_PER_Q
);
347 card
->qdio
.c_q
->next_buf_to_init
= 127;
348 rc
= do_QDIO(CARD_DDEV(card
), QDIO_FLAG_SYNC_INPUT
,
349 card
->qdio
.no_in_queues
- 1, 0,
352 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
361 static int qeth_alloc_cq(struct qeth_card
*card
)
365 if (card
->options
.cq
== QETH_CQ_ENABLED
) {
367 struct qdio_outbuf_state
*outbuf_states
;
369 QETH_DBF_TEXT(SETUP
, 2, "cqon");
370 card
->qdio
.c_q
= qeth_alloc_qdio_queue();
371 if (!card
->qdio
.c_q
) {
375 card
->qdio
.no_in_queues
= 2;
376 card
->qdio
.out_bufstates
=
377 kzalloc(card
->qdio
.no_out_queues
*
378 QDIO_MAX_BUFFERS_PER_Q
*
379 sizeof(struct qdio_outbuf_state
), GFP_KERNEL
);
380 outbuf_states
= card
->qdio
.out_bufstates
;
381 if (outbuf_states
== NULL
) {
385 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
386 card
->qdio
.out_qs
[i
]->bufstates
= outbuf_states
;
387 outbuf_states
+= QDIO_MAX_BUFFERS_PER_Q
;
390 QETH_DBF_TEXT(SETUP
, 2, "nocq");
391 card
->qdio
.c_q
= NULL
;
392 card
->qdio
.no_in_queues
= 1;
394 QETH_DBF_TEXT_(SETUP
, 2, "iqc%d", card
->qdio
.no_in_queues
);
399 qeth_free_qdio_queue(card
->qdio
.c_q
);
400 card
->qdio
.c_q
= NULL
;
402 dev_err(&card
->gdev
->dev
, "Failed to create completion queue\n");
406 static void qeth_free_cq(struct qeth_card
*card
)
408 if (card
->qdio
.c_q
) {
409 --card
->qdio
.no_in_queues
;
410 qeth_free_qdio_queue(card
->qdio
.c_q
);
411 card
->qdio
.c_q
= NULL
;
413 kfree(card
->qdio
.out_bufstates
);
414 card
->qdio
.out_bufstates
= NULL
;
417 static enum iucv_tx_notify
qeth_compute_cq_notification(int sbalf15
,
420 enum iucv_tx_notify n
;
424 n
= delayed
? TX_NOTIFY_DELAYED_OK
: TX_NOTIFY_OK
;
430 n
= delayed
? TX_NOTIFY_DELAYED_UNREACHABLE
:
431 TX_NOTIFY_UNREACHABLE
;
434 n
= delayed
? TX_NOTIFY_DELAYED_GENERALERROR
:
435 TX_NOTIFY_GENERALERROR
;
442 static void qeth_cleanup_handled_pending(struct qeth_qdio_out_q
*q
, int bidx
,
445 if (q
->card
->options
.cq
!= QETH_CQ_ENABLED
)
448 if (q
->bufs
[bidx
]->next_pending
!= NULL
) {
449 struct qeth_qdio_out_buffer
*head
= q
->bufs
[bidx
];
450 struct qeth_qdio_out_buffer
*c
= q
->bufs
[bidx
]->next_pending
;
453 if (forced_cleanup
||
454 atomic_read(&c
->state
) ==
455 QETH_QDIO_BUF_HANDLED_DELAYED
) {
456 struct qeth_qdio_out_buffer
*f
= c
;
457 QETH_CARD_TEXT(f
->q
->card
, 5, "fp");
458 QETH_CARD_TEXT_(f
->q
->card
, 5, "%lx", (long) f
);
459 /* release here to avoid interleaving between
460 outbound tasklet and inbound tasklet
461 regarding notifications and lifecycle */
462 qeth_release_skbs(c
);
465 WARN_ON_ONCE(head
->next_pending
!= f
);
466 head
->next_pending
= c
;
467 kmem_cache_free(qeth_qdio_outbuf_cache
, f
);
475 if (forced_cleanup
&& (atomic_read(&(q
->bufs
[bidx
]->state
)) ==
476 QETH_QDIO_BUF_HANDLED_DELAYED
)) {
477 /* for recovery situations */
478 q
->bufs
[bidx
]->aob
= q
->bufstates
[bidx
].aob
;
479 qeth_init_qdio_out_buf(q
, bidx
);
480 QETH_CARD_TEXT(q
->card
, 2, "clprecov");
485 static void qeth_qdio_handle_aob(struct qeth_card
*card
,
486 unsigned long phys_aob_addr
)
489 struct qeth_qdio_out_buffer
*buffer
;
490 enum iucv_tx_notify notification
;
492 aob
= (struct qaob
*) phys_to_virt(phys_aob_addr
);
493 QETH_CARD_TEXT(card
, 5, "haob");
494 QETH_CARD_TEXT_(card
, 5, "%lx", phys_aob_addr
);
495 buffer
= (struct qeth_qdio_out_buffer
*) aob
->user1
;
496 QETH_CARD_TEXT_(card
, 5, "%lx", aob
->user1
);
498 if (atomic_cmpxchg(&buffer
->state
, QETH_QDIO_BUF_PRIMED
,
499 QETH_QDIO_BUF_IN_CQ
) == QETH_QDIO_BUF_PRIMED
) {
500 notification
= TX_NOTIFY_OK
;
502 WARN_ON_ONCE(atomic_read(&buffer
->state
) !=
503 QETH_QDIO_BUF_PENDING
);
504 atomic_set(&buffer
->state
, QETH_QDIO_BUF_IN_CQ
);
505 notification
= TX_NOTIFY_DELAYED_OK
;
508 if (aob
->aorc
!= 0) {
509 QETH_CARD_TEXT_(card
, 2, "aorc%02X", aob
->aorc
);
510 notification
= qeth_compute_cq_notification(aob
->aorc
, 1);
512 qeth_notify_skbs(buffer
->q
, buffer
, notification
);
515 qeth_clear_output_buffer(buffer
->q
, buffer
,
516 QETH_QDIO_BUF_HANDLED_DELAYED
);
518 /* from here on: do not touch buffer anymore */
519 qdio_release_aob(aob
);
522 static inline int qeth_is_cq(struct qeth_card
*card
, unsigned int queue
)
524 return card
->options
.cq
== QETH_CQ_ENABLED
&&
525 card
->qdio
.c_q
!= NULL
&&
527 queue
== card
->qdio
.no_in_queues
- 1;
531 static int qeth_issue_next_read(struct qeth_card
*card
)
534 struct qeth_cmd_buffer
*iob
;
536 QETH_CARD_TEXT(card
, 5, "issnxrd");
537 if (card
->read
.state
!= CH_STATE_UP
)
539 iob
= qeth_get_buffer(&card
->read
);
541 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
542 "failed to recover an error on the device\n");
543 QETH_DBF_MESSAGE(2, "%s issue_next_read failed: no iob "
544 "available\n", dev_name(&card
->gdev
->dev
));
547 qeth_setup_ccw(&card
->read
, iob
->data
, QETH_BUFSIZE
);
548 QETH_CARD_TEXT(card
, 6, "noirqpnd");
549 rc
= ccw_device_start(card
->read
.ccwdev
, &card
->read
.ccw
,
552 QETH_DBF_MESSAGE(2, "%s error in starting next read ccw! "
553 "rc=%i\n", dev_name(&card
->gdev
->dev
), rc
);
554 atomic_set(&card
->read
.irq_pending
, 0);
555 card
->read_or_write_problem
= 1;
556 qeth_schedule_recovery(card
);
557 wake_up(&card
->wait_q
);
562 static struct qeth_reply
*qeth_alloc_reply(struct qeth_card
*card
)
564 struct qeth_reply
*reply
;
566 reply
= kzalloc(sizeof(struct qeth_reply
), GFP_ATOMIC
);
568 refcount_set(&reply
->refcnt
, 1);
569 atomic_set(&reply
->received
, 0);
575 static void qeth_get_reply(struct qeth_reply
*reply
)
577 refcount_inc(&reply
->refcnt
);
580 static void qeth_put_reply(struct qeth_reply
*reply
)
582 if (refcount_dec_and_test(&reply
->refcnt
))
586 static void qeth_issue_ipa_msg(struct qeth_ipa_cmd
*cmd
, int rc
,
587 struct qeth_card
*card
)
590 int com
= cmd
->hdr
.command
;
591 ipa_name
= qeth_get_ipa_cmd_name(com
);
593 QETH_DBF_MESSAGE(2, "IPA: %s(x%X) for %s/%s returned "
595 ipa_name
, com
, dev_name(&card
->gdev
->dev
),
596 QETH_CARD_IFNAME(card
), rc
,
597 qeth_get_ipa_msg(rc
));
599 QETH_DBF_MESSAGE(5, "IPA: %s(x%X) for %s/%s succeeded\n",
600 ipa_name
, com
, dev_name(&card
->gdev
->dev
),
601 QETH_CARD_IFNAME(card
));
604 static struct qeth_ipa_cmd
*qeth_check_ipa_data(struct qeth_card
*card
,
605 struct qeth_cmd_buffer
*iob
)
607 struct qeth_ipa_cmd
*cmd
= NULL
;
609 QETH_CARD_TEXT(card
, 5, "chkipad");
610 if (IS_IPA(iob
->data
)) {
611 cmd
= (struct qeth_ipa_cmd
*) PDU_ENCAPSULATION(iob
->data
);
612 if (IS_IPA_REPLY(cmd
)) {
613 if (cmd
->hdr
.command
!= IPA_CMD_SETCCID
&&
614 cmd
->hdr
.command
!= IPA_CMD_DELCCID
&&
615 cmd
->hdr
.command
!= IPA_CMD_MODCCID
&&
616 cmd
->hdr
.command
!= IPA_CMD_SET_DIAG_ASS
)
617 qeth_issue_ipa_msg(cmd
,
618 cmd
->hdr
.return_code
, card
);
621 switch (cmd
->hdr
.command
) {
622 case IPA_CMD_STOPLAN
:
623 if (cmd
->hdr
.return_code
==
624 IPA_RC_VEPA_TO_VEB_TRANSITION
) {
625 dev_err(&card
->gdev
->dev
,
626 "Interface %s is down because the "
627 "adjacent port is no longer in "
628 "reflective relay mode\n",
629 QETH_CARD_IFNAME(card
));
630 qeth_close_dev(card
);
632 dev_warn(&card
->gdev
->dev
,
633 "The link for interface %s on CHPID"
635 QETH_CARD_IFNAME(card
),
637 qeth_issue_ipa_msg(cmd
,
638 cmd
->hdr
.return_code
, card
);
640 card
->lan_online
= 0;
641 if (card
->dev
&& netif_carrier_ok(card
->dev
))
642 netif_carrier_off(card
->dev
);
644 case IPA_CMD_STARTLAN
:
645 dev_info(&card
->gdev
->dev
,
646 "The link for %s on CHPID 0x%X has"
648 QETH_CARD_IFNAME(card
),
650 netif_carrier_on(card
->dev
);
651 card
->lan_online
= 1;
652 if (card
->info
.hwtrap
)
653 card
->info
.hwtrap
= 2;
654 qeth_schedule_recovery(card
);
656 case IPA_CMD_SETBRIDGEPORT_IQD
:
657 case IPA_CMD_SETBRIDGEPORT_OSA
:
658 case IPA_CMD_ADDRESS_CHANGE_NOTIF
:
659 if (card
->discipline
->control_event_handler
664 case IPA_CMD_MODCCID
:
666 case IPA_CMD_REGISTER_LOCAL_ADDR
:
667 QETH_CARD_TEXT(card
, 3, "irla");
669 case IPA_CMD_UNREGISTER_LOCAL_ADDR
:
670 QETH_CARD_TEXT(card
, 3, "urla");
673 QETH_DBF_MESSAGE(2, "Received data is IPA "
674 "but not a reply!\n");
682 void qeth_clear_ipacmd_list(struct qeth_card
*card
)
684 struct qeth_reply
*reply
, *r
;
687 QETH_CARD_TEXT(card
, 4, "clipalst");
689 spin_lock_irqsave(&card
->lock
, flags
);
690 list_for_each_entry_safe(reply
, r
, &card
->cmd_waiter_list
, list
) {
691 qeth_get_reply(reply
);
693 atomic_inc(&reply
->received
);
694 list_del_init(&reply
->list
);
695 wake_up(&reply
->wait_q
);
696 qeth_put_reply(reply
);
698 spin_unlock_irqrestore(&card
->lock
, flags
);
699 atomic_set(&card
->write
.irq_pending
, 0);
701 EXPORT_SYMBOL_GPL(qeth_clear_ipacmd_list
);
703 static int qeth_check_idx_response(struct qeth_card
*card
,
704 unsigned char *buffer
)
709 QETH_DBF_HEX(CTRL
, 2, buffer
, QETH_DBF_CTRL_LEN
);
710 if ((buffer
[2] & 0xc0) == 0xc0) {
711 QETH_DBF_MESSAGE(2, "received an IDX TERMINATE "
712 "with cause code 0x%02x%s\n",
714 ((buffer
[4] == 0x22) ?
715 " -- try another portname" : ""));
716 QETH_CARD_TEXT(card
, 2, "ckidxres");
717 QETH_CARD_TEXT(card
, 2, " idxterm");
718 QETH_CARD_TEXT_(card
, 2, " rc%d", -EIO
);
719 if (buffer
[4] == 0xf6) {
720 dev_err(&card
->gdev
->dev
,
721 "The qeth device is not configured "
722 "for the OSI layer required by z/VM\n");
730 static struct qeth_card
*CARD_FROM_CDEV(struct ccw_device
*cdev
)
732 struct qeth_card
*card
= dev_get_drvdata(&((struct ccwgroup_device
*)
733 dev_get_drvdata(&cdev
->dev
))->dev
);
737 static void qeth_setup_ccw(struct qeth_channel
*channel
, unsigned char *iob
,
740 struct qeth_card
*card
;
742 card
= CARD_FROM_CDEV(channel
->ccwdev
);
743 QETH_CARD_TEXT(card
, 4, "setupccw");
744 if (channel
== &card
->read
)
745 memcpy(&channel
->ccw
, READ_CCW
, sizeof(struct ccw1
));
747 memcpy(&channel
->ccw
, WRITE_CCW
, sizeof(struct ccw1
));
748 channel
->ccw
.count
= len
;
749 channel
->ccw
.cda
= (__u32
) __pa(iob
);
752 static struct qeth_cmd_buffer
*__qeth_get_buffer(struct qeth_channel
*channel
)
756 QETH_CARD_TEXT(CARD_FROM_CDEV(channel
->ccwdev
), 6, "getbuff");
757 index
= channel
->io_buf_no
;
759 if (channel
->iob
[index
].state
== BUF_STATE_FREE
) {
760 channel
->iob
[index
].state
= BUF_STATE_LOCKED
;
761 channel
->io_buf_no
= (channel
->io_buf_no
+ 1) %
763 memset(channel
->iob
[index
].data
, 0, QETH_BUFSIZE
);
764 return channel
->iob
+ index
;
766 index
= (index
+ 1) % QETH_CMD_BUFFER_NO
;
767 } while (index
!= channel
->io_buf_no
);
772 void qeth_release_buffer(struct qeth_channel
*channel
,
773 struct qeth_cmd_buffer
*iob
)
777 QETH_CARD_TEXT(CARD_FROM_CDEV(channel
->ccwdev
), 6, "relbuff");
778 spin_lock_irqsave(&channel
->iob_lock
, flags
);
779 memset(iob
->data
, 0, QETH_BUFSIZE
);
780 iob
->state
= BUF_STATE_FREE
;
781 iob
->callback
= qeth_send_control_data_cb
;
783 spin_unlock_irqrestore(&channel
->iob_lock
, flags
);
784 wake_up(&channel
->wait_q
);
786 EXPORT_SYMBOL_GPL(qeth_release_buffer
);
788 static struct qeth_cmd_buffer
*qeth_get_buffer(struct qeth_channel
*channel
)
790 struct qeth_cmd_buffer
*buffer
= NULL
;
793 spin_lock_irqsave(&channel
->iob_lock
, flags
);
794 buffer
= __qeth_get_buffer(channel
);
795 spin_unlock_irqrestore(&channel
->iob_lock
, flags
);
799 struct qeth_cmd_buffer
*qeth_wait_for_buffer(struct qeth_channel
*channel
)
801 struct qeth_cmd_buffer
*buffer
;
802 wait_event(channel
->wait_q
,
803 ((buffer
= qeth_get_buffer(channel
)) != NULL
));
806 EXPORT_SYMBOL_GPL(qeth_wait_for_buffer
);
808 void qeth_clear_cmd_buffers(struct qeth_channel
*channel
)
812 for (cnt
= 0; cnt
< QETH_CMD_BUFFER_NO
; cnt
++)
813 qeth_release_buffer(channel
, &channel
->iob
[cnt
]);
815 channel
->io_buf_no
= 0;
817 EXPORT_SYMBOL_GPL(qeth_clear_cmd_buffers
);
819 static void qeth_send_control_data_cb(struct qeth_channel
*channel
,
820 struct qeth_cmd_buffer
*iob
)
822 struct qeth_card
*card
;
823 struct qeth_reply
*reply
, *r
;
824 struct qeth_ipa_cmd
*cmd
;
829 card
= CARD_FROM_CDEV(channel
->ccwdev
);
830 QETH_CARD_TEXT(card
, 4, "sndctlcb");
831 rc
= qeth_check_idx_response(card
, iob
->data
);
836 qeth_clear_ipacmd_list(card
);
837 qeth_schedule_recovery(card
);
843 cmd
= qeth_check_ipa_data(card
, iob
);
844 if ((cmd
== NULL
) && (card
->state
!= CARD_STATE_DOWN
))
846 /*in case of OSN : check if cmd is set */
847 if (card
->info
.type
== QETH_CARD_TYPE_OSN
&&
849 cmd
->hdr
.command
!= IPA_CMD_STARTLAN
&&
850 card
->osn_info
.assist_cb
!= NULL
) {
851 card
->osn_info
.assist_cb(card
->dev
, cmd
);
855 spin_lock_irqsave(&card
->lock
, flags
);
856 list_for_each_entry_safe(reply
, r
, &card
->cmd_waiter_list
, list
) {
857 if ((reply
->seqno
== QETH_IDX_COMMAND_SEQNO
) ||
858 ((cmd
) && (reply
->seqno
== cmd
->hdr
.seqno
))) {
859 qeth_get_reply(reply
);
860 list_del_init(&reply
->list
);
861 spin_unlock_irqrestore(&card
->lock
, flags
);
863 if (reply
->callback
!= NULL
) {
865 reply
->offset
= (__u16
)((char *)cmd
-
867 keep_reply
= reply
->callback(card
,
871 keep_reply
= reply
->callback(card
,
876 reply
->rc
= (u16
) cmd
->hdr
.return_code
;
880 spin_lock_irqsave(&card
->lock
, flags
);
881 list_add_tail(&reply
->list
,
882 &card
->cmd_waiter_list
);
883 spin_unlock_irqrestore(&card
->lock
, flags
);
885 atomic_inc(&reply
->received
);
886 wake_up(&reply
->wait_q
);
888 qeth_put_reply(reply
);
892 spin_unlock_irqrestore(&card
->lock
, flags
);
894 memcpy(&card
->seqno
.pdu_hdr_ack
,
895 QETH_PDU_HEADER_SEQ_NO(iob
->data
),
897 qeth_release_buffer(channel
, iob
);
900 static int qeth_setup_channel(struct qeth_channel
*channel
)
904 QETH_DBF_TEXT(SETUP
, 2, "setupch");
905 for (cnt
= 0; cnt
< QETH_CMD_BUFFER_NO
; cnt
++) {
906 channel
->iob
[cnt
].data
=
907 kzalloc(QETH_BUFSIZE
, GFP_DMA
|GFP_KERNEL
);
908 if (channel
->iob
[cnt
].data
== NULL
)
910 channel
->iob
[cnt
].state
= BUF_STATE_FREE
;
911 channel
->iob
[cnt
].channel
= channel
;
912 channel
->iob
[cnt
].callback
= qeth_send_control_data_cb
;
913 channel
->iob
[cnt
].rc
= 0;
915 if (cnt
< QETH_CMD_BUFFER_NO
) {
917 kfree(channel
->iob
[cnt
].data
);
921 channel
->io_buf_no
= 0;
922 atomic_set(&channel
->irq_pending
, 0);
923 spin_lock_init(&channel
->iob_lock
);
925 init_waitqueue_head(&channel
->wait_q
);
929 static int qeth_set_thread_start_bit(struct qeth_card
*card
,
930 unsigned long thread
)
934 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
935 if (!(card
->thread_allowed_mask
& thread
) ||
936 (card
->thread_start_mask
& thread
)) {
937 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
940 card
->thread_start_mask
|= thread
;
941 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
945 void qeth_clear_thread_start_bit(struct qeth_card
*card
, unsigned long thread
)
949 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
950 card
->thread_start_mask
&= ~thread
;
951 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
952 wake_up(&card
->wait_q
);
954 EXPORT_SYMBOL_GPL(qeth_clear_thread_start_bit
);
956 void qeth_clear_thread_running_bit(struct qeth_card
*card
, unsigned long thread
)
960 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
961 card
->thread_running_mask
&= ~thread
;
962 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
963 wake_up(&card
->wait_q
);
965 EXPORT_SYMBOL_GPL(qeth_clear_thread_running_bit
);
967 static int __qeth_do_run_thread(struct qeth_card
*card
, unsigned long thread
)
972 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
973 if (card
->thread_start_mask
& thread
) {
974 if ((card
->thread_allowed_mask
& thread
) &&
975 !(card
->thread_running_mask
& thread
)) {
977 card
->thread_start_mask
&= ~thread
;
978 card
->thread_running_mask
|= thread
;
982 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
986 int qeth_do_run_thread(struct qeth_card
*card
, unsigned long thread
)
990 wait_event(card
->wait_q
,
991 (rc
= __qeth_do_run_thread(card
, thread
)) >= 0);
994 EXPORT_SYMBOL_GPL(qeth_do_run_thread
);
996 void qeth_schedule_recovery(struct qeth_card
*card
)
998 QETH_CARD_TEXT(card
, 2, "startrec");
999 if (qeth_set_thread_start_bit(card
, QETH_RECOVER_THREAD
) == 0)
1000 schedule_work(&card
->kernel_thread_starter
);
1002 EXPORT_SYMBOL_GPL(qeth_schedule_recovery
);
1004 static int qeth_get_problem(struct ccw_device
*cdev
, struct irb
*irb
)
1008 struct qeth_card
*card
;
1010 sense
= (char *) irb
->ecw
;
1011 cstat
= irb
->scsw
.cmd
.cstat
;
1012 dstat
= irb
->scsw
.cmd
.dstat
;
1013 card
= CARD_FROM_CDEV(cdev
);
1015 if (cstat
& (SCHN_STAT_CHN_CTRL_CHK
| SCHN_STAT_INTF_CTRL_CHK
|
1016 SCHN_STAT_CHN_DATA_CHK
| SCHN_STAT_CHAIN_CHECK
|
1017 SCHN_STAT_PROT_CHECK
| SCHN_STAT_PROG_CHECK
)) {
1018 QETH_CARD_TEXT(card
, 2, "CGENCHK");
1019 dev_warn(&cdev
->dev
, "The qeth device driver "
1020 "failed to recover an error on the device\n");
1021 QETH_DBF_MESSAGE(2, "%s check on device dstat=x%x, cstat=x%x\n",
1022 dev_name(&cdev
->dev
), dstat
, cstat
);
1023 print_hex_dump(KERN_WARNING
, "qeth: irb ", DUMP_PREFIX_OFFSET
,
1028 if (dstat
& DEV_STAT_UNIT_CHECK
) {
1029 if (sense
[SENSE_RESETTING_EVENT_BYTE
] &
1030 SENSE_RESETTING_EVENT_FLAG
) {
1031 QETH_CARD_TEXT(card
, 2, "REVIND");
1034 if (sense
[SENSE_COMMAND_REJECT_BYTE
] &
1035 SENSE_COMMAND_REJECT_FLAG
) {
1036 QETH_CARD_TEXT(card
, 2, "CMDREJi");
1039 if ((sense
[2] == 0xaf) && (sense
[3] == 0xfe)) {
1040 QETH_CARD_TEXT(card
, 2, "AFFE");
1043 if ((!sense
[0]) && (!sense
[1]) && (!sense
[2]) && (!sense
[3])) {
1044 QETH_CARD_TEXT(card
, 2, "ZEROSEN");
1047 QETH_CARD_TEXT(card
, 2, "DGENCHK");
1053 static long __qeth_check_irb_error(struct ccw_device
*cdev
,
1054 unsigned long intparm
, struct irb
*irb
)
1056 struct qeth_card
*card
;
1058 card
= CARD_FROM_CDEV(cdev
);
1060 if (!card
|| !IS_ERR(irb
))
1063 switch (PTR_ERR(irb
)) {
1065 QETH_DBF_MESSAGE(2, "%s i/o-error on device\n",
1066 dev_name(&cdev
->dev
));
1067 QETH_CARD_TEXT(card
, 2, "ckirberr");
1068 QETH_CARD_TEXT_(card
, 2, " rc%d", -EIO
);
1071 dev_warn(&cdev
->dev
, "A hardware operation timed out"
1072 " on the device\n");
1073 QETH_CARD_TEXT(card
, 2, "ckirberr");
1074 QETH_CARD_TEXT_(card
, 2, " rc%d", -ETIMEDOUT
);
1075 if (intparm
== QETH_RCD_PARM
) {
1076 if (card
->data
.ccwdev
== cdev
) {
1077 card
->data
.state
= CH_STATE_DOWN
;
1078 wake_up(&card
->wait_q
);
1083 QETH_DBF_MESSAGE(2, "%s unknown error %ld on device\n",
1084 dev_name(&cdev
->dev
), PTR_ERR(irb
));
1085 QETH_CARD_TEXT(card
, 2, "ckirberr");
1086 QETH_CARD_TEXT(card
, 2, " rc???");
1088 return PTR_ERR(irb
);
1091 static void qeth_irq(struct ccw_device
*cdev
, unsigned long intparm
,
1096 struct qeth_cmd_buffer
*buffer
;
1097 struct qeth_channel
*channel
;
1098 struct qeth_card
*card
;
1099 struct qeth_cmd_buffer
*iob
;
1102 if (__qeth_check_irb_error(cdev
, intparm
, irb
))
1104 cstat
= irb
->scsw
.cmd
.cstat
;
1105 dstat
= irb
->scsw
.cmd
.dstat
;
1107 card
= CARD_FROM_CDEV(cdev
);
1111 QETH_CARD_TEXT(card
, 5, "irq");
1113 if (card
->read
.ccwdev
== cdev
) {
1114 channel
= &card
->read
;
1115 QETH_CARD_TEXT(card
, 5, "read");
1116 } else if (card
->write
.ccwdev
== cdev
) {
1117 channel
= &card
->write
;
1118 QETH_CARD_TEXT(card
, 5, "write");
1120 channel
= &card
->data
;
1121 QETH_CARD_TEXT(card
, 5, "data");
1123 atomic_set(&channel
->irq_pending
, 0);
1125 if (irb
->scsw
.cmd
.fctl
& (SCSW_FCTL_CLEAR_FUNC
))
1126 channel
->state
= CH_STATE_STOPPED
;
1128 if (irb
->scsw
.cmd
.fctl
& (SCSW_FCTL_HALT_FUNC
))
1129 channel
->state
= CH_STATE_HALTED
;
1131 /*let's wake up immediately on data channel*/
1132 if ((channel
== &card
->data
) && (intparm
!= 0) &&
1133 (intparm
!= QETH_RCD_PARM
))
1136 if (intparm
== QETH_CLEAR_CHANNEL_PARM
) {
1137 QETH_CARD_TEXT(card
, 6, "clrchpar");
1138 /* we don't have to handle this further */
1141 if (intparm
== QETH_HALT_CHANNEL_PARM
) {
1142 QETH_CARD_TEXT(card
, 6, "hltchpar");
1143 /* we don't have to handle this further */
1146 if ((dstat
& DEV_STAT_UNIT_EXCEP
) ||
1147 (dstat
& DEV_STAT_UNIT_CHECK
) ||
1149 if (irb
->esw
.esw0
.erw
.cons
) {
1150 dev_warn(&channel
->ccwdev
->dev
,
1151 "The qeth device driver failed to recover "
1152 "an error on the device\n");
1153 QETH_DBF_MESSAGE(2, "%s sense data available. cstat "
1154 "0x%X dstat 0x%X\n",
1155 dev_name(&channel
->ccwdev
->dev
), cstat
, dstat
);
1156 print_hex_dump(KERN_WARNING
, "qeth: irb ",
1157 DUMP_PREFIX_OFFSET
, 16, 1, irb
, 32, 1);
1158 print_hex_dump(KERN_WARNING
, "qeth: sense data ",
1159 DUMP_PREFIX_OFFSET
, 16, 1, irb
->ecw
, 32, 1);
1161 if (intparm
== QETH_RCD_PARM
) {
1162 channel
->state
= CH_STATE_DOWN
;
1165 rc
= qeth_get_problem(cdev
, irb
);
1167 qeth_clear_ipacmd_list(card
);
1168 qeth_schedule_recovery(card
);
1173 if (intparm
== QETH_RCD_PARM
) {
1174 channel
->state
= CH_STATE_RCD_DONE
;
1178 buffer
= (struct qeth_cmd_buffer
*) __va((addr_t
)intparm
);
1179 buffer
->state
= BUF_STATE_PROCESSED
;
1181 if (channel
== &card
->data
)
1183 if (channel
== &card
->read
&&
1184 channel
->state
== CH_STATE_UP
)
1185 qeth_issue_next_read(card
);
1188 index
= channel
->buf_no
;
1189 while (iob
[index
].state
== BUF_STATE_PROCESSED
) {
1190 if (iob
[index
].callback
!= NULL
)
1191 iob
[index
].callback(channel
, iob
+ index
);
1193 index
= (index
+ 1) % QETH_CMD_BUFFER_NO
;
1195 channel
->buf_no
= index
;
1197 wake_up(&card
->wait_q
);
1201 static void qeth_notify_skbs(struct qeth_qdio_out_q
*q
,
1202 struct qeth_qdio_out_buffer
*buf
,
1203 enum iucv_tx_notify notification
)
1205 struct sk_buff
*skb
;
1207 if (skb_queue_empty(&buf
->skb_list
))
1209 skb
= skb_peek(&buf
->skb_list
);
1211 QETH_CARD_TEXT_(q
->card
, 5, "skbn%d", notification
);
1212 QETH_CARD_TEXT_(q
->card
, 5, "%lx", (long) skb
);
1213 if (be16_to_cpu(skb
->protocol
) == ETH_P_AF_IUCV
) {
1215 struct iucv_sock
*iucv
= iucv_sk(skb
->sk
);
1216 iucv
->sk_txnotify(skb
, notification
);
1219 if (skb_queue_is_last(&buf
->skb_list
, skb
))
1222 skb
= skb_queue_next(&buf
->skb_list
, skb
);
1228 static void qeth_release_skbs(struct qeth_qdio_out_buffer
*buf
)
1230 struct sk_buff
*skb
;
1231 struct iucv_sock
*iucv
;
1232 int notify_general_error
= 0;
1234 if (atomic_read(&buf
->state
) == QETH_QDIO_BUF_PENDING
)
1235 notify_general_error
= 1;
1237 /* release may never happen from within CQ tasklet scope */
1238 WARN_ON_ONCE(atomic_read(&buf
->state
) == QETH_QDIO_BUF_IN_CQ
);
1240 skb
= skb_dequeue(&buf
->skb_list
);
1242 QETH_CARD_TEXT(buf
->q
->card
, 5, "skbr");
1243 QETH_CARD_TEXT_(buf
->q
->card
, 5, "%lx", (long) skb
);
1244 if (notify_general_error
&&
1245 be16_to_cpu(skb
->protocol
) == ETH_P_AF_IUCV
) {
1247 iucv
= iucv_sk(skb
->sk
);
1248 iucv
->sk_txnotify(skb
, TX_NOTIFY_GENERALERROR
);
1251 refcount_dec(&skb
->users
);
1252 dev_kfree_skb_any(skb
);
1253 skb
= skb_dequeue(&buf
->skb_list
);
1257 static void qeth_clear_output_buffer(struct qeth_qdio_out_q
*queue
,
1258 struct qeth_qdio_out_buffer
*buf
,
1259 enum qeth_qdio_buffer_states newbufstate
)
1263 /* is PCI flag set on buffer? */
1264 if (buf
->buffer
->element
[0].sflags
& SBAL_SFLAGS0_PCI_REQ
)
1265 atomic_dec(&queue
->set_pci_flags_count
);
1267 if (newbufstate
== QETH_QDIO_BUF_EMPTY
) {
1268 qeth_release_skbs(buf
);
1270 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(queue
->card
); ++i
) {
1271 if (buf
->buffer
->element
[i
].addr
&& buf
->is_header
[i
])
1272 kmem_cache_free(qeth_core_header_cache
,
1273 buf
->buffer
->element
[i
].addr
);
1274 buf
->is_header
[i
] = 0;
1275 buf
->buffer
->element
[i
].length
= 0;
1276 buf
->buffer
->element
[i
].addr
= NULL
;
1277 buf
->buffer
->element
[i
].eflags
= 0;
1278 buf
->buffer
->element
[i
].sflags
= 0;
1280 buf
->buffer
->element
[15].eflags
= 0;
1281 buf
->buffer
->element
[15].sflags
= 0;
1282 buf
->next_element_to_fill
= 0;
1283 atomic_set(&buf
->state
, newbufstate
);
1286 static void qeth_clear_outq_buffers(struct qeth_qdio_out_q
*q
, int free
)
1290 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
) {
1293 qeth_cleanup_handled_pending(q
, j
, 1);
1294 qeth_clear_output_buffer(q
, q
->bufs
[j
], QETH_QDIO_BUF_EMPTY
);
1296 kmem_cache_free(qeth_qdio_outbuf_cache
, q
->bufs
[j
]);
1302 void qeth_clear_qdio_buffers(struct qeth_card
*card
)
1306 QETH_CARD_TEXT(card
, 2, "clearqdbf");
1307 /* clear outbound buffers to free skbs */
1308 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
1309 if (card
->qdio
.out_qs
[i
]) {
1310 qeth_clear_outq_buffers(card
->qdio
.out_qs
[i
], 0);
1314 EXPORT_SYMBOL_GPL(qeth_clear_qdio_buffers
);
1316 static void qeth_free_buffer_pool(struct qeth_card
*card
)
1318 struct qeth_buffer_pool_entry
*pool_entry
, *tmp
;
1320 list_for_each_entry_safe(pool_entry
, tmp
,
1321 &card
->qdio
.init_pool
.entry_list
, init_list
){
1322 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(card
); ++i
)
1323 free_page((unsigned long)pool_entry
->elements
[i
]);
1324 list_del(&pool_entry
->init_list
);
1329 static void qeth_clean_channel(struct qeth_channel
*channel
)
1333 QETH_DBF_TEXT(SETUP
, 2, "freech");
1334 for (cnt
= 0; cnt
< QETH_CMD_BUFFER_NO
; cnt
++)
1335 kfree(channel
->iob
[cnt
].data
);
1338 static void qeth_set_single_write_queues(struct qeth_card
*card
)
1340 if ((atomic_read(&card
->qdio
.state
) != QETH_QDIO_UNINITIALIZED
) &&
1341 (card
->qdio
.no_out_queues
== 4))
1342 qeth_free_qdio_buffers(card
);
1344 card
->qdio
.no_out_queues
= 1;
1345 if (card
->qdio
.default_out_queue
!= 0)
1346 dev_info(&card
->gdev
->dev
, "Priority Queueing not supported\n");
1348 card
->qdio
.default_out_queue
= 0;
1351 static void qeth_set_multiple_write_queues(struct qeth_card
*card
)
1353 if ((atomic_read(&card
->qdio
.state
) != QETH_QDIO_UNINITIALIZED
) &&
1354 (card
->qdio
.no_out_queues
== 1)) {
1355 qeth_free_qdio_buffers(card
);
1356 card
->qdio
.default_out_queue
= 2;
1358 card
->qdio
.no_out_queues
= 4;
1361 static void qeth_update_from_chp_desc(struct qeth_card
*card
)
1363 struct ccw_device
*ccwdev
;
1364 struct channel_path_desc
*chp_dsc
;
1366 QETH_DBF_TEXT(SETUP
, 2, "chp_desc");
1368 ccwdev
= card
->data
.ccwdev
;
1369 chp_dsc
= ccw_device_get_chp_desc(ccwdev
, 0);
1373 card
->info
.func_level
= 0x4100 + chp_dsc
->desc
;
1374 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
1377 /* CHPP field bit 6 == 1 -> single queue */
1378 if ((chp_dsc
->chpp
& 0x02) == 0x02)
1379 qeth_set_single_write_queues(card
);
1381 qeth_set_multiple_write_queues(card
);
1384 QETH_DBF_TEXT_(SETUP
, 2, "nr:%x", card
->qdio
.no_out_queues
);
1385 QETH_DBF_TEXT_(SETUP
, 2, "lvl:%02x", card
->info
.func_level
);
1388 static void qeth_init_qdio_info(struct qeth_card
*card
)
1390 QETH_DBF_TEXT(SETUP
, 4, "intqdinf");
1391 atomic_set(&card
->qdio
.state
, QETH_QDIO_UNINITIALIZED
);
1393 card
->qdio
.no_in_queues
= 1;
1394 card
->qdio
.in_buf_size
= QETH_IN_BUF_SIZE_DEFAULT
;
1395 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
1396 card
->qdio
.init_pool
.buf_count
= QETH_IN_BUF_COUNT_HSDEFAULT
;
1398 card
->qdio
.init_pool
.buf_count
= QETH_IN_BUF_COUNT_DEFAULT
;
1399 card
->qdio
.in_buf_pool
.buf_count
= card
->qdio
.init_pool
.buf_count
;
1400 INIT_LIST_HEAD(&card
->qdio
.in_buf_pool
.entry_list
);
1401 INIT_LIST_HEAD(&card
->qdio
.init_pool
.entry_list
);
1404 static void qeth_set_intial_options(struct qeth_card
*card
)
1406 card
->options
.route4
.type
= NO_ROUTER
;
1407 card
->options
.route6
.type
= NO_ROUTER
;
1408 card
->options
.fake_broadcast
= 0;
1409 card
->options
.performance_stats
= 0;
1410 card
->options
.rx_sg_cb
= QETH_RX_SG_CB
;
1411 card
->options
.isolation
= ISOLATION_MODE_NONE
;
1412 card
->options
.cq
= QETH_CQ_DISABLED
;
1415 static int qeth_do_start_thread(struct qeth_card
*card
, unsigned long thread
)
1417 unsigned long flags
;
1420 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
1421 QETH_CARD_TEXT_(card
, 4, " %02x%02x%02x",
1422 (u8
) card
->thread_start_mask
,
1423 (u8
) card
->thread_allowed_mask
,
1424 (u8
) card
->thread_running_mask
);
1425 rc
= (card
->thread_start_mask
& thread
);
1426 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
1430 static void qeth_start_kernel_thread(struct work_struct
*work
)
1432 struct task_struct
*ts
;
1433 struct qeth_card
*card
= container_of(work
, struct qeth_card
,
1434 kernel_thread_starter
);
1435 QETH_CARD_TEXT(card
, 2, "strthrd");
1437 if (card
->read
.state
!= CH_STATE_UP
&&
1438 card
->write
.state
!= CH_STATE_UP
)
1440 if (qeth_do_start_thread(card
, QETH_RECOVER_THREAD
)) {
1441 ts
= kthread_run(card
->discipline
->recover
, (void *)card
,
1444 qeth_clear_thread_start_bit(card
, QETH_RECOVER_THREAD
);
1445 qeth_clear_thread_running_bit(card
,
1446 QETH_RECOVER_THREAD
);
1451 static void qeth_buffer_reclaim_work(struct work_struct
*);
1452 static int qeth_setup_card(struct qeth_card
*card
)
1455 QETH_DBF_TEXT(SETUP
, 2, "setupcrd");
1456 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
1458 card
->read
.state
= CH_STATE_DOWN
;
1459 card
->write
.state
= CH_STATE_DOWN
;
1460 card
->data
.state
= CH_STATE_DOWN
;
1461 card
->state
= CARD_STATE_DOWN
;
1462 card
->lan_online
= 0;
1463 card
->read_or_write_problem
= 0;
1465 spin_lock_init(&card
->vlanlock
);
1466 spin_lock_init(&card
->mclock
);
1467 spin_lock_init(&card
->lock
);
1468 spin_lock_init(&card
->ip_lock
);
1469 spin_lock_init(&card
->thread_mask_lock
);
1470 mutex_init(&card
->conf_mutex
);
1471 mutex_init(&card
->discipline_mutex
);
1472 card
->thread_start_mask
= 0;
1473 card
->thread_allowed_mask
= 0;
1474 card
->thread_running_mask
= 0;
1475 INIT_WORK(&card
->kernel_thread_starter
, qeth_start_kernel_thread
);
1476 INIT_LIST_HEAD(&card
->cmd_waiter_list
);
1477 init_waitqueue_head(&card
->wait_q
);
1478 /* initial options */
1479 qeth_set_intial_options(card
);
1480 /* IP address takeover */
1481 INIT_LIST_HEAD(&card
->ipato
.entries
);
1482 card
->ipato
.enabled
= false;
1483 card
->ipato
.invert4
= false;
1484 card
->ipato
.invert6
= false;
1485 /* init QDIO stuff */
1486 qeth_init_qdio_info(card
);
1487 INIT_DELAYED_WORK(&card
->buffer_reclaim_work
, qeth_buffer_reclaim_work
);
1488 INIT_WORK(&card
->close_dev_work
, qeth_close_dev_handler
);
1492 static void qeth_core_sl_print(struct seq_file
*m
, struct service_level
*slr
)
1494 struct qeth_card
*card
= container_of(slr
, struct qeth_card
,
1495 qeth_service_level
);
1496 if (card
->info
.mcl_level
[0])
1497 seq_printf(m
, "qeth: %s firmware level %s\n",
1498 CARD_BUS_ID(card
), card
->info
.mcl_level
);
1501 static struct qeth_card
*qeth_alloc_card(void)
1503 struct qeth_card
*card
;
1505 QETH_DBF_TEXT(SETUP
, 2, "alloccrd");
1506 card
= kzalloc(sizeof(struct qeth_card
), GFP_DMA
|GFP_KERNEL
);
1509 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
1510 if (qeth_setup_channel(&card
->read
))
1512 if (qeth_setup_channel(&card
->write
))
1514 card
->options
.layer2
= -1;
1515 card
->qeth_service_level
.seq_print
= qeth_core_sl_print
;
1516 register_service_level(&card
->qeth_service_level
);
1520 qeth_clean_channel(&card
->read
);
1527 static void qeth_determine_card_type(struct qeth_card
*card
)
1529 QETH_DBF_TEXT(SETUP
, 2, "detcdtyp");
1531 card
->qdio
.do_prio_queueing
= QETH_PRIOQ_DEFAULT
;
1532 card
->qdio
.default_out_queue
= QETH_DEFAULT_QUEUE
;
1533 card
->info
.type
= CARD_RDEV(card
)->id
.driver_info
;
1534 card
->qdio
.no_out_queues
= QETH_MAX_QUEUES
;
1535 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
1536 card
->info
.is_multicast_different
= 0x0103;
1537 qeth_update_from_chp_desc(card
);
1540 static int qeth_clear_channel(struct qeth_channel
*channel
)
1542 unsigned long flags
;
1543 struct qeth_card
*card
;
1546 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1547 QETH_CARD_TEXT(card
, 3, "clearch");
1548 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1549 rc
= ccw_device_clear(channel
->ccwdev
, QETH_CLEAR_CHANNEL_PARM
);
1550 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1554 rc
= wait_event_interruptible_timeout(card
->wait_q
,
1555 channel
->state
== CH_STATE_STOPPED
, QETH_TIMEOUT
);
1556 if (rc
== -ERESTARTSYS
)
1558 if (channel
->state
!= CH_STATE_STOPPED
)
1560 channel
->state
= CH_STATE_DOWN
;
1564 static int qeth_halt_channel(struct qeth_channel
*channel
)
1566 unsigned long flags
;
1567 struct qeth_card
*card
;
1570 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1571 QETH_CARD_TEXT(card
, 3, "haltch");
1572 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1573 rc
= ccw_device_halt(channel
->ccwdev
, QETH_HALT_CHANNEL_PARM
);
1574 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1578 rc
= wait_event_interruptible_timeout(card
->wait_q
,
1579 channel
->state
== CH_STATE_HALTED
, QETH_TIMEOUT
);
1580 if (rc
== -ERESTARTSYS
)
1582 if (channel
->state
!= CH_STATE_HALTED
)
1587 static int qeth_halt_channels(struct qeth_card
*card
)
1589 int rc1
= 0, rc2
= 0, rc3
= 0;
1591 QETH_CARD_TEXT(card
, 3, "haltchs");
1592 rc1
= qeth_halt_channel(&card
->read
);
1593 rc2
= qeth_halt_channel(&card
->write
);
1594 rc3
= qeth_halt_channel(&card
->data
);
1602 static int qeth_clear_channels(struct qeth_card
*card
)
1604 int rc1
= 0, rc2
= 0, rc3
= 0;
1606 QETH_CARD_TEXT(card
, 3, "clearchs");
1607 rc1
= qeth_clear_channel(&card
->read
);
1608 rc2
= qeth_clear_channel(&card
->write
);
1609 rc3
= qeth_clear_channel(&card
->data
);
1617 static int qeth_clear_halt_card(struct qeth_card
*card
, int halt
)
1621 QETH_CARD_TEXT(card
, 3, "clhacrd");
1624 rc
= qeth_halt_channels(card
);
1627 return qeth_clear_channels(card
);
1630 int qeth_qdio_clear_card(struct qeth_card
*card
, int use_halt
)
1634 QETH_CARD_TEXT(card
, 3, "qdioclr");
1635 switch (atomic_cmpxchg(&card
->qdio
.state
, QETH_QDIO_ESTABLISHED
,
1636 QETH_QDIO_CLEANING
)) {
1637 case QETH_QDIO_ESTABLISHED
:
1638 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
1639 rc
= qdio_shutdown(CARD_DDEV(card
),
1640 QDIO_FLAG_CLEANUP_USING_HALT
);
1642 rc
= qdio_shutdown(CARD_DDEV(card
),
1643 QDIO_FLAG_CLEANUP_USING_CLEAR
);
1645 QETH_CARD_TEXT_(card
, 3, "1err%d", rc
);
1646 atomic_set(&card
->qdio
.state
, QETH_QDIO_ALLOCATED
);
1648 case QETH_QDIO_CLEANING
:
1653 rc
= qeth_clear_halt_card(card
, use_halt
);
1655 QETH_CARD_TEXT_(card
, 3, "2err%d", rc
);
1656 card
->state
= CARD_STATE_DOWN
;
1659 EXPORT_SYMBOL_GPL(qeth_qdio_clear_card
);
1661 static int qeth_read_conf_data(struct qeth_card
*card
, void **buffer
,
1667 struct qeth_channel
*channel
= &card
->data
;
1668 unsigned long flags
;
1671 * scan for RCD command in extended SenseID data
1673 ciw
= ccw_device_get_ciw(channel
->ccwdev
, CIW_TYPE_RCD
);
1674 if (!ciw
|| ciw
->cmd
== 0)
1676 rcd_buf
= kzalloc(ciw
->count
, GFP_KERNEL
| GFP_DMA
);
1680 channel
->ccw
.cmd_code
= ciw
->cmd
;
1681 channel
->ccw
.cda
= (__u32
) __pa(rcd_buf
);
1682 channel
->ccw
.count
= ciw
->count
;
1683 channel
->ccw
.flags
= CCW_FLAG_SLI
;
1684 channel
->state
= CH_STATE_RCD
;
1685 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1686 ret
= ccw_device_start_timeout(channel
->ccwdev
, &channel
->ccw
,
1687 QETH_RCD_PARM
, LPM_ANYPATH
, 0,
1689 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1691 wait_event(card
->wait_q
,
1692 (channel
->state
== CH_STATE_RCD_DONE
||
1693 channel
->state
== CH_STATE_DOWN
));
1694 if (channel
->state
== CH_STATE_DOWN
)
1697 channel
->state
= CH_STATE_DOWN
;
1703 *length
= ciw
->count
;
1709 static void qeth_configure_unitaddr(struct qeth_card
*card
, char *prcd
)
1711 QETH_DBF_TEXT(SETUP
, 2, "cfgunit");
1712 card
->info
.chpid
= prcd
[30];
1713 card
->info
.unit_addr2
= prcd
[31];
1714 card
->info
.cula
= prcd
[63];
1715 card
->info
.guestlan
= ((prcd
[0x10] == _ascebc
['V']) &&
1716 (prcd
[0x11] == _ascebc
['M']));
1719 static enum qeth_discipline_id
qeth_vm_detect_layer(struct qeth_card
*card
)
1721 enum qeth_discipline_id disc
= QETH_DISCIPLINE_UNDETERMINED
;
1722 struct diag26c_vnic_resp
*response
= NULL
;
1723 struct diag26c_vnic_req
*request
= NULL
;
1724 struct ccw_dev_id id
;
1728 QETH_DBF_TEXT(SETUP
, 2, "vmlayer");
1730 cpcmd("QUERY USERID", userid
, sizeof(userid
), &rc
);
1734 request
= kzalloc(sizeof(*request
), GFP_KERNEL
| GFP_DMA
);
1735 response
= kzalloc(sizeof(*response
), GFP_KERNEL
| GFP_DMA
);
1736 if (!request
|| !response
) {
1741 ccw_device_get_id(CARD_RDEV(card
), &id
);
1742 request
->resp_buf_len
= sizeof(*response
);
1743 request
->resp_version
= DIAG26C_VERSION6_VM65918
;
1744 request
->req_format
= DIAG26C_VNIC_INFO
;
1746 memcpy(&request
->sys_name
, userid
, 8);
1747 request
->devno
= id
.devno
;
1749 QETH_DBF_HEX(CTRL
, 2, request
, sizeof(*request
));
1750 rc
= diag26c(request
, response
, DIAG26C_PORT_VNIC
);
1751 QETH_DBF_HEX(CTRL
, 2, request
, sizeof(*request
));
1754 QETH_DBF_HEX(CTRL
, 2, response
, sizeof(*response
));
1756 if (request
->resp_buf_len
< sizeof(*response
) ||
1757 response
->version
!= request
->resp_version
) {
1762 if (response
->protocol
== VNIC_INFO_PROT_L2
)
1763 disc
= QETH_DISCIPLINE_LAYER2
;
1764 else if (response
->protocol
== VNIC_INFO_PROT_L3
)
1765 disc
= QETH_DISCIPLINE_LAYER3
;
1771 QETH_DBF_TEXT_(SETUP
, 2, "err%x", rc
);
1775 /* Determine whether the device requires a specific layer discipline */
1776 static enum qeth_discipline_id
qeth_enforce_discipline(struct qeth_card
*card
)
1778 enum qeth_discipline_id disc
= QETH_DISCIPLINE_UNDETERMINED
;
1780 if (card
->info
.type
== QETH_CARD_TYPE_OSM
||
1781 card
->info
.type
== QETH_CARD_TYPE_OSN
)
1782 disc
= QETH_DISCIPLINE_LAYER2
;
1783 else if (card
->info
.guestlan
)
1784 disc
= (card
->info
.type
== QETH_CARD_TYPE_IQD
) ?
1785 QETH_DISCIPLINE_LAYER3
:
1786 qeth_vm_detect_layer(card
);
1789 case QETH_DISCIPLINE_LAYER2
:
1790 QETH_DBF_TEXT(SETUP
, 3, "force l2");
1792 case QETH_DISCIPLINE_LAYER3
:
1793 QETH_DBF_TEXT(SETUP
, 3, "force l3");
1796 QETH_DBF_TEXT(SETUP
, 3, "force no");
1802 static void qeth_configure_blkt_default(struct qeth_card
*card
, char *prcd
)
1804 QETH_DBF_TEXT(SETUP
, 2, "cfgblkt");
1806 if (prcd
[74] == 0xF0 && prcd
[75] == 0xF0 &&
1807 prcd
[76] >= 0xF1 && prcd
[76] <= 0xF4) {
1808 card
->info
.blkt
.time_total
= 0;
1809 card
->info
.blkt
.inter_packet
= 0;
1810 card
->info
.blkt
.inter_packet_jumbo
= 0;
1812 card
->info
.blkt
.time_total
= 250;
1813 card
->info
.blkt
.inter_packet
= 5;
1814 card
->info
.blkt
.inter_packet_jumbo
= 15;
1818 static void qeth_init_tokens(struct qeth_card
*card
)
1820 card
->token
.issuer_rm_w
= 0x00010103UL
;
1821 card
->token
.cm_filter_w
= 0x00010108UL
;
1822 card
->token
.cm_connection_w
= 0x0001010aUL
;
1823 card
->token
.ulp_filter_w
= 0x0001010bUL
;
1824 card
->token
.ulp_connection_w
= 0x0001010dUL
;
1827 static void qeth_init_func_level(struct qeth_card
*card
)
1829 switch (card
->info
.type
) {
1830 case QETH_CARD_TYPE_IQD
:
1831 card
->info
.func_level
= QETH_IDX_FUNC_LEVEL_IQD
;
1833 case QETH_CARD_TYPE_OSD
:
1834 case QETH_CARD_TYPE_OSN
:
1835 card
->info
.func_level
= QETH_IDX_FUNC_LEVEL_OSD
;
1842 static int qeth_idx_activate_get_answer(struct qeth_channel
*channel
,
1843 void (*idx_reply_cb
)(struct qeth_channel
*,
1844 struct qeth_cmd_buffer
*))
1846 struct qeth_cmd_buffer
*iob
;
1847 unsigned long flags
;
1849 struct qeth_card
*card
;
1851 QETH_DBF_TEXT(SETUP
, 2, "idxanswr");
1852 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1853 iob
= qeth_get_buffer(channel
);
1856 iob
->callback
= idx_reply_cb
;
1857 memcpy(&channel
->ccw
, READ_CCW
, sizeof(struct ccw1
));
1858 channel
->ccw
.count
= QETH_BUFSIZE
;
1859 channel
->ccw
.cda
= (__u32
) __pa(iob
->data
);
1861 wait_event(card
->wait_q
,
1862 atomic_cmpxchg(&channel
->irq_pending
, 0, 1) == 0);
1863 QETH_DBF_TEXT(SETUP
, 6, "noirqpnd");
1864 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1865 rc
= ccw_device_start(channel
->ccwdev
,
1866 &channel
->ccw
, (addr_t
) iob
, 0, 0);
1867 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1870 QETH_DBF_MESSAGE(2, "Error2 in activating channel rc=%d\n", rc
);
1871 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
1872 atomic_set(&channel
->irq_pending
, 0);
1873 wake_up(&card
->wait_q
);
1876 rc
= wait_event_interruptible_timeout(card
->wait_q
,
1877 channel
->state
== CH_STATE_UP
, QETH_TIMEOUT
);
1878 if (rc
== -ERESTARTSYS
)
1880 if (channel
->state
!= CH_STATE_UP
) {
1882 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
1883 qeth_clear_cmd_buffers(channel
);
1889 static int qeth_idx_activate_channel(struct qeth_channel
*channel
,
1890 void (*idx_reply_cb
)(struct qeth_channel
*,
1891 struct qeth_cmd_buffer
*))
1893 struct qeth_card
*card
;
1894 struct qeth_cmd_buffer
*iob
;
1895 unsigned long flags
;
1899 struct ccw_dev_id temp_devid
;
1901 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1903 QETH_DBF_TEXT(SETUP
, 2, "idxactch");
1905 iob
= qeth_get_buffer(channel
);
1908 iob
->callback
= idx_reply_cb
;
1909 memcpy(&channel
->ccw
, WRITE_CCW
, sizeof(struct ccw1
));
1910 channel
->ccw
.count
= IDX_ACTIVATE_SIZE
;
1911 channel
->ccw
.cda
= (__u32
) __pa(iob
->data
);
1912 if (channel
== &card
->write
) {
1913 memcpy(iob
->data
, IDX_ACTIVATE_WRITE
, IDX_ACTIVATE_SIZE
);
1914 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob
->data
),
1915 &card
->seqno
.trans_hdr
, QETH_SEQ_NO_LENGTH
);
1916 card
->seqno
.trans_hdr
++;
1918 memcpy(iob
->data
, IDX_ACTIVATE_READ
, IDX_ACTIVATE_SIZE
);
1919 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob
->data
),
1920 &card
->seqno
.trans_hdr
, QETH_SEQ_NO_LENGTH
);
1922 tmp
= ((__u8
)card
->info
.portno
) | 0x80;
1923 memcpy(QETH_IDX_ACT_PNO(iob
->data
), &tmp
, 1);
1924 memcpy(QETH_IDX_ACT_ISSUER_RM_TOKEN(iob
->data
),
1925 &card
->token
.issuer_rm_w
, QETH_MPC_TOKEN_LENGTH
);
1926 memcpy(QETH_IDX_ACT_FUNC_LEVEL(iob
->data
),
1927 &card
->info
.func_level
, sizeof(__u16
));
1928 ccw_device_get_id(CARD_DDEV(card
), &temp_devid
);
1929 memcpy(QETH_IDX_ACT_QDIO_DEV_CUA(iob
->data
), &temp_devid
.devno
, 2);
1930 temp
= (card
->info
.cula
<< 8) + card
->info
.unit_addr2
;
1931 memcpy(QETH_IDX_ACT_QDIO_DEV_REALADDR(iob
->data
), &temp
, 2);
1933 wait_event(card
->wait_q
,
1934 atomic_cmpxchg(&channel
->irq_pending
, 0, 1) == 0);
1935 QETH_DBF_TEXT(SETUP
, 6, "noirqpnd");
1936 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1937 rc
= ccw_device_start(channel
->ccwdev
,
1938 &channel
->ccw
, (addr_t
) iob
, 0, 0);
1939 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1942 QETH_DBF_MESSAGE(2, "Error1 in activating channel. rc=%d\n",
1944 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
1945 atomic_set(&channel
->irq_pending
, 0);
1946 wake_up(&card
->wait_q
);
1949 rc
= wait_event_interruptible_timeout(card
->wait_q
,
1950 channel
->state
== CH_STATE_ACTIVATING
, QETH_TIMEOUT
);
1951 if (rc
== -ERESTARTSYS
)
1953 if (channel
->state
!= CH_STATE_ACTIVATING
) {
1954 dev_warn(&channel
->ccwdev
->dev
, "The qeth device driver"
1955 " failed to recover an error on the device\n");
1956 QETH_DBF_MESSAGE(2, "%s IDX activate timed out\n",
1957 dev_name(&channel
->ccwdev
->dev
));
1958 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", -ETIME
);
1959 qeth_clear_cmd_buffers(channel
);
1962 return qeth_idx_activate_get_answer(channel
, idx_reply_cb
);
1965 static int qeth_peer_func_level(int level
)
1967 if ((level
& 0xff) == 8)
1968 return (level
& 0xff) + 0x400;
1969 if (((level
>> 8) & 3) == 1)
1970 return (level
& 0xff) + 0x200;
1974 static void qeth_idx_write_cb(struct qeth_channel
*channel
,
1975 struct qeth_cmd_buffer
*iob
)
1977 struct qeth_card
*card
;
1980 QETH_DBF_TEXT(SETUP
, 2, "idxwrcb");
1982 if (channel
->state
== CH_STATE_DOWN
) {
1983 channel
->state
= CH_STATE_ACTIVATING
;
1986 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1988 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob
->data
))) {
1989 if (QETH_IDX_ACT_CAUSE_CODE(iob
->data
) == QETH_IDX_ACT_ERR_EXCL
)
1990 dev_err(&card
->write
.ccwdev
->dev
,
1991 "The adapter is used exclusively by another "
1994 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on write channel:"
1995 " negative reply\n",
1996 dev_name(&card
->write
.ccwdev
->dev
));
1999 memcpy(&temp
, QETH_IDX_ACT_FUNC_LEVEL(iob
->data
), 2);
2000 if ((temp
& ~0x0100) != qeth_peer_func_level(card
->info
.func_level
)) {
2001 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on write channel: "
2002 "function level mismatch (sent: 0x%x, received: "
2003 "0x%x)\n", dev_name(&card
->write
.ccwdev
->dev
),
2004 card
->info
.func_level
, temp
);
2007 channel
->state
= CH_STATE_UP
;
2009 qeth_release_buffer(channel
, iob
);
2012 static void qeth_idx_read_cb(struct qeth_channel
*channel
,
2013 struct qeth_cmd_buffer
*iob
)
2015 struct qeth_card
*card
;
2018 QETH_DBF_TEXT(SETUP
, 2, "idxrdcb");
2019 if (channel
->state
== CH_STATE_DOWN
) {
2020 channel
->state
= CH_STATE_ACTIVATING
;
2024 card
= CARD_FROM_CDEV(channel
->ccwdev
);
2025 if (qeth_check_idx_response(card
, iob
->data
))
2028 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob
->data
))) {
2029 switch (QETH_IDX_ACT_CAUSE_CODE(iob
->data
)) {
2030 case QETH_IDX_ACT_ERR_EXCL
:
2031 dev_err(&card
->write
.ccwdev
->dev
,
2032 "The adapter is used exclusively by another "
2035 case QETH_IDX_ACT_ERR_AUTH
:
2036 case QETH_IDX_ACT_ERR_AUTH_USER
:
2037 dev_err(&card
->read
.ccwdev
->dev
,
2038 "Setting the device online failed because of "
2039 "insufficient authorization\n");
2042 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on read channel:"
2043 " negative reply\n",
2044 dev_name(&card
->read
.ccwdev
->dev
));
2046 QETH_CARD_TEXT_(card
, 2, "idxread%c",
2047 QETH_IDX_ACT_CAUSE_CODE(iob
->data
));
2051 memcpy(&temp
, QETH_IDX_ACT_FUNC_LEVEL(iob
->data
), 2);
2052 if (temp
!= qeth_peer_func_level(card
->info
.func_level
)) {
2053 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on read channel: function "
2054 "level mismatch (sent: 0x%x, received: 0x%x)\n",
2055 dev_name(&card
->read
.ccwdev
->dev
),
2056 card
->info
.func_level
, temp
);
2059 memcpy(&card
->token
.issuer_rm_r
,
2060 QETH_IDX_ACT_ISSUER_RM_TOKEN(iob
->data
),
2061 QETH_MPC_TOKEN_LENGTH
);
2062 memcpy(&card
->info
.mcl_level
[0],
2063 QETH_IDX_REPLY_LEVEL(iob
->data
), QETH_MCL_LENGTH
);
2064 channel
->state
= CH_STATE_UP
;
2066 qeth_release_buffer(channel
, iob
);
2069 void qeth_prepare_control_data(struct qeth_card
*card
, int len
,
2070 struct qeth_cmd_buffer
*iob
)
2072 qeth_setup_ccw(&card
->write
, iob
->data
, len
);
2073 iob
->callback
= qeth_release_buffer
;
2075 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob
->data
),
2076 &card
->seqno
.trans_hdr
, QETH_SEQ_NO_LENGTH
);
2077 card
->seqno
.trans_hdr
++;
2078 memcpy(QETH_PDU_HEADER_SEQ_NO(iob
->data
),
2079 &card
->seqno
.pdu_hdr
, QETH_SEQ_NO_LENGTH
);
2080 card
->seqno
.pdu_hdr
++;
2081 memcpy(QETH_PDU_HEADER_ACK_SEQ_NO(iob
->data
),
2082 &card
->seqno
.pdu_hdr_ack
, QETH_SEQ_NO_LENGTH
);
2083 QETH_DBF_HEX(CTRL
, 2, iob
->data
, QETH_DBF_CTRL_LEN
);
2085 EXPORT_SYMBOL_GPL(qeth_prepare_control_data
);
2088 * qeth_send_control_data() - send control command to the card
2089 * @card: qeth_card structure pointer
2090 * @len: size of the command buffer
2091 * @iob: qeth_cmd_buffer pointer
2092 * @reply_cb: callback function pointer
2093 * @cb_card: pointer to the qeth_card structure
2094 * @cb_reply: pointer to the qeth_reply structure
2095 * @cb_cmd: pointer to the original iob for non-IPA
2096 * commands, or to the qeth_ipa_cmd structure
2097 * for the IPA commands.
2098 * @reply_param: private pointer passed to the callback
2100 * Returns the value of the `return_code' field of the response
2101 * block returned from the hardware, or other error indication.
2102 * Value of zero indicates successful execution of the command.
2104 * Callback function gets called one or more times, with cb_cmd
2105 * pointing to the response returned by the hardware. Callback
2106 * function must return non-zero if more reply blocks are expected,
2107 * and zero if the last or only reply block is received. Callback
2108 * function can get the value of the reply_param pointer from the
2109 * field 'param' of the structure qeth_reply.
2112 int qeth_send_control_data(struct qeth_card
*card
, int len
,
2113 struct qeth_cmd_buffer
*iob
,
2114 int (*reply_cb
)(struct qeth_card
*cb_card
,
2115 struct qeth_reply
*cb_reply
,
2116 unsigned long cb_cmd
),
2120 unsigned long flags
;
2121 struct qeth_reply
*reply
= NULL
;
2122 unsigned long timeout
, event_timeout
;
2123 struct qeth_ipa_cmd
*cmd
= NULL
;
2125 QETH_CARD_TEXT(card
, 2, "sendctl");
2127 if (card
->read_or_write_problem
) {
2128 qeth_release_buffer(iob
->channel
, iob
);
2131 reply
= qeth_alloc_reply(card
);
2135 reply
->callback
= reply_cb
;
2136 reply
->param
= reply_param
;
2137 if (card
->state
== CARD_STATE_DOWN
)
2138 reply
->seqno
= QETH_IDX_COMMAND_SEQNO
;
2140 reply
->seqno
= card
->seqno
.ipa
++;
2141 init_waitqueue_head(&reply
->wait_q
);
2142 spin_lock_irqsave(&card
->lock
, flags
);
2143 list_add_tail(&reply
->list
, &card
->cmd_waiter_list
);
2144 spin_unlock_irqrestore(&card
->lock
, flags
);
2146 while (atomic_cmpxchg(&card
->write
.irq_pending
, 0, 1)) ;
2147 qeth_prepare_control_data(card
, len
, iob
);
2149 if (IS_IPA(iob
->data
)) {
2150 cmd
= __ipa_cmd(iob
);
2151 event_timeout
= QETH_IPA_TIMEOUT
;
2153 event_timeout
= QETH_TIMEOUT
;
2156 timeout
= jiffies
+ event_timeout
;
2158 QETH_CARD_TEXT(card
, 6, "noirqpnd");
2159 spin_lock_irqsave(get_ccwdev_lock(card
->write
.ccwdev
), flags
);
2160 rc
= ccw_device_start(card
->write
.ccwdev
, &card
->write
.ccw
,
2161 (addr_t
) iob
, 0, 0);
2162 spin_unlock_irqrestore(get_ccwdev_lock(card
->write
.ccwdev
), flags
);
2164 QETH_DBF_MESSAGE(2, "%s qeth_send_control_data: "
2165 "ccw_device_start rc = %i\n",
2166 dev_name(&card
->write
.ccwdev
->dev
), rc
);
2167 QETH_CARD_TEXT_(card
, 2, " err%d", rc
);
2168 spin_lock_irqsave(&card
->lock
, flags
);
2169 list_del_init(&reply
->list
);
2170 qeth_put_reply(reply
);
2171 spin_unlock_irqrestore(&card
->lock
, flags
);
2172 qeth_release_buffer(iob
->channel
, iob
);
2173 atomic_set(&card
->write
.irq_pending
, 0);
2174 wake_up(&card
->wait_q
);
2178 /* we have only one long running ipassist, since we can ensure
2179 process context of this command we can sleep */
2180 if (cmd
&& cmd
->hdr
.command
== IPA_CMD_SETIP
&&
2181 cmd
->hdr
.prot_version
== QETH_PROT_IPV4
) {
2182 if (!wait_event_timeout(reply
->wait_q
,
2183 atomic_read(&reply
->received
), event_timeout
))
2186 while (!atomic_read(&reply
->received
)) {
2187 if (time_after(jiffies
, timeout
))
2193 if (reply
->rc
== -EIO
)
2196 qeth_put_reply(reply
);
2201 spin_lock_irqsave(&reply
->card
->lock
, flags
);
2202 list_del_init(&reply
->list
);
2203 spin_unlock_irqrestore(&reply
->card
->lock
, flags
);
2204 atomic_inc(&reply
->received
);
2206 atomic_set(&card
->write
.irq_pending
, 0);
2207 qeth_release_buffer(iob
->channel
, iob
);
2208 card
->write
.buf_no
= (card
->write
.buf_no
+ 1) % QETH_CMD_BUFFER_NO
;
2210 qeth_put_reply(reply
);
2213 EXPORT_SYMBOL_GPL(qeth_send_control_data
);
2215 static int qeth_cm_enable_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
2218 struct qeth_cmd_buffer
*iob
;
2220 QETH_DBF_TEXT(SETUP
, 2, "cmenblcb");
2222 iob
= (struct qeth_cmd_buffer
*) data
;
2223 memcpy(&card
->token
.cm_filter_r
,
2224 QETH_CM_ENABLE_RESP_FILTER_TOKEN(iob
->data
),
2225 QETH_MPC_TOKEN_LENGTH
);
2226 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
2230 static int qeth_cm_enable(struct qeth_card
*card
)
2233 struct qeth_cmd_buffer
*iob
;
2235 QETH_DBF_TEXT(SETUP
, 2, "cmenable");
2237 iob
= qeth_wait_for_buffer(&card
->write
);
2238 memcpy(iob
->data
, CM_ENABLE
, CM_ENABLE_SIZE
);
2239 memcpy(QETH_CM_ENABLE_ISSUER_RM_TOKEN(iob
->data
),
2240 &card
->token
.issuer_rm_r
, QETH_MPC_TOKEN_LENGTH
);
2241 memcpy(QETH_CM_ENABLE_FILTER_TOKEN(iob
->data
),
2242 &card
->token
.cm_filter_w
, QETH_MPC_TOKEN_LENGTH
);
2244 rc
= qeth_send_control_data(card
, CM_ENABLE_SIZE
, iob
,
2245 qeth_cm_enable_cb
, NULL
);
2249 static int qeth_cm_setup_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
2253 struct qeth_cmd_buffer
*iob
;
2255 QETH_DBF_TEXT(SETUP
, 2, "cmsetpcb");
2257 iob
= (struct qeth_cmd_buffer
*) data
;
2258 memcpy(&card
->token
.cm_connection_r
,
2259 QETH_CM_SETUP_RESP_DEST_ADDR(iob
->data
),
2260 QETH_MPC_TOKEN_LENGTH
);
2261 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
2265 static int qeth_cm_setup(struct qeth_card
*card
)
2268 struct qeth_cmd_buffer
*iob
;
2270 QETH_DBF_TEXT(SETUP
, 2, "cmsetup");
2272 iob
= qeth_wait_for_buffer(&card
->write
);
2273 memcpy(iob
->data
, CM_SETUP
, CM_SETUP_SIZE
);
2274 memcpy(QETH_CM_SETUP_DEST_ADDR(iob
->data
),
2275 &card
->token
.issuer_rm_r
, QETH_MPC_TOKEN_LENGTH
);
2276 memcpy(QETH_CM_SETUP_CONNECTION_TOKEN(iob
->data
),
2277 &card
->token
.cm_connection_w
, QETH_MPC_TOKEN_LENGTH
);
2278 memcpy(QETH_CM_SETUP_FILTER_TOKEN(iob
->data
),
2279 &card
->token
.cm_filter_r
, QETH_MPC_TOKEN_LENGTH
);
2280 rc
= qeth_send_control_data(card
, CM_SETUP_SIZE
, iob
,
2281 qeth_cm_setup_cb
, NULL
);
2286 static int qeth_get_initial_mtu_for_card(struct qeth_card
*card
)
2288 switch (card
->info
.type
) {
2289 case QETH_CARD_TYPE_IQD
:
2290 return card
->info
.max_mtu
;
2291 case QETH_CARD_TYPE_OSD
:
2292 case QETH_CARD_TYPE_OSX
:
2293 if (!card
->options
.layer2
)
2294 return ETH_DATA_LEN
- 8; /* L3: allow for LLC + SNAP */
2297 return ETH_DATA_LEN
;
2301 static int qeth_get_mtu_outof_framesize(int framesize
)
2303 switch (framesize
) {
2317 static int qeth_mtu_is_valid(struct qeth_card
*card
, int mtu
)
2319 switch (card
->info
.type
) {
2320 case QETH_CARD_TYPE_OSD
:
2321 case QETH_CARD_TYPE_OSM
:
2322 case QETH_CARD_TYPE_OSX
:
2323 case QETH_CARD_TYPE_IQD
:
2324 return ((mtu
>= 576) &&
2325 (mtu
<= card
->info
.max_mtu
));
2326 case QETH_CARD_TYPE_OSN
:
2332 static int qeth_ulp_enable_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
2336 __u16 mtu
, framesize
;
2339 struct qeth_cmd_buffer
*iob
;
2341 QETH_DBF_TEXT(SETUP
, 2, "ulpenacb");
2343 iob
= (struct qeth_cmd_buffer
*) data
;
2344 memcpy(&card
->token
.ulp_filter_r
,
2345 QETH_ULP_ENABLE_RESP_FILTER_TOKEN(iob
->data
),
2346 QETH_MPC_TOKEN_LENGTH
);
2347 if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
2348 memcpy(&framesize
, QETH_ULP_ENABLE_RESP_MAX_MTU(iob
->data
), 2);
2349 mtu
= qeth_get_mtu_outof_framesize(framesize
);
2352 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
2355 if (card
->info
.initial_mtu
&& (card
->info
.initial_mtu
!= mtu
)) {
2356 /* frame size has changed */
2358 ((card
->dev
->mtu
== card
->info
.initial_mtu
) ||
2359 (card
->dev
->mtu
> mtu
)))
2360 card
->dev
->mtu
= mtu
;
2361 qeth_free_qdio_buffers(card
);
2363 card
->info
.initial_mtu
= mtu
;
2364 card
->info
.max_mtu
= mtu
;
2365 card
->qdio
.in_buf_size
= mtu
+ 2 * PAGE_SIZE
;
2367 card
->info
.max_mtu
= *(__u16
*)QETH_ULP_ENABLE_RESP_MAX_MTU(
2369 card
->info
.initial_mtu
= min(card
->info
.max_mtu
,
2370 qeth_get_initial_mtu_for_card(card
));
2371 card
->qdio
.in_buf_size
= QETH_IN_BUF_SIZE_DEFAULT
;
2374 memcpy(&len
, QETH_ULP_ENABLE_RESP_DIFINFO_LEN(iob
->data
), 2);
2375 if (len
>= QETH_MPC_DIFINFO_LEN_INDICATES_LINK_TYPE
) {
2377 QETH_ULP_ENABLE_RESP_LINK_TYPE(iob
->data
), 1);
2378 card
->info
.link_type
= link_type
;
2380 card
->info
.link_type
= 0;
2381 QETH_DBF_TEXT_(SETUP
, 2, "link%d", card
->info
.link_type
);
2382 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
2386 static int qeth_ulp_enable(struct qeth_card
*card
)
2390 struct qeth_cmd_buffer
*iob
;
2392 /*FIXME: trace view callbacks*/
2393 QETH_DBF_TEXT(SETUP
, 2, "ulpenabl");
2395 iob
= qeth_wait_for_buffer(&card
->write
);
2396 memcpy(iob
->data
, ULP_ENABLE
, ULP_ENABLE_SIZE
);
2398 *(QETH_ULP_ENABLE_LINKNUM(iob
->data
)) =
2399 (__u8
) card
->info
.portno
;
2400 if (card
->options
.layer2
)
2401 if (card
->info
.type
== QETH_CARD_TYPE_OSN
)
2402 prot_type
= QETH_PROT_OSN2
;
2404 prot_type
= QETH_PROT_LAYER2
;
2406 prot_type
= QETH_PROT_TCPIP
;
2408 memcpy(QETH_ULP_ENABLE_PROT_TYPE(iob
->data
), &prot_type
, 1);
2409 memcpy(QETH_ULP_ENABLE_DEST_ADDR(iob
->data
),
2410 &card
->token
.cm_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2411 memcpy(QETH_ULP_ENABLE_FILTER_TOKEN(iob
->data
),
2412 &card
->token
.ulp_filter_w
, QETH_MPC_TOKEN_LENGTH
);
2413 rc
= qeth_send_control_data(card
, ULP_ENABLE_SIZE
, iob
,
2414 qeth_ulp_enable_cb
, NULL
);
2419 static int qeth_ulp_setup_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
2422 struct qeth_cmd_buffer
*iob
;
2424 QETH_DBF_TEXT(SETUP
, 2, "ulpstpcb");
2426 iob
= (struct qeth_cmd_buffer
*) data
;
2427 memcpy(&card
->token
.ulp_connection_r
,
2428 QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob
->data
),
2429 QETH_MPC_TOKEN_LENGTH
);
2430 if (!strncmp("00S", QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob
->data
),
2432 QETH_DBF_TEXT(SETUP
, 2, "olmlimit");
2433 dev_err(&card
->gdev
->dev
, "A connection could not be "
2434 "established because of an OLM limit\n");
2437 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
2441 static int qeth_ulp_setup(struct qeth_card
*card
)
2445 struct qeth_cmd_buffer
*iob
;
2446 struct ccw_dev_id dev_id
;
2448 QETH_DBF_TEXT(SETUP
, 2, "ulpsetup");
2450 iob
= qeth_wait_for_buffer(&card
->write
);
2451 memcpy(iob
->data
, ULP_SETUP
, ULP_SETUP_SIZE
);
2453 memcpy(QETH_ULP_SETUP_DEST_ADDR(iob
->data
),
2454 &card
->token
.cm_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2455 memcpy(QETH_ULP_SETUP_CONNECTION_TOKEN(iob
->data
),
2456 &card
->token
.ulp_connection_w
, QETH_MPC_TOKEN_LENGTH
);
2457 memcpy(QETH_ULP_SETUP_FILTER_TOKEN(iob
->data
),
2458 &card
->token
.ulp_filter_r
, QETH_MPC_TOKEN_LENGTH
);
2460 ccw_device_get_id(CARD_DDEV(card
), &dev_id
);
2461 memcpy(QETH_ULP_SETUP_CUA(iob
->data
), &dev_id
.devno
, 2);
2462 temp
= (card
->info
.cula
<< 8) + card
->info
.unit_addr2
;
2463 memcpy(QETH_ULP_SETUP_REAL_DEVADDR(iob
->data
), &temp
, 2);
2464 rc
= qeth_send_control_data(card
, ULP_SETUP_SIZE
, iob
,
2465 qeth_ulp_setup_cb
, NULL
);
2469 static int qeth_init_qdio_out_buf(struct qeth_qdio_out_q
*q
, int bidx
)
2472 struct qeth_qdio_out_buffer
*newbuf
;
2475 newbuf
= kmem_cache_zalloc(qeth_qdio_outbuf_cache
, GFP_ATOMIC
);
2480 newbuf
->buffer
= q
->qdio_bufs
[bidx
];
2481 skb_queue_head_init(&newbuf
->skb_list
);
2482 lockdep_set_class(&newbuf
->skb_list
.lock
, &qdio_out_skb_queue_key
);
2485 newbuf
->next_pending
= q
->bufs
[bidx
];
2486 atomic_set(&newbuf
->state
, QETH_QDIO_BUF_EMPTY
);
2487 q
->bufs
[bidx
] = newbuf
;
2489 q
->bufstates
[bidx
].user
= newbuf
;
2490 QETH_CARD_TEXT_(q
->card
, 2, "nbs%d", bidx
);
2491 QETH_CARD_TEXT_(q
->card
, 2, "%lx", (long) newbuf
);
2492 QETH_CARD_TEXT_(q
->card
, 2, "%lx",
2493 (long) newbuf
->next_pending
);
2499 static void qeth_free_qdio_out_buf(struct qeth_qdio_out_q
*q
)
2504 qdio_free_buffers(q
->qdio_bufs
, QDIO_MAX_BUFFERS_PER_Q
);
2508 static struct qeth_qdio_out_q
*qeth_alloc_qdio_out_buf(void)
2510 struct qeth_qdio_out_q
*q
= kzalloc(sizeof(*q
), GFP_KERNEL
);
2515 if (qdio_alloc_buffers(q
->qdio_bufs
, QDIO_MAX_BUFFERS_PER_Q
)) {
2522 static int qeth_alloc_qdio_buffers(struct qeth_card
*card
)
2526 QETH_DBF_TEXT(SETUP
, 2, "allcqdbf");
2528 if (atomic_cmpxchg(&card
->qdio
.state
, QETH_QDIO_UNINITIALIZED
,
2529 QETH_QDIO_ALLOCATED
) != QETH_QDIO_UNINITIALIZED
)
2532 QETH_DBF_TEXT(SETUP
, 2, "inq");
2533 card
->qdio
.in_q
= qeth_alloc_qdio_queue();
2534 if (!card
->qdio
.in_q
)
2537 /* inbound buffer pool */
2538 if (qeth_alloc_buffer_pool(card
))
2543 kzalloc(card
->qdio
.no_out_queues
*
2544 sizeof(struct qeth_qdio_out_q
*), GFP_KERNEL
);
2545 if (!card
->qdio
.out_qs
)
2547 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
2548 card
->qdio
.out_qs
[i
] = qeth_alloc_qdio_out_buf();
2549 if (!card
->qdio
.out_qs
[i
])
2551 QETH_DBF_TEXT_(SETUP
, 2, "outq %i", i
);
2552 QETH_DBF_HEX(SETUP
, 2, &card
->qdio
.out_qs
[i
], sizeof(void *));
2553 card
->qdio
.out_qs
[i
]->queue_no
= i
;
2554 /* give outbound qeth_qdio_buffers their qdio_buffers */
2555 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
) {
2556 WARN_ON(card
->qdio
.out_qs
[i
]->bufs
[j
] != NULL
);
2557 if (qeth_init_qdio_out_buf(card
->qdio
.out_qs
[i
], j
))
2558 goto out_freeoutqbufs
;
2563 if (qeth_alloc_cq(card
))
2571 kmem_cache_free(qeth_qdio_outbuf_cache
,
2572 card
->qdio
.out_qs
[i
]->bufs
[j
]);
2573 card
->qdio
.out_qs
[i
]->bufs
[j
] = NULL
;
2577 qeth_free_qdio_out_buf(card
->qdio
.out_qs
[--i
]);
2578 qeth_clear_outq_buffers(card
->qdio
.out_qs
[i
], 1);
2580 kfree(card
->qdio
.out_qs
);
2581 card
->qdio
.out_qs
= NULL
;
2583 qeth_free_buffer_pool(card
);
2585 qeth_free_qdio_queue(card
->qdio
.in_q
);
2586 card
->qdio
.in_q
= NULL
;
2588 atomic_set(&card
->qdio
.state
, QETH_QDIO_UNINITIALIZED
);
2592 static void qeth_free_qdio_buffers(struct qeth_card
*card
)
2596 if (atomic_xchg(&card
->qdio
.state
, QETH_QDIO_UNINITIALIZED
) ==
2597 QETH_QDIO_UNINITIALIZED
)
2601 cancel_delayed_work_sync(&card
->buffer_reclaim_work
);
2602 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
) {
2603 if (card
->qdio
.in_q
->bufs
[j
].rx_skb
)
2604 dev_kfree_skb_any(card
->qdio
.in_q
->bufs
[j
].rx_skb
);
2606 qeth_free_qdio_queue(card
->qdio
.in_q
);
2607 card
->qdio
.in_q
= NULL
;
2608 /* inbound buffer pool */
2609 qeth_free_buffer_pool(card
);
2610 /* free outbound qdio_qs */
2611 if (card
->qdio
.out_qs
) {
2612 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
2613 qeth_clear_outq_buffers(card
->qdio
.out_qs
[i
], 1);
2614 qeth_free_qdio_out_buf(card
->qdio
.out_qs
[i
]);
2616 kfree(card
->qdio
.out_qs
);
2617 card
->qdio
.out_qs
= NULL
;
2621 static void qeth_create_qib_param_field(struct qeth_card
*card
,
2625 param_field
[0] = _ascebc
['P'];
2626 param_field
[1] = _ascebc
['C'];
2627 param_field
[2] = _ascebc
['I'];
2628 param_field
[3] = _ascebc
['T'];
2629 *((unsigned int *) (¶m_field
[4])) = QETH_PCI_THRESHOLD_A(card
);
2630 *((unsigned int *) (¶m_field
[8])) = QETH_PCI_THRESHOLD_B(card
);
2631 *((unsigned int *) (¶m_field
[12])) = QETH_PCI_TIMER_VALUE(card
);
2634 static void qeth_create_qib_param_field_blkt(struct qeth_card
*card
,
2637 param_field
[16] = _ascebc
['B'];
2638 param_field
[17] = _ascebc
['L'];
2639 param_field
[18] = _ascebc
['K'];
2640 param_field
[19] = _ascebc
['T'];
2641 *((unsigned int *) (¶m_field
[20])) = card
->info
.blkt
.time_total
;
2642 *((unsigned int *) (¶m_field
[24])) = card
->info
.blkt
.inter_packet
;
2643 *((unsigned int *) (¶m_field
[28])) =
2644 card
->info
.blkt
.inter_packet_jumbo
;
2647 static int qeth_qdio_activate(struct qeth_card
*card
)
2649 QETH_DBF_TEXT(SETUP
, 3, "qdioact");
2650 return qdio_activate(CARD_DDEV(card
));
2653 static int qeth_dm_act(struct qeth_card
*card
)
2656 struct qeth_cmd_buffer
*iob
;
2658 QETH_DBF_TEXT(SETUP
, 2, "dmact");
2660 iob
= qeth_wait_for_buffer(&card
->write
);
2661 memcpy(iob
->data
, DM_ACT
, DM_ACT_SIZE
);
2663 memcpy(QETH_DM_ACT_DEST_ADDR(iob
->data
),
2664 &card
->token
.cm_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2665 memcpy(QETH_DM_ACT_CONNECTION_TOKEN(iob
->data
),
2666 &card
->token
.ulp_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2667 rc
= qeth_send_control_data(card
, DM_ACT_SIZE
, iob
, NULL
, NULL
);
2671 static int qeth_mpc_initialize(struct qeth_card
*card
)
2675 QETH_DBF_TEXT(SETUP
, 2, "mpcinit");
2677 rc
= qeth_issue_next_read(card
);
2679 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
2682 rc
= qeth_cm_enable(card
);
2684 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
2687 rc
= qeth_cm_setup(card
);
2689 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
2692 rc
= qeth_ulp_enable(card
);
2694 QETH_DBF_TEXT_(SETUP
, 2, "4err%d", rc
);
2697 rc
= qeth_ulp_setup(card
);
2699 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
2702 rc
= qeth_alloc_qdio_buffers(card
);
2704 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
2707 rc
= qeth_qdio_establish(card
);
2709 QETH_DBF_TEXT_(SETUP
, 2, "6err%d", rc
);
2710 qeth_free_qdio_buffers(card
);
2713 rc
= qeth_qdio_activate(card
);
2715 QETH_DBF_TEXT_(SETUP
, 2, "7err%d", rc
);
2718 rc
= qeth_dm_act(card
);
2720 QETH_DBF_TEXT_(SETUP
, 2, "8err%d", rc
);
2726 qeth_qdio_clear_card(card
, card
->info
.type
!= QETH_CARD_TYPE_IQD
);
2727 qdio_free(CARD_DDEV(card
));
2731 void qeth_print_status_message(struct qeth_card
*card
)
2733 switch (card
->info
.type
) {
2734 case QETH_CARD_TYPE_OSD
:
2735 case QETH_CARD_TYPE_OSM
:
2736 case QETH_CARD_TYPE_OSX
:
2737 /* VM will use a non-zero first character
2738 * to indicate a HiperSockets like reporting
2739 * of the level OSA sets the first character to zero
2741 if (!card
->info
.mcl_level
[0]) {
2742 sprintf(card
->info
.mcl_level
, "%02x%02x",
2743 card
->info
.mcl_level
[2],
2744 card
->info
.mcl_level
[3]);
2748 case QETH_CARD_TYPE_IQD
:
2749 if ((card
->info
.guestlan
) ||
2750 (card
->info
.mcl_level
[0] & 0x80)) {
2751 card
->info
.mcl_level
[0] = (char) _ebcasc
[(__u8
)
2752 card
->info
.mcl_level
[0]];
2753 card
->info
.mcl_level
[1] = (char) _ebcasc
[(__u8
)
2754 card
->info
.mcl_level
[1]];
2755 card
->info
.mcl_level
[2] = (char) _ebcasc
[(__u8
)
2756 card
->info
.mcl_level
[2]];
2757 card
->info
.mcl_level
[3] = (char) _ebcasc
[(__u8
)
2758 card
->info
.mcl_level
[3]];
2759 card
->info
.mcl_level
[QETH_MCL_LENGTH
] = 0;
2763 memset(&card
->info
.mcl_level
[0], 0, QETH_MCL_LENGTH
+ 1);
2765 dev_info(&card
->gdev
->dev
,
2766 "Device is a%s card%s%s%s\nwith link type %s.\n",
2767 qeth_get_cardname(card
),
2768 (card
->info
.mcl_level
[0]) ? " (level: " : "",
2769 (card
->info
.mcl_level
[0]) ? card
->info
.mcl_level
: "",
2770 (card
->info
.mcl_level
[0]) ? ")" : "",
2771 qeth_get_cardname_short(card
));
2773 EXPORT_SYMBOL_GPL(qeth_print_status_message
);
2775 static void qeth_initialize_working_pool_list(struct qeth_card
*card
)
2777 struct qeth_buffer_pool_entry
*entry
;
2779 QETH_CARD_TEXT(card
, 5, "inwrklst");
2781 list_for_each_entry(entry
,
2782 &card
->qdio
.init_pool
.entry_list
, init_list
) {
2783 qeth_put_buffer_pool_entry(card
, entry
);
2787 static struct qeth_buffer_pool_entry
*qeth_find_free_buffer_pool_entry(
2788 struct qeth_card
*card
)
2790 struct list_head
*plh
;
2791 struct qeth_buffer_pool_entry
*entry
;
2795 if (list_empty(&card
->qdio
.in_buf_pool
.entry_list
))
2798 list_for_each(plh
, &card
->qdio
.in_buf_pool
.entry_list
) {
2799 entry
= list_entry(plh
, struct qeth_buffer_pool_entry
, list
);
2801 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(card
); ++i
) {
2802 if (page_count(virt_to_page(entry
->elements
[i
])) > 1) {
2808 list_del_init(&entry
->list
);
2813 /* no free buffer in pool so take first one and swap pages */
2814 entry
= list_entry(card
->qdio
.in_buf_pool
.entry_list
.next
,
2815 struct qeth_buffer_pool_entry
, list
);
2816 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(card
); ++i
) {
2817 if (page_count(virt_to_page(entry
->elements
[i
])) > 1) {
2818 page
= alloc_page(GFP_ATOMIC
);
2822 free_page((unsigned long)entry
->elements
[i
]);
2823 entry
->elements
[i
] = page_address(page
);
2824 if (card
->options
.performance_stats
)
2825 card
->perf_stats
.sg_alloc_page_rx
++;
2829 list_del_init(&entry
->list
);
2833 static int qeth_init_input_buffer(struct qeth_card
*card
,
2834 struct qeth_qdio_buffer
*buf
)
2836 struct qeth_buffer_pool_entry
*pool_entry
;
2839 if ((card
->options
.cq
== QETH_CQ_ENABLED
) && (!buf
->rx_skb
)) {
2840 buf
->rx_skb
= dev_alloc_skb(QETH_RX_PULL_LEN
+ ETH_HLEN
);
2845 pool_entry
= qeth_find_free_buffer_pool_entry(card
);
2850 * since the buffer is accessed only from the input_tasklet
2851 * there shouldn't be a need to synchronize; also, since we use
2852 * the QETH_IN_BUF_REQUEUE_THRESHOLD we should never run out off
2856 buf
->pool_entry
= pool_entry
;
2857 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(card
); ++i
) {
2858 buf
->buffer
->element
[i
].length
= PAGE_SIZE
;
2859 buf
->buffer
->element
[i
].addr
= pool_entry
->elements
[i
];
2860 if (i
== QETH_MAX_BUFFER_ELEMENTS(card
) - 1)
2861 buf
->buffer
->element
[i
].eflags
= SBAL_EFLAGS_LAST_ENTRY
;
2863 buf
->buffer
->element
[i
].eflags
= 0;
2864 buf
->buffer
->element
[i
].sflags
= 0;
2869 int qeth_init_qdio_queues(struct qeth_card
*card
)
2874 QETH_DBF_TEXT(SETUP
, 2, "initqdqs");
2877 qdio_reset_buffers(card
->qdio
.in_q
->qdio_bufs
,
2878 QDIO_MAX_BUFFERS_PER_Q
);
2879 qeth_initialize_working_pool_list(card
);
2880 /*give only as many buffers to hardware as we have buffer pool entries*/
2881 for (i
= 0; i
< card
->qdio
.in_buf_pool
.buf_count
- 1; ++i
)
2882 qeth_init_input_buffer(card
, &card
->qdio
.in_q
->bufs
[i
]);
2883 card
->qdio
.in_q
->next_buf_to_init
=
2884 card
->qdio
.in_buf_pool
.buf_count
- 1;
2885 rc
= do_QDIO(CARD_DDEV(card
), QDIO_FLAG_SYNC_INPUT
, 0, 0,
2886 card
->qdio
.in_buf_pool
.buf_count
- 1);
2888 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
2893 rc
= qeth_cq_init(card
);
2898 /* outbound queue */
2899 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
2900 qdio_reset_buffers(card
->qdio
.out_qs
[i
]->qdio_bufs
,
2901 QDIO_MAX_BUFFERS_PER_Q
);
2902 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
) {
2903 qeth_clear_output_buffer(card
->qdio
.out_qs
[i
],
2904 card
->qdio
.out_qs
[i
]->bufs
[j
],
2905 QETH_QDIO_BUF_EMPTY
);
2907 card
->qdio
.out_qs
[i
]->card
= card
;
2908 card
->qdio
.out_qs
[i
]->next_buf_to_fill
= 0;
2909 card
->qdio
.out_qs
[i
]->do_pack
= 0;
2910 atomic_set(&card
->qdio
.out_qs
[i
]->used_buffers
, 0);
2911 atomic_set(&card
->qdio
.out_qs
[i
]->set_pci_flags_count
, 0);
2912 atomic_set(&card
->qdio
.out_qs
[i
]->state
,
2913 QETH_OUT_Q_UNLOCKED
);
2917 EXPORT_SYMBOL_GPL(qeth_init_qdio_queues
);
2919 static __u8
qeth_get_ipa_adp_type(enum qeth_link_types link_type
)
2921 switch (link_type
) {
2922 case QETH_LINK_TYPE_HSTR
:
2929 static void qeth_fill_ipacmd_header(struct qeth_card
*card
,
2930 struct qeth_ipa_cmd
*cmd
, __u8 command
,
2931 enum qeth_prot_versions prot
)
2933 memset(cmd
, 0, sizeof(struct qeth_ipa_cmd
));
2934 cmd
->hdr
.command
= command
;
2935 cmd
->hdr
.initiator
= IPA_CMD_INITIATOR_HOST
;
2936 cmd
->hdr
.seqno
= card
->seqno
.ipa
;
2937 cmd
->hdr
.adapter_type
= qeth_get_ipa_adp_type(card
->info
.link_type
);
2938 cmd
->hdr
.rel_adapter_no
= (__u8
) card
->info
.portno
;
2939 if (card
->options
.layer2
)
2940 cmd
->hdr
.prim_version_no
= 2;
2942 cmd
->hdr
.prim_version_no
= 1;
2943 cmd
->hdr
.param_count
= 1;
2944 cmd
->hdr
.prot_version
= prot
;
2945 cmd
->hdr
.ipa_supported
= 0;
2946 cmd
->hdr
.ipa_enabled
= 0;
2949 struct qeth_cmd_buffer
*qeth_get_ipacmd_buffer(struct qeth_card
*card
,
2950 enum qeth_ipa_cmds ipacmd
, enum qeth_prot_versions prot
)
2952 struct qeth_cmd_buffer
*iob
;
2953 struct qeth_ipa_cmd
*cmd
;
2955 iob
= qeth_get_buffer(&card
->write
);
2957 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
2958 qeth_fill_ipacmd_header(card
, cmd
, ipacmd
, prot
);
2960 dev_warn(&card
->gdev
->dev
,
2961 "The qeth driver ran out of channel command buffers\n");
2962 QETH_DBF_MESSAGE(1, "%s The qeth driver ran out of channel command buffers",
2963 dev_name(&card
->gdev
->dev
));
2968 EXPORT_SYMBOL_GPL(qeth_get_ipacmd_buffer
);
2970 void qeth_prepare_ipa_cmd(struct qeth_card
*card
, struct qeth_cmd_buffer
*iob
,
2973 memcpy(iob
->data
, IPA_PDU_HEADER
, IPA_PDU_HEADER_SIZE
);
2974 memcpy(QETH_IPA_CMD_PROT_TYPE(iob
->data
), &prot_type
, 1);
2975 memcpy(QETH_IPA_CMD_DEST_ADDR(iob
->data
),
2976 &card
->token
.ulp_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2978 EXPORT_SYMBOL_GPL(qeth_prepare_ipa_cmd
);
2981 * qeth_send_ipa_cmd() - send an IPA command
2983 * See qeth_send_control_data() for explanation of the arguments.
2986 int qeth_send_ipa_cmd(struct qeth_card
*card
, struct qeth_cmd_buffer
*iob
,
2987 int (*reply_cb
)(struct qeth_card
*, struct qeth_reply
*,
2994 QETH_CARD_TEXT(card
, 4, "sendipa");
2996 if (card
->options
.layer2
)
2997 if (card
->info
.type
== QETH_CARD_TYPE_OSN
)
2998 prot_type
= QETH_PROT_OSN2
;
3000 prot_type
= QETH_PROT_LAYER2
;
3002 prot_type
= QETH_PROT_TCPIP
;
3003 qeth_prepare_ipa_cmd(card
, iob
, prot_type
);
3004 rc
= qeth_send_control_data(card
, IPA_CMD_LENGTH
,
3005 iob
, reply_cb
, reply_param
);
3007 qeth_clear_ipacmd_list(card
);
3008 qeth_schedule_recovery(card
);
3012 EXPORT_SYMBOL_GPL(qeth_send_ipa_cmd
);
3014 static int qeth_send_startlan(struct qeth_card
*card
)
3017 struct qeth_cmd_buffer
*iob
;
3019 QETH_DBF_TEXT(SETUP
, 2, "strtlan");
3021 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_STARTLAN
, 0);
3024 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
3028 static int qeth_default_setadapterparms_cb(struct qeth_card
*card
,
3029 struct qeth_reply
*reply
, unsigned long data
)
3031 struct qeth_ipa_cmd
*cmd
;
3033 QETH_CARD_TEXT(card
, 4, "defadpcb");
3035 cmd
= (struct qeth_ipa_cmd
*) data
;
3036 if (cmd
->hdr
.return_code
== 0)
3037 cmd
->hdr
.return_code
=
3038 cmd
->data
.setadapterparms
.hdr
.return_code
;
3042 static int qeth_query_setadapterparms_cb(struct qeth_card
*card
,
3043 struct qeth_reply
*reply
, unsigned long data
)
3045 struct qeth_ipa_cmd
*cmd
;
3047 QETH_CARD_TEXT(card
, 3, "quyadpcb");
3049 cmd
= (struct qeth_ipa_cmd
*) data
;
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
;
3057 return qeth_default_setadapterparms_cb(card
, reply
, (unsigned long)cmd
);
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
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
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
;
3150 struct qeth_switch_info
*sw_info
;
3151 struct qeth_query_switch_attributes
*attrs
;
3153 QETH_CARD_TEXT(card
, 2, "qswiatcb");
3154 cmd
= (struct qeth_ipa_cmd
*) data
;
3155 sw_info
= (struct qeth_switch_info
*)reply
->param
;
3156 if (cmd
->data
.setadapterparms
.hdr
.return_code
== 0) {
3157 attrs
= &cmd
->data
.setadapterparms
.data
.query_switch_attributes
;
3158 sw_info
->capabilities
= attrs
->capabilities
;
3159 sw_info
->settings
= attrs
->settings
;
3160 QETH_CARD_TEXT_(card
, 2, "%04x%04x", sw_info
->capabilities
,
3163 qeth_default_setadapterparms_cb(card
, reply
, (unsigned long) cmd
);
3168 int qeth_query_switch_attributes(struct qeth_card
*card
,
3169 struct qeth_switch_info
*sw_info
)
3171 struct qeth_cmd_buffer
*iob
;
3173 QETH_CARD_TEXT(card
, 2, "qswiattr");
3174 if (!qeth_adp_supported(card
, IPA_SETADP_QUERY_SWITCH_ATTRIBUTES
))
3176 if (!netif_carrier_ok(card
->dev
))
3178 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_QUERY_SWITCH_ATTRIBUTES
,
3179 sizeof(struct qeth_ipacmd_setadpparms_hdr
));
3182 return qeth_send_ipa_cmd(card
, iob
,
3183 qeth_query_switch_attributes_cb
, sw_info
);
3185 EXPORT_SYMBOL_GPL(qeth_query_switch_attributes
);
3187 static int qeth_query_setdiagass_cb(struct qeth_card
*card
,
3188 struct qeth_reply
*reply
, unsigned long data
)
3190 struct qeth_ipa_cmd
*cmd
;
3193 cmd
= (struct qeth_ipa_cmd
*)data
;
3194 rc
= cmd
->hdr
.return_code
;
3196 QETH_CARD_TEXT_(card
, 2, "diagq:%x", rc
);
3198 card
->info
.diagass_support
= cmd
->data
.diagass
.ext
;
3202 static int qeth_query_setdiagass(struct qeth_card
*card
)
3204 struct qeth_cmd_buffer
*iob
;
3205 struct qeth_ipa_cmd
*cmd
;
3207 QETH_DBF_TEXT(SETUP
, 2, "qdiagass");
3208 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SET_DIAG_ASS
, 0);
3211 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
3212 cmd
->data
.diagass
.subcmd_len
= 16;
3213 cmd
->data
.diagass
.subcmd
= QETH_DIAGS_CMD_QUERY
;
3214 return qeth_send_ipa_cmd(card
, iob
, qeth_query_setdiagass_cb
, NULL
);
3217 static void qeth_get_trap_id(struct qeth_card
*card
, struct qeth_trap_id
*tid
)
3219 unsigned long info
= get_zeroed_page(GFP_KERNEL
);
3220 struct sysinfo_2_2_2
*info222
= (struct sysinfo_2_2_2
*)info
;
3221 struct sysinfo_3_2_2
*info322
= (struct sysinfo_3_2_2
*)info
;
3222 struct ccw_dev_id ccwid
;
3225 tid
->chpid
= card
->info
.chpid
;
3226 ccw_device_get_id(CARD_RDEV(card
), &ccwid
);
3227 tid
->ssid
= ccwid
.ssid
;
3228 tid
->devno
= ccwid
.devno
;
3231 level
= stsi(NULL
, 0, 0, 0);
3232 if ((level
>= 2) && (stsi(info222
, 2, 2, 2) == 0))
3233 tid
->lparnr
= info222
->lpar_number
;
3234 if ((level
>= 3) && (stsi(info322
, 3, 2, 2) == 0)) {
3235 EBCASC(info322
->vm
[0].name
, sizeof(info322
->vm
[0].name
));
3236 memcpy(tid
->vmname
, info322
->vm
[0].name
, sizeof(tid
->vmname
));
3242 static int qeth_hw_trap_cb(struct qeth_card
*card
,
3243 struct qeth_reply
*reply
, unsigned long data
)
3245 struct qeth_ipa_cmd
*cmd
;
3248 cmd
= (struct qeth_ipa_cmd
*)data
;
3249 rc
= cmd
->hdr
.return_code
;
3251 QETH_CARD_TEXT_(card
, 2, "trapc:%x", rc
);
3255 int qeth_hw_trap(struct qeth_card
*card
, enum qeth_diags_trap_action action
)
3257 struct qeth_cmd_buffer
*iob
;
3258 struct qeth_ipa_cmd
*cmd
;
3260 QETH_DBF_TEXT(SETUP
, 2, "diagtrap");
3261 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SET_DIAG_ASS
, 0);
3264 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
3265 cmd
->data
.diagass
.subcmd_len
= 80;
3266 cmd
->data
.diagass
.subcmd
= QETH_DIAGS_CMD_TRAP
;
3267 cmd
->data
.diagass
.type
= 1;
3268 cmd
->data
.diagass
.action
= action
;
3270 case QETH_DIAGS_TRAP_ARM
:
3271 cmd
->data
.diagass
.options
= 0x0003;
3272 cmd
->data
.diagass
.ext
= 0x00010000 +
3273 sizeof(struct qeth_trap_id
);
3274 qeth_get_trap_id(card
,
3275 (struct qeth_trap_id
*)cmd
->data
.diagass
.cdata
);
3277 case QETH_DIAGS_TRAP_DISARM
:
3278 cmd
->data
.diagass
.options
= 0x0001;
3280 case QETH_DIAGS_TRAP_CAPTURE
:
3283 return qeth_send_ipa_cmd(card
, iob
, qeth_hw_trap_cb
, NULL
);
3285 EXPORT_SYMBOL_GPL(qeth_hw_trap
);
3287 static int qeth_check_qdio_errors(struct qeth_card
*card
,
3288 struct qdio_buffer
*buf
,
3289 unsigned int qdio_error
,
3290 const char *dbftext
)
3293 QETH_CARD_TEXT(card
, 2, dbftext
);
3294 QETH_CARD_TEXT_(card
, 2, " F15=%02X",
3295 buf
->element
[15].sflags
);
3296 QETH_CARD_TEXT_(card
, 2, " F14=%02X",
3297 buf
->element
[14].sflags
);
3298 QETH_CARD_TEXT_(card
, 2, " qerr=%X", qdio_error
);
3299 if ((buf
->element
[15].sflags
) == 0x12) {
3300 card
->stats
.rx_dropped
++;
3308 static void qeth_queue_input_buffer(struct qeth_card
*card
, int index
)
3310 struct qeth_qdio_q
*queue
= card
->qdio
.in_q
;
3311 struct list_head
*lh
;
3317 count
= (index
< queue
->next_buf_to_init
)?
3318 card
->qdio
.in_buf_pool
.buf_count
-
3319 (queue
->next_buf_to_init
- index
) :
3320 card
->qdio
.in_buf_pool
.buf_count
-
3321 (queue
->next_buf_to_init
+ QDIO_MAX_BUFFERS_PER_Q
- index
);
3322 /* only requeue at a certain threshold to avoid SIGAs */
3323 if (count
>= QETH_IN_BUF_REQUEUE_THRESHOLD(card
)) {
3324 for (i
= queue
->next_buf_to_init
;
3325 i
< queue
->next_buf_to_init
+ count
; ++i
) {
3326 if (qeth_init_input_buffer(card
,
3327 &queue
->bufs
[i
% QDIO_MAX_BUFFERS_PER_Q
])) {
3334 if (newcount
< count
) {
3335 /* we are in memory shortage so we switch back to
3336 traditional skb allocation and drop packages */
3337 atomic_set(&card
->force_alloc_skb
, 3);
3340 atomic_add_unless(&card
->force_alloc_skb
, -1, 0);
3345 list_for_each(lh
, &card
->qdio
.in_buf_pool
.entry_list
)
3347 if (i
== card
->qdio
.in_buf_pool
.buf_count
) {
3348 QETH_CARD_TEXT(card
, 2, "qsarbw");
3349 card
->reclaim_index
= index
;
3350 schedule_delayed_work(
3351 &card
->buffer_reclaim_work
,
3352 QETH_RECLAIM_WORK_TIME
);
3358 * according to old code it should be avoided to requeue all
3359 * 128 buffers in order to benefit from PCI avoidance.
3360 * this function keeps at least one buffer (the buffer at
3361 * 'index') un-requeued -> this buffer is the first buffer that
3362 * will be requeued the next time
3364 if (card
->options
.performance_stats
) {
3365 card
->perf_stats
.inbound_do_qdio_cnt
++;
3366 card
->perf_stats
.inbound_do_qdio_start_time
=
3369 rc
= do_QDIO(CARD_DDEV(card
), QDIO_FLAG_SYNC_INPUT
, 0,
3370 queue
->next_buf_to_init
, count
);
3371 if (card
->options
.performance_stats
)
3372 card
->perf_stats
.inbound_do_qdio_time
+=
3374 card
->perf_stats
.inbound_do_qdio_start_time
;
3376 QETH_CARD_TEXT(card
, 2, "qinberr");
3378 queue
->next_buf_to_init
= (queue
->next_buf_to_init
+ count
) %
3379 QDIO_MAX_BUFFERS_PER_Q
;
3383 static void qeth_buffer_reclaim_work(struct work_struct
*work
)
3385 struct qeth_card
*card
= container_of(work
, struct qeth_card
,
3386 buffer_reclaim_work
.work
);
3388 QETH_CARD_TEXT_(card
, 2, "brw:%x", card
->reclaim_index
);
3389 qeth_queue_input_buffer(card
, card
->reclaim_index
);
3392 static void qeth_handle_send_error(struct qeth_card
*card
,
3393 struct qeth_qdio_out_buffer
*buffer
, unsigned int qdio_err
)
3395 int sbalf15
= buffer
->buffer
->element
[15].sflags
;
3397 QETH_CARD_TEXT(card
, 6, "hdsnderr");
3398 if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
3405 qeth_check_qdio_errors(card
, buffer
->buffer
, qdio_err
, "qouterr");
3410 if ((sbalf15
>= 15) && (sbalf15
<= 31))
3413 QETH_CARD_TEXT(card
, 1, "lnkfail");
3414 QETH_CARD_TEXT_(card
, 1, "%04x %02x",
3415 (u16
)qdio_err
, (u8
)sbalf15
);
3419 * qeth_prep_flush_pack_buffer - Prepares flushing of a packing buffer.
3420 * @queue: queue to check for packing buffer
3422 * Returns number of buffers that were prepared for flush.
3424 static int qeth_prep_flush_pack_buffer(struct qeth_qdio_out_q
*queue
)
3426 struct qeth_qdio_out_buffer
*buffer
;
3428 buffer
= queue
->bufs
[queue
->next_buf_to_fill
];
3429 if ((atomic_read(&buffer
->state
) == QETH_QDIO_BUF_EMPTY
) &&
3430 (buffer
->next_element_to_fill
> 0)) {
3431 /* it's a packing buffer */
3432 atomic_set(&buffer
->state
, QETH_QDIO_BUF_PRIMED
);
3433 queue
->next_buf_to_fill
=
3434 (queue
->next_buf_to_fill
+ 1) % QDIO_MAX_BUFFERS_PER_Q
;
3441 * Switched to packing state if the number of used buffers on a queue
3442 * reaches a certain limit.
3444 static void qeth_switch_to_packing_if_needed(struct qeth_qdio_out_q
*queue
)
3446 if (!queue
->do_pack
) {
3447 if (atomic_read(&queue
->used_buffers
)
3448 >= QETH_HIGH_WATERMARK_PACK
){
3449 /* switch non-PACKING -> PACKING */
3450 QETH_CARD_TEXT(queue
->card
, 6, "np->pack");
3451 if (queue
->card
->options
.performance_stats
)
3452 queue
->card
->perf_stats
.sc_dp_p
++;
3459 * Switches from packing to non-packing mode. If there is a packing
3460 * buffer on the queue this buffer will be prepared to be flushed.
3461 * In that case 1 is returned to inform the caller. If no buffer
3462 * has to be flushed, zero is returned.
3464 static int qeth_switch_to_nonpacking_if_needed(struct qeth_qdio_out_q
*queue
)
3466 if (queue
->do_pack
) {
3467 if (atomic_read(&queue
->used_buffers
)
3468 <= QETH_LOW_WATERMARK_PACK
) {
3469 /* switch PACKING -> non-PACKING */
3470 QETH_CARD_TEXT(queue
->card
, 6, "pack->np");
3471 if (queue
->card
->options
.performance_stats
)
3472 queue
->card
->perf_stats
.sc_p_dp
++;
3474 return qeth_prep_flush_pack_buffer(queue
);
3480 static void qeth_flush_buffers(struct qeth_qdio_out_q
*queue
, int index
,
3483 struct qeth_qdio_out_buffer
*buf
;
3486 unsigned int qdio_flags
;
3488 for (i
= index
; i
< index
+ count
; ++i
) {
3489 int bidx
= i
% QDIO_MAX_BUFFERS_PER_Q
;
3490 buf
= queue
->bufs
[bidx
];
3491 buf
->buffer
->element
[buf
->next_element_to_fill
- 1].eflags
|=
3492 SBAL_EFLAGS_LAST_ENTRY
;
3494 if (queue
->bufstates
)
3495 queue
->bufstates
[bidx
].user
= buf
;
3497 if (queue
->card
->info
.type
== QETH_CARD_TYPE_IQD
)
3500 if (!queue
->do_pack
) {
3501 if ((atomic_read(&queue
->used_buffers
) >=
3502 (QETH_HIGH_WATERMARK_PACK
-
3503 QETH_WATERMARK_PACK_FUZZ
)) &&
3504 !atomic_read(&queue
->set_pci_flags_count
)) {
3505 /* it's likely that we'll go to packing
3507 atomic_inc(&queue
->set_pci_flags_count
);
3508 buf
->buffer
->element
[0].sflags
|= SBAL_SFLAGS0_PCI_REQ
;
3511 if (!atomic_read(&queue
->set_pci_flags_count
)) {
3513 * there's no outstanding PCI any more, so we
3514 * have to request a PCI to be sure the the PCI
3515 * will wake at some time in the future then we
3516 * can flush packed buffers that might still be
3517 * hanging around, which can happen if no
3518 * further send was requested by the stack
3520 atomic_inc(&queue
->set_pci_flags_count
);
3521 buf
->buffer
->element
[0].sflags
|= SBAL_SFLAGS0_PCI_REQ
;
3526 netif_trans_update(queue
->card
->dev
);
3527 if (queue
->card
->options
.performance_stats
) {
3528 queue
->card
->perf_stats
.outbound_do_qdio_cnt
++;
3529 queue
->card
->perf_stats
.outbound_do_qdio_start_time
=
3532 qdio_flags
= QDIO_FLAG_SYNC_OUTPUT
;
3533 if (atomic_read(&queue
->set_pci_flags_count
))
3534 qdio_flags
|= QDIO_FLAG_PCI_OUT
;
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
;
3541 atomic_add(count
, &queue
->used_buffers
);
3543 queue
->card
->stats
.tx_errors
+= count
;
3544 /* ignore temporary SIGA errors without busy condition */
3547 QETH_CARD_TEXT(queue
->card
, 2, "flushbuf");
3548 QETH_CARD_TEXT_(queue
->card
, 2, " q%d", queue
->queue_no
);
3549 QETH_CARD_TEXT_(queue
->card
, 2, " idx%d", index
);
3550 QETH_CARD_TEXT_(queue
->card
, 2, " c%d", count
);
3551 QETH_CARD_TEXT_(queue
->card
, 2, " err%d", rc
);
3553 /* this must not happen under normal circumstances. if it
3554 * happens something is really wrong -> recover */
3555 qeth_schedule_recovery(queue
->card
);
3558 if (queue
->card
->options
.performance_stats
)
3559 queue
->card
->perf_stats
.bufs_sent
+= count
;
3562 static void qeth_check_outbound_queue(struct qeth_qdio_out_q
*queue
)
3566 int q_was_packing
= 0;
3569 * check if weed have to switch to non-packing mode or if
3570 * we have to get a pci flag out on the queue
3572 if ((atomic_read(&queue
->used_buffers
) <= QETH_LOW_WATERMARK_PACK
) ||
3573 !atomic_read(&queue
->set_pci_flags_count
)) {
3574 if (atomic_xchg(&queue
->state
, QETH_OUT_Q_LOCKED_FLUSH
) ==
3575 QETH_OUT_Q_UNLOCKED
) {
3577 * If we get in here, there was no action in
3578 * do_send_packet. So, we check if there is a
3579 * packing buffer to be flushed here.
3581 netif_stop_queue(queue
->card
->dev
);
3582 index
= queue
->next_buf_to_fill
;
3583 q_was_packing
= queue
->do_pack
;
3584 /* queue->do_pack may change */
3586 flush_cnt
+= qeth_switch_to_nonpacking_if_needed(queue
);
3588 !atomic_read(&queue
->set_pci_flags_count
))
3589 flush_cnt
+= qeth_prep_flush_pack_buffer(queue
);
3590 if (queue
->card
->options
.performance_stats
&&
3592 queue
->card
->perf_stats
.bufs_sent_pack
+=
3595 qeth_flush_buffers(queue
, index
, flush_cnt
);
3596 atomic_set(&queue
->state
, QETH_OUT_Q_UNLOCKED
);
3601 void qeth_qdio_start_poll(struct ccw_device
*ccwdev
, int queue
,
3602 unsigned long card_ptr
)
3604 struct qeth_card
*card
= (struct qeth_card
*)card_ptr
;
3606 if (card
->dev
&& (card
->dev
->flags
& IFF_UP
))
3607 napi_schedule(&card
->napi
);
3609 EXPORT_SYMBOL_GPL(qeth_qdio_start_poll
);
3611 int qeth_configure_cq(struct qeth_card
*card
, enum qeth_cq cq
)
3615 if (card
->options
.cq
== QETH_CQ_NOTAVAILABLE
) {
3619 if (card
->options
.cq
== cq
) {
3624 if (card
->state
!= CARD_STATE_DOWN
&&
3625 card
->state
!= CARD_STATE_RECOVER
) {
3630 qeth_free_qdio_buffers(card
);
3631 card
->options
.cq
= cq
;
3638 EXPORT_SYMBOL_GPL(qeth_configure_cq
);
3641 static void qeth_qdio_cq_handler(struct qeth_card
*card
,
3642 unsigned int qdio_err
,
3643 unsigned int queue
, int first_element
, int count
) {
3644 struct qeth_qdio_q
*cq
= card
->qdio
.c_q
;
3648 if (!qeth_is_cq(card
, queue
))
3651 QETH_CARD_TEXT_(card
, 5, "qcqhe%d", first_element
);
3652 QETH_CARD_TEXT_(card
, 5, "qcqhc%d", count
);
3653 QETH_CARD_TEXT_(card
, 5, "qcqherr%d", qdio_err
);
3656 netif_stop_queue(card
->dev
);
3657 qeth_schedule_recovery(card
);
3661 if (card
->options
.performance_stats
) {
3662 card
->perf_stats
.cq_cnt
++;
3663 card
->perf_stats
.cq_start_time
= qeth_get_micros();
3666 for (i
= first_element
; i
< first_element
+ count
; ++i
) {
3667 int bidx
= i
% QDIO_MAX_BUFFERS_PER_Q
;
3668 struct qdio_buffer
*buffer
= cq
->qdio_bufs
[bidx
];
3672 while ((e
< QDIO_MAX_ELEMENTS_PER_BUFFER
) &&
3673 buffer
->element
[e
].addr
) {
3674 unsigned long phys_aob_addr
;
3676 phys_aob_addr
= (unsigned long) buffer
->element
[e
].addr
;
3677 qeth_qdio_handle_aob(card
, phys_aob_addr
);
3678 buffer
->element
[e
].addr
= NULL
;
3679 buffer
->element
[e
].eflags
= 0;
3680 buffer
->element
[e
].sflags
= 0;
3681 buffer
->element
[e
].length
= 0;
3686 buffer
->element
[15].eflags
= 0;
3687 buffer
->element
[15].sflags
= 0;
3689 rc
= do_QDIO(CARD_DDEV(card
), QDIO_FLAG_SYNC_INPUT
, queue
,
3690 card
->qdio
.c_q
->next_buf_to_init
,
3693 dev_warn(&card
->gdev
->dev
,
3694 "QDIO reported an error, rc=%i\n", rc
);
3695 QETH_CARD_TEXT(card
, 2, "qcqherr");
3697 card
->qdio
.c_q
->next_buf_to_init
= (card
->qdio
.c_q
->next_buf_to_init
3698 + count
) % QDIO_MAX_BUFFERS_PER_Q
;
3700 netif_wake_queue(card
->dev
);
3702 if (card
->options
.performance_stats
) {
3703 int delta_t
= qeth_get_micros();
3704 delta_t
-= card
->perf_stats
.cq_start_time
;
3705 card
->perf_stats
.cq_time
+= delta_t
;
3711 void qeth_qdio_input_handler(struct ccw_device
*ccwdev
, unsigned int qdio_err
,
3712 unsigned int queue
, int first_elem
, int count
,
3713 unsigned long card_ptr
)
3715 struct qeth_card
*card
= (struct qeth_card
*)card_ptr
;
3717 QETH_CARD_TEXT_(card
, 2, "qihq%d", queue
);
3718 QETH_CARD_TEXT_(card
, 2, "qiec%d", qdio_err
);
3720 if (qeth_is_cq(card
, queue
))
3721 qeth_qdio_cq_handler(card
, qdio_err
, queue
, first_elem
, count
);
3723 qeth_schedule_recovery(card
);
3727 EXPORT_SYMBOL_GPL(qeth_qdio_input_handler
);
3729 void qeth_qdio_output_handler(struct ccw_device
*ccwdev
,
3730 unsigned int qdio_error
, int __queue
, int first_element
,
3731 int count
, unsigned long card_ptr
)
3733 struct qeth_card
*card
= (struct qeth_card
*) card_ptr
;
3734 struct qeth_qdio_out_q
*queue
= card
->qdio
.out_qs
[__queue
];
3735 struct qeth_qdio_out_buffer
*buffer
;
3738 QETH_CARD_TEXT(card
, 6, "qdouhdl");
3739 if (qdio_error
& QDIO_ERROR_FATAL
) {
3740 QETH_CARD_TEXT(card
, 2, "achkcond");
3741 netif_stop_queue(card
->dev
);
3742 qeth_schedule_recovery(card
);
3745 if (card
->options
.performance_stats
) {
3746 card
->perf_stats
.outbound_handler_cnt
++;
3747 card
->perf_stats
.outbound_handler_start_time
=
3750 for (i
= first_element
; i
< (first_element
+ count
); ++i
) {
3751 int bidx
= i
% QDIO_MAX_BUFFERS_PER_Q
;
3752 buffer
= queue
->bufs
[bidx
];
3753 qeth_handle_send_error(card
, buffer
, qdio_error
);
3755 if (queue
->bufstates
&&
3756 (queue
->bufstates
[bidx
].flags
&
3757 QDIO_OUTBUF_STATE_FLAG_PENDING
) != 0) {
3758 WARN_ON_ONCE(card
->options
.cq
!= QETH_CQ_ENABLED
);
3760 if (atomic_cmpxchg(&buffer
->state
,
3761 QETH_QDIO_BUF_PRIMED
,
3762 QETH_QDIO_BUF_PENDING
) ==
3763 QETH_QDIO_BUF_PRIMED
) {
3764 qeth_notify_skbs(queue
, buffer
,
3767 buffer
->aob
= queue
->bufstates
[bidx
].aob
;
3768 QETH_CARD_TEXT_(queue
->card
, 5, "pel%d", bidx
);
3769 QETH_CARD_TEXT(queue
->card
, 5, "aob");
3770 QETH_CARD_TEXT_(queue
->card
, 5, "%lx",
3771 virt_to_phys(buffer
->aob
));
3772 if (qeth_init_qdio_out_buf(queue
, bidx
)) {
3773 QETH_CARD_TEXT(card
, 2, "outofbuf");
3774 qeth_schedule_recovery(card
);
3777 if (card
->options
.cq
== QETH_CQ_ENABLED
) {
3778 enum iucv_tx_notify n
;
3780 n
= qeth_compute_cq_notification(
3781 buffer
->buffer
->element
[15].sflags
, 0);
3782 qeth_notify_skbs(queue
, buffer
, n
);
3785 qeth_clear_output_buffer(queue
, buffer
,
3786 QETH_QDIO_BUF_EMPTY
);
3788 qeth_cleanup_handled_pending(queue
, bidx
, 0);
3790 atomic_sub(count
, &queue
->used_buffers
);
3791 /* check if we need to do something on this outbound queue */
3792 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
)
3793 qeth_check_outbound_queue(queue
);
3795 netif_wake_queue(queue
->card
->dev
);
3796 if (card
->options
.performance_stats
)
3797 card
->perf_stats
.outbound_handler_time
+= qeth_get_micros() -
3798 card
->perf_stats
.outbound_handler_start_time
;
3800 EXPORT_SYMBOL_GPL(qeth_qdio_output_handler
);
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 int elements
= qeth_get_elements_for_range(
3902 (addr_t
)skb
->data
+ data_offset
,
3903 (addr_t
)skb
->data
+ skb_headlen(skb
)) +
3904 qeth_get_elements_for_frags(skb
);
3906 if ((elements
+ extra_elems
) > QETH_MAX_BUFFER_ELEMENTS(card
)) {
3907 QETH_DBF_MESSAGE(2, "Invalid size of IP packet "
3908 "(Number=%d / Length=%d). Discarded.\n",
3909 elements
+ extra_elems
, skb
->len
);
3914 EXPORT_SYMBOL_GPL(qeth_get_elements_no
);
3916 int qeth_hdr_chk_and_bounce(struct sk_buff
*skb
, struct qeth_hdr
**hdr
, int len
)
3918 int hroom
, inpage
, rest
;
3920 if (((unsigned long)skb
->data
& PAGE_MASK
) !=
3921 (((unsigned long)skb
->data
+ len
- 1) & PAGE_MASK
)) {
3922 hroom
= skb_headroom(skb
);
3923 inpage
= PAGE_SIZE
- ((unsigned long) skb
->data
% PAGE_SIZE
);
3924 rest
= len
- inpage
;
3927 memmove(skb
->data
- rest
, skb
->data
, skb_headlen(skb
));
3930 *hdr
= (struct qeth_hdr
*)skb
->data
;
3931 QETH_DBF_MESSAGE(2, "skb bounce len: %d rest: %d\n", len
, rest
);
3935 EXPORT_SYMBOL_GPL(qeth_hdr_chk_and_bounce
);
3938 * qeth_push_hdr() - push a qeth_hdr onto an skb.
3939 * @skb: skb that the qeth_hdr should be pushed onto.
3940 * @hdr: double pointer to a qeth_hdr. When returning with >= 0,
3941 * it contains a valid pointer to a qeth_hdr.
3942 * @len: length of the hdr that needs to be pushed on.
3944 * Returns the pushed length. If the header can't be pushed on
3945 * (eg. because it would cross a page boundary), it is allocated from
3946 * the cache instead and 0 is returned.
3947 * Error to create the hdr is indicated by returning with < 0.
3949 int qeth_push_hdr(struct sk_buff
*skb
, struct qeth_hdr
**hdr
, unsigned int len
)
3951 if (skb_headroom(skb
) >= len
&&
3952 qeth_get_elements_for_range((addr_t
)skb
->data
- len
,
3953 (addr_t
)skb
->data
) == 1) {
3954 *hdr
= skb_push(skb
, len
);
3958 *hdr
= kmem_cache_alloc(qeth_core_header_cache
, GFP_ATOMIC
);
3963 EXPORT_SYMBOL_GPL(qeth_push_hdr
);
3965 static void __qeth_fill_buffer(struct sk_buff
*skb
,
3966 struct qeth_qdio_out_buffer
*buf
,
3967 bool is_first_elem
, unsigned int offset
)
3969 struct qdio_buffer
*buffer
= buf
->buffer
;
3970 int element
= buf
->next_element_to_fill
;
3971 int length
= skb_headlen(skb
) - offset
;
3972 char *data
= skb
->data
+ offset
;
3973 int length_here
, cnt
;
3975 /* map linear part into buffer element(s) */
3976 while (length
> 0) {
3977 /* length_here is the remaining amount of data in this page */
3978 length_here
= PAGE_SIZE
- ((unsigned long) data
% PAGE_SIZE
);
3979 if (length
< length_here
)
3980 length_here
= length
;
3982 buffer
->element
[element
].addr
= data
;
3983 buffer
->element
[element
].length
= length_here
;
3984 length
-= length_here
;
3985 if (is_first_elem
) {
3986 is_first_elem
= false;
3987 if (length
|| skb_is_nonlinear(skb
))
3988 /* skb needs additional elements */
3989 buffer
->element
[element
].eflags
=
3990 SBAL_EFLAGS_FIRST_FRAG
;
3992 buffer
->element
[element
].eflags
= 0;
3994 buffer
->element
[element
].eflags
=
3995 SBAL_EFLAGS_MIDDLE_FRAG
;
3997 data
+= length_here
;
4001 /* map page frags into buffer element(s) */
4002 for (cnt
= 0; cnt
< skb_shinfo(skb
)->nr_frags
; cnt
++) {
4003 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[cnt
];
4005 data
= skb_frag_address(frag
);
4006 length
= skb_frag_size(frag
);
4007 while (length
> 0) {
4008 length_here
= PAGE_SIZE
-
4009 ((unsigned long) data
% PAGE_SIZE
);
4010 if (length
< length_here
)
4011 length_here
= length
;
4013 buffer
->element
[element
].addr
= data
;
4014 buffer
->element
[element
].length
= length_here
;
4015 buffer
->element
[element
].eflags
=
4016 SBAL_EFLAGS_MIDDLE_FRAG
;
4017 length
-= length_here
;
4018 data
+= length_here
;
4023 if (buffer
->element
[element
- 1].eflags
)
4024 buffer
->element
[element
- 1].eflags
= SBAL_EFLAGS_LAST_FRAG
;
4025 buf
->next_element_to_fill
= element
;
4029 * qeth_fill_buffer() - map skb into an output buffer
4030 * @queue: QDIO queue to submit the buffer on
4031 * @buf: buffer to transport the skb
4032 * @skb: skb to map into the buffer
4033 * @hdr: qeth_hdr for this skb. Either at skb->data, or allocated
4034 * from qeth_core_header_cache.
4035 * @offset: when mapping the skb, start at skb->data + offset
4036 * @hd_len: if > 0, build a dedicated header element of this size
4038 static int qeth_fill_buffer(struct qeth_qdio_out_q
*queue
,
4039 struct qeth_qdio_out_buffer
*buf
,
4040 struct sk_buff
*skb
, struct qeth_hdr
*hdr
,
4041 unsigned int offset
, unsigned int hd_len
)
4043 struct qdio_buffer
*buffer
= buf
->buffer
;
4044 bool is_first_elem
= true;
4047 refcount_inc(&skb
->users
);
4048 skb_queue_tail(&buf
->skb_list
, skb
);
4050 /* build dedicated header element */
4052 int element
= buf
->next_element_to_fill
;
4053 is_first_elem
= false;
4055 buffer
->element
[element
].addr
= hdr
;
4056 buffer
->element
[element
].length
= hd_len
;
4057 buffer
->element
[element
].eflags
= SBAL_EFLAGS_FIRST_FRAG
;
4058 /* remember to free cache-allocated qeth_hdr: */
4059 buf
->is_header
[element
] = ((void *)hdr
!= skb
->data
);
4060 buf
->next_element_to_fill
++;
4063 __qeth_fill_buffer(skb
, buf
, is_first_elem
, offset
);
4065 if (!queue
->do_pack
) {
4066 QETH_CARD_TEXT(queue
->card
, 6, "fillbfnp");
4067 /* set state to PRIMED -> will be flushed */
4068 atomic_set(&buf
->state
, QETH_QDIO_BUF_PRIMED
);
4071 QETH_CARD_TEXT(queue
->card
, 6, "fillbfpa");
4072 if (queue
->card
->options
.performance_stats
)
4073 queue
->card
->perf_stats
.skbs_sent_pack
++;
4074 if (buf
->next_element_to_fill
>=
4075 QETH_MAX_BUFFER_ELEMENTS(queue
->card
)) {
4077 * packed buffer if full -> set state PRIMED
4078 * -> will be flushed
4080 atomic_set(&buf
->state
, QETH_QDIO_BUF_PRIMED
);
4087 int qeth_do_send_packet_fast(struct qeth_qdio_out_q
*queue
, struct sk_buff
*skb
,
4088 struct qeth_hdr
*hdr
, unsigned int offset
,
4089 unsigned int hd_len
)
4091 int index
= queue
->next_buf_to_fill
;
4092 struct qeth_qdio_out_buffer
*buffer
= queue
->bufs
[index
];
4095 * check if buffer is empty to make sure that we do not 'overtake'
4096 * ourselves and try to fill a buffer that is already primed
4098 if (atomic_read(&buffer
->state
) != QETH_QDIO_BUF_EMPTY
)
4100 queue
->next_buf_to_fill
= (index
+ 1) % QDIO_MAX_BUFFERS_PER_Q
;
4101 qeth_fill_buffer(queue
, buffer
, skb
, hdr
, offset
, hd_len
);
4102 qeth_flush_buffers(queue
, index
, 1);
4105 EXPORT_SYMBOL_GPL(qeth_do_send_packet_fast
);
4107 int qeth_do_send_packet(struct qeth_card
*card
, struct qeth_qdio_out_q
*queue
,
4108 struct sk_buff
*skb
, struct qeth_hdr
*hdr
,
4109 unsigned int offset
, unsigned int hd_len
,
4110 int elements_needed
)
4112 struct qeth_qdio_out_buffer
*buffer
;
4114 int flush_count
= 0;
4119 /* spin until we get the queue ... */
4120 while (atomic_cmpxchg(&queue
->state
, QETH_OUT_Q_UNLOCKED
,
4121 QETH_OUT_Q_LOCKED
) != QETH_OUT_Q_UNLOCKED
);
4122 start_index
= queue
->next_buf_to_fill
;
4123 buffer
= queue
->bufs
[queue
->next_buf_to_fill
];
4125 * check if buffer is empty to make sure that we do not 'overtake'
4126 * ourselves and try to fill a buffer that is already primed
4128 if (atomic_read(&buffer
->state
) != QETH_QDIO_BUF_EMPTY
) {
4129 atomic_set(&queue
->state
, QETH_OUT_Q_UNLOCKED
);
4132 /* check if we need to switch packing state of this queue */
4133 qeth_switch_to_packing_if_needed(queue
);
4134 if (queue
->do_pack
) {
4136 /* does packet fit in current buffer? */
4137 if ((QETH_MAX_BUFFER_ELEMENTS(card
) -
4138 buffer
->next_element_to_fill
) < elements_needed
) {
4139 /* ... no -> set state PRIMED */
4140 atomic_set(&buffer
->state
, QETH_QDIO_BUF_PRIMED
);
4142 queue
->next_buf_to_fill
=
4143 (queue
->next_buf_to_fill
+ 1) %
4144 QDIO_MAX_BUFFERS_PER_Q
;
4145 buffer
= queue
->bufs
[queue
->next_buf_to_fill
];
4146 /* we did a step forward, so check buffer state
4148 if (atomic_read(&buffer
->state
) !=
4149 QETH_QDIO_BUF_EMPTY
) {
4150 qeth_flush_buffers(queue
, start_index
,
4152 atomic_set(&queue
->state
,
4153 QETH_OUT_Q_UNLOCKED
);
4159 tmp
= qeth_fill_buffer(queue
, buffer
, skb
, hdr
, offset
, hd_len
);
4160 queue
->next_buf_to_fill
= (queue
->next_buf_to_fill
+ tmp
) %
4161 QDIO_MAX_BUFFERS_PER_Q
;
4164 qeth_flush_buffers(queue
, start_index
, flush_count
);
4165 else if (!atomic_read(&queue
->set_pci_flags_count
))
4166 atomic_xchg(&queue
->state
, QETH_OUT_Q_LOCKED_FLUSH
);
4168 * queue->state will go from LOCKED -> UNLOCKED or from
4169 * LOCKED_FLUSH -> LOCKED if output_handler wanted to 'notify' us
4170 * (switch packing state or flush buffer to get another pci flag out).
4171 * In that case we will enter this loop
4173 while (atomic_dec_return(&queue
->state
)) {
4174 start_index
= queue
->next_buf_to_fill
;
4175 /* check if we can go back to non-packing state */
4176 tmp
= qeth_switch_to_nonpacking_if_needed(queue
);
4178 * check if we need to flush a packing buffer to get a pci
4179 * flag out on the queue
4181 if (!tmp
&& !atomic_read(&queue
->set_pci_flags_count
))
4182 tmp
= qeth_prep_flush_pack_buffer(queue
);
4184 qeth_flush_buffers(queue
, start_index
, tmp
);
4189 /* at this point the queue is UNLOCKED again */
4190 if (queue
->card
->options
.performance_stats
&& do_pack
)
4191 queue
->card
->perf_stats
.bufs_sent_pack
+= flush_count
;
4195 EXPORT_SYMBOL_GPL(qeth_do_send_packet
);
4197 static int qeth_setadp_promisc_mode_cb(struct qeth_card
*card
,
4198 struct qeth_reply
*reply
, unsigned long data
)
4200 struct qeth_ipa_cmd
*cmd
;
4201 struct qeth_ipacmd_setadpparms
*setparms
;
4203 QETH_CARD_TEXT(card
, 4, "prmadpcb");
4205 cmd
= (struct qeth_ipa_cmd
*) data
;
4206 setparms
= &(cmd
->data
.setadapterparms
);
4208 qeth_default_setadapterparms_cb(card
, reply
, (unsigned long)cmd
);
4209 if (cmd
->hdr
.return_code
) {
4210 QETH_CARD_TEXT_(card
, 4, "prmrc%x", cmd
->hdr
.return_code
);
4211 setparms
->data
.mode
= SET_PROMISC_MODE_OFF
;
4213 card
->info
.promisc_mode
= setparms
->data
.mode
;
4217 void qeth_setadp_promisc_mode(struct qeth_card
*card
)
4219 enum qeth_ipa_promisc_modes mode
;
4220 struct net_device
*dev
= card
->dev
;
4221 struct qeth_cmd_buffer
*iob
;
4222 struct qeth_ipa_cmd
*cmd
;
4224 QETH_CARD_TEXT(card
, 4, "setprom");
4226 if (((dev
->flags
& IFF_PROMISC
) &&
4227 (card
->info
.promisc_mode
== SET_PROMISC_MODE_ON
)) ||
4228 (!(dev
->flags
& IFF_PROMISC
) &&
4229 (card
->info
.promisc_mode
== SET_PROMISC_MODE_OFF
)))
4231 mode
= SET_PROMISC_MODE_OFF
;
4232 if (dev
->flags
& IFF_PROMISC
)
4233 mode
= SET_PROMISC_MODE_ON
;
4234 QETH_CARD_TEXT_(card
, 4, "mode:%x", mode
);
4236 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_SET_PROMISC_MODE
,
4237 sizeof(struct qeth_ipacmd_setadpparms_hdr
) + 8);
4240 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+ IPA_PDU_HEADER_SIZE
);
4241 cmd
->data
.setadapterparms
.data
.mode
= mode
;
4242 qeth_send_ipa_cmd(card
, iob
, qeth_setadp_promisc_mode_cb
, NULL
);
4244 EXPORT_SYMBOL_GPL(qeth_setadp_promisc_mode
);
4246 int qeth_change_mtu(struct net_device
*dev
, int new_mtu
)
4248 struct qeth_card
*card
;
4251 card
= dev
->ml_priv
;
4253 QETH_CARD_TEXT(card
, 4, "chgmtu");
4254 sprintf(dbf_text
, "%8x", new_mtu
);
4255 QETH_CARD_TEXT(card
, 4, dbf_text
);
4257 if (!qeth_mtu_is_valid(card
, new_mtu
))
4262 EXPORT_SYMBOL_GPL(qeth_change_mtu
);
4264 struct net_device_stats
*qeth_get_stats(struct net_device
*dev
)
4266 struct qeth_card
*card
;
4268 card
= dev
->ml_priv
;
4270 QETH_CARD_TEXT(card
, 5, "getstat");
4272 return &card
->stats
;
4274 EXPORT_SYMBOL_GPL(qeth_get_stats
);
4276 static int qeth_setadpparms_change_macaddr_cb(struct qeth_card
*card
,
4277 struct qeth_reply
*reply
, unsigned long data
)
4279 struct qeth_ipa_cmd
*cmd
;
4281 QETH_CARD_TEXT(card
, 4, "chgmaccb");
4283 cmd
= (struct qeth_ipa_cmd
*) data
;
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
;
4290 qeth_default_setadapterparms_cb(card
, reply
, (unsigned long) cmd
);
4294 int qeth_setadpparms_change_macaddr(struct qeth_card
*card
)
4297 struct qeth_cmd_buffer
*iob
;
4298 struct qeth_ipa_cmd
*cmd
;
4300 QETH_CARD_TEXT(card
, 4, "chgmac");
4302 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_ALTER_MAC_ADDRESS
,
4303 sizeof(struct qeth_ipacmd_setadpparms_hdr
) +
4304 sizeof(struct qeth_change_addr
));
4307 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
4308 cmd
->data
.setadapterparms
.data
.change_addr
.cmd
= CHANGE_ADDR_READ_MAC
;
4309 cmd
->data
.setadapterparms
.data
.change_addr
.addr_size
= ETH_ALEN
;
4310 ether_addr_copy(cmd
->data
.setadapterparms
.data
.change_addr
.addr
,
4311 card
->dev
->dev_addr
);
4312 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_setadpparms_change_macaddr_cb
,
4316 EXPORT_SYMBOL_GPL(qeth_setadpparms_change_macaddr
);
4318 static int qeth_setadpparms_set_access_ctrl_cb(struct qeth_card
*card
,
4319 struct qeth_reply
*reply
, unsigned long data
)
4321 struct qeth_ipa_cmd
*cmd
;
4322 struct qeth_set_access_ctrl
*access_ctrl_req
;
4323 int fallback
= *(int *)reply
->param
;
4325 QETH_CARD_TEXT(card
, 4, "setaccb");
4327 cmd
= (struct qeth_ipa_cmd
*) data
;
4328 access_ctrl_req
= &cmd
->data
.setadapterparms
.data
.set_access_ctrl
;
4329 QETH_DBF_TEXT_(SETUP
, 2, "setaccb");
4330 QETH_DBF_TEXT_(SETUP
, 2, "%s", card
->gdev
->dev
.kobj
.name
);
4331 QETH_DBF_TEXT_(SETUP
, 2, "rc=%d",
4332 cmd
->data
.setadapterparms
.hdr
.return_code
);
4333 if (cmd
->data
.setadapterparms
.hdr
.return_code
!=
4334 SET_ACCESS_CTRL_RC_SUCCESS
)
4335 QETH_DBF_MESSAGE(3, "ERR:SET_ACCESS_CTRL(%s,%d)==%d\n",
4336 card
->gdev
->dev
.kobj
.name
,
4337 access_ctrl_req
->subcmd_code
,
4338 cmd
->data
.setadapterparms
.hdr
.return_code
);
4339 switch (cmd
->data
.setadapterparms
.hdr
.return_code
) {
4340 case SET_ACCESS_CTRL_RC_SUCCESS
:
4341 if (card
->options
.isolation
== ISOLATION_MODE_NONE
) {
4342 dev_info(&card
->gdev
->dev
,
4343 "QDIO data connection isolation is deactivated\n");
4345 dev_info(&card
->gdev
->dev
,
4346 "QDIO data connection isolation is activated\n");
4349 case SET_ACCESS_CTRL_RC_ALREADY_NOT_ISOLATED
:
4350 QETH_DBF_MESSAGE(2, "%s QDIO data connection isolation already "
4351 "deactivated\n", dev_name(&card
->gdev
->dev
));
4353 card
->options
.isolation
= card
->options
.prev_isolation
;
4355 case SET_ACCESS_CTRL_RC_ALREADY_ISOLATED
:
4356 QETH_DBF_MESSAGE(2, "%s QDIO data connection isolation already"
4357 " activated\n", dev_name(&card
->gdev
->dev
));
4359 card
->options
.isolation
= card
->options
.prev_isolation
;
4361 case SET_ACCESS_CTRL_RC_NOT_SUPPORTED
:
4362 dev_err(&card
->gdev
->dev
, "Adapter does not "
4363 "support QDIO data connection isolation\n");
4365 case SET_ACCESS_CTRL_RC_NONE_SHARED_ADAPTER
:
4366 dev_err(&card
->gdev
->dev
,
4367 "Adapter is dedicated. "
4368 "QDIO data connection isolation not supported\n");
4370 card
->options
.isolation
= card
->options
.prev_isolation
;
4372 case SET_ACCESS_CTRL_RC_ACTIVE_CHECKSUM_OFF
:
4373 dev_err(&card
->gdev
->dev
,
4374 "TSO does not permit QDIO data connection isolation\n");
4376 card
->options
.isolation
= card
->options
.prev_isolation
;
4378 case SET_ACCESS_CTRL_RC_REFLREL_UNSUPPORTED
:
4379 dev_err(&card
->gdev
->dev
, "The adjacent switch port does not "
4380 "support reflective relay mode\n");
4382 card
->options
.isolation
= card
->options
.prev_isolation
;
4384 case SET_ACCESS_CTRL_RC_REFLREL_FAILED
:
4385 dev_err(&card
->gdev
->dev
, "The reflective relay mode cannot be "
4386 "enabled at the adjacent switch port");
4388 card
->options
.isolation
= card
->options
.prev_isolation
;
4390 case SET_ACCESS_CTRL_RC_REFLREL_DEACT_FAILED
:
4391 dev_warn(&card
->gdev
->dev
, "Turning off reflective relay mode "
4392 "at the adjacent switch failed\n");
4395 /* this should never happen */
4397 card
->options
.isolation
= card
->options
.prev_isolation
;
4400 qeth_default_setadapterparms_cb(card
, reply
, (unsigned long) cmd
);
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
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
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
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
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
;
4689 struct qeth_qoat_priv
*priv
;
4693 QETH_CARD_TEXT(card
, 3, "qoatcb");
4695 cmd
= (struct qeth_ipa_cmd
*)data
;
4696 priv
= (struct qeth_qoat_priv
*)reply
->param
;
4697 resdatalen
= cmd
->data
.setadapterparms
.hdr
.cmdlength
;
4698 resdata
= (char *)data
+ 28;
4700 if (resdatalen
> (priv
->buffer_len
- priv
->response_len
)) {
4701 cmd
->hdr
.return_code
= IPA_RC_FFFF
;
4705 memcpy((priv
->buffer
+ priv
->response_len
), resdata
,
4707 priv
->response_len
+= resdatalen
;
4709 if (cmd
->data
.setadapterparms
.hdr
.seq_no
<
4710 cmd
->data
.setadapterparms
.hdr
.used_total
)
4715 static int qeth_query_oat_command(struct qeth_card
*card
, char __user
*udata
)
4718 struct qeth_cmd_buffer
*iob
;
4719 struct qeth_ipa_cmd
*cmd
;
4720 struct qeth_query_oat
*oat_req
;
4721 struct qeth_query_oat_data oat_data
;
4722 struct qeth_qoat_priv priv
;
4725 QETH_CARD_TEXT(card
, 3, "qoatcmd");
4727 if (!qeth_adp_supported(card
, IPA_SETADP_QUERY_OAT
)) {
4732 if (copy_from_user(&oat_data
, udata
,
4733 sizeof(struct qeth_query_oat_data
))) {
4738 priv
.buffer_len
= oat_data
.buffer_len
;
4739 priv
.response_len
= 0;
4740 priv
.buffer
= kzalloc(oat_data
.buffer_len
, GFP_KERNEL
);
4746 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_QUERY_OAT
,
4747 sizeof(struct qeth_ipacmd_setadpparms_hdr
) +
4748 sizeof(struct qeth_query_oat
));
4753 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
4754 oat_req
= &cmd
->data
.setadapterparms
.data
.query_oat
;
4755 oat_req
->subcmd_code
= oat_data
.command
;
4757 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_setadpparms_query_oat_cb
,
4760 if (is_compat_task())
4761 tmp
= compat_ptr(oat_data
.ptr
);
4763 tmp
= (void __user
*)(unsigned long)oat_data
.ptr
;
4765 if (copy_to_user(tmp
, priv
.buffer
,
4766 priv
.response_len
)) {
4771 oat_data
.response_len
= priv
.response_len
;
4773 if (copy_to_user(udata
, &oat_data
,
4774 sizeof(struct qeth_query_oat_data
)))
4777 if (rc
== IPA_RC_FFFF
)
4786 static int qeth_query_card_info_cb(struct qeth_card
*card
,
4787 struct qeth_reply
*reply
, unsigned long data
)
4789 struct qeth_ipa_cmd
*cmd
;
4790 struct qeth_query_card_info
*card_info
;
4791 struct carrier_info
*carrier_info
;
4793 QETH_CARD_TEXT(card
, 2, "qcrdincb");
4794 carrier_info
= (struct carrier_info
*)reply
->param
;
4795 cmd
= (struct qeth_ipa_cmd
*)data
;
4796 card_info
= &cmd
->data
.setadapterparms
.data
.card_info
;
4797 if (cmd
->data
.setadapterparms
.hdr
.return_code
== 0) {
4798 carrier_info
->card_type
= card_info
->card_type
;
4799 carrier_info
->port_mode
= card_info
->port_mode
;
4800 carrier_info
->port_speed
= card_info
->port_speed
;
4803 qeth_default_setadapterparms_cb(card
, reply
, (unsigned long) cmd
);
4807 static int qeth_query_card_info(struct qeth_card
*card
,
4808 struct carrier_info
*carrier_info
)
4810 struct qeth_cmd_buffer
*iob
;
4812 QETH_CARD_TEXT(card
, 2, "qcrdinfo");
4813 if (!qeth_adp_supported(card
, IPA_SETADP_QUERY_CARD_INFO
))
4815 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_QUERY_CARD_INFO
,
4816 sizeof(struct qeth_ipacmd_setadpparms_hdr
));
4819 return qeth_send_ipa_cmd(card
, iob
, qeth_query_card_info_cb
,
4820 (void *)carrier_info
);
4824 * qeth_vm_request_mac() - Request a hypervisor-managed MAC address
4825 * @card: pointer to a qeth_card
4828 * 0, if a MAC address has been set for the card's netdevice
4829 * a return code, for various error conditions
4831 int qeth_vm_request_mac(struct qeth_card
*card
)
4833 struct diag26c_mac_resp
*response
;
4834 struct diag26c_mac_req
*request
;
4835 struct ccw_dev_id id
;
4838 QETH_DBF_TEXT(SETUP
, 2, "vmreqmac");
4843 request
= kzalloc(sizeof(*request
), GFP_KERNEL
| GFP_DMA
);
4844 response
= kzalloc(sizeof(*response
), GFP_KERNEL
| GFP_DMA
);
4845 if (!request
|| !response
) {
4850 ccw_device_get_id(CARD_DDEV(card
), &id
);
4851 request
->resp_buf_len
= sizeof(*response
);
4852 request
->resp_version
= DIAG26C_VERSION2
;
4853 request
->op_code
= DIAG26C_GET_MAC
;
4854 request
->devno
= id
.devno
;
4856 QETH_DBF_HEX(CTRL
, 2, request
, sizeof(*request
));
4857 rc
= diag26c(request
, response
, DIAG26C_MAC_SERVICES
);
4858 QETH_DBF_HEX(CTRL
, 2, request
, sizeof(*request
));
4861 QETH_DBF_HEX(CTRL
, 2, response
, sizeof(*response
));
4863 if (request
->resp_buf_len
< sizeof(*response
) ||
4864 response
->version
!= request
->resp_version
) {
4866 QETH_DBF_TEXT(SETUP
, 2, "badresp");
4867 QETH_DBF_HEX(SETUP
, 2, &request
->resp_buf_len
,
4868 sizeof(request
->resp_buf_len
));
4869 } else if (!is_valid_ether_addr(response
->mac
)) {
4871 QETH_DBF_TEXT(SETUP
, 2, "badmac");
4872 QETH_DBF_HEX(SETUP
, 2, response
->mac
, ETH_ALEN
);
4874 ether_addr_copy(card
->dev
->dev_addr
, response
->mac
);
4882 EXPORT_SYMBOL_GPL(qeth_vm_request_mac
);
4884 static int qeth_get_qdio_q_format(struct qeth_card
*card
)
4886 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
4887 return QDIO_IQDIO_QFMT
;
4889 return QDIO_QETH_QFMT
;
4892 static void qeth_determine_capabilities(struct qeth_card
*card
)
4897 struct ccw_device
*ddev
;
4898 int ddev_offline
= 0;
4900 QETH_DBF_TEXT(SETUP
, 2, "detcapab");
4901 ddev
= CARD_DDEV(card
);
4902 if (!ddev
->online
) {
4904 rc
= ccw_device_set_online(ddev
);
4906 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
4911 rc
= qeth_read_conf_data(card
, (void **) &prcd
, &length
);
4913 QETH_DBF_MESSAGE(2, "%s qeth_read_conf_data returned %i\n",
4914 dev_name(&card
->gdev
->dev
), rc
);
4915 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
4918 qeth_configure_unitaddr(card
, prcd
);
4920 qeth_configure_blkt_default(card
, prcd
);
4923 rc
= qdio_get_ssqd_desc(ddev
, &card
->ssqd
);
4925 QETH_DBF_TEXT_(SETUP
, 2, "6err%d", rc
);
4927 QETH_DBF_TEXT_(SETUP
, 2, "qfmt%d", card
->ssqd
.qfmt
);
4928 QETH_DBF_TEXT_(SETUP
, 2, "ac1:%02x", card
->ssqd
.qdioac1
);
4929 QETH_DBF_TEXT_(SETUP
, 2, "ac2:%04x", card
->ssqd
.qdioac2
);
4930 QETH_DBF_TEXT_(SETUP
, 2, "ac3:%04x", card
->ssqd
.qdioac3
);
4931 QETH_DBF_TEXT_(SETUP
, 2, "icnt%d", card
->ssqd
.icnt
);
4932 if (!((card
->ssqd
.qfmt
!= QDIO_IQDIO_QFMT
) ||
4933 ((card
->ssqd
.qdioac1
& CHSC_AC1_INITIATE_INPUTQ
) == 0) ||
4934 ((card
->ssqd
.qdioac3
& CHSC_AC3_FORMAT2_CQ_AVAILABLE
) == 0))) {
4935 dev_info(&card
->gdev
->dev
,
4936 "Completion Queueing supported\n");
4938 card
->options
.cq
= QETH_CQ_NOTAVAILABLE
;
4943 if (ddev_offline
== 1)
4944 ccw_device_set_offline(ddev
);
4949 static void qeth_qdio_establish_cq(struct qeth_card
*card
,
4950 struct qdio_buffer
**in_sbal_ptrs
,
4951 void (**queue_start_poll
)
4952 (struct ccw_device
*, int,
4957 if (card
->options
.cq
== QETH_CQ_ENABLED
) {
4958 int offset
= QDIO_MAX_BUFFERS_PER_Q
*
4959 (card
->qdio
.no_in_queues
- 1);
4960 for (i
= 0; i
< QDIO_MAX_BUFFERS_PER_Q
; ++i
) {
4961 in_sbal_ptrs
[offset
+ i
] = (struct qdio_buffer
*)
4962 virt_to_phys(card
->qdio
.c_q
->bufs
[i
].buffer
);
4965 queue_start_poll
[card
->qdio
.no_in_queues
- 1] = NULL
;
4969 static int qeth_qdio_establish(struct qeth_card
*card
)
4971 struct qdio_initialize init_data
;
4972 char *qib_param_field
;
4973 struct qdio_buffer
**in_sbal_ptrs
;
4974 void (**queue_start_poll
) (struct ccw_device
*, int, unsigned long);
4975 struct qdio_buffer
**out_sbal_ptrs
;
4979 QETH_DBF_TEXT(SETUP
, 2, "qdioest");
4981 qib_param_field
= kzalloc(QDIO_MAX_BUFFERS_PER_Q
* sizeof(char),
4983 if (!qib_param_field
) {
4985 goto out_free_nothing
;
4988 qeth_create_qib_param_field(card
, qib_param_field
);
4989 qeth_create_qib_param_field_blkt(card
, qib_param_field
);
4991 in_sbal_ptrs
= kzalloc(card
->qdio
.no_in_queues
*
4992 QDIO_MAX_BUFFERS_PER_Q
* sizeof(void *),
4994 if (!in_sbal_ptrs
) {
4996 goto out_free_qib_param
;
4998 for (i
= 0; i
< QDIO_MAX_BUFFERS_PER_Q
; ++i
) {
4999 in_sbal_ptrs
[i
] = (struct qdio_buffer
*)
5000 virt_to_phys(card
->qdio
.in_q
->bufs
[i
].buffer
);
5003 queue_start_poll
= kzalloc(sizeof(void *) * card
->qdio
.no_in_queues
,
5005 if (!queue_start_poll
) {
5007 goto out_free_in_sbals
;
5009 for (i
= 0; i
< card
->qdio
.no_in_queues
; ++i
)
5010 queue_start_poll
[i
] = card
->discipline
->start_poll
;
5012 qeth_qdio_establish_cq(card
, in_sbal_ptrs
, queue_start_poll
);
5015 kzalloc(card
->qdio
.no_out_queues
* QDIO_MAX_BUFFERS_PER_Q
*
5016 sizeof(void *), GFP_KERNEL
);
5017 if (!out_sbal_ptrs
) {
5019 goto out_free_queue_start_poll
;
5021 for (i
= 0, k
= 0; i
< card
->qdio
.no_out_queues
; ++i
)
5022 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
, ++k
) {
5023 out_sbal_ptrs
[k
] = (struct qdio_buffer
*)virt_to_phys(
5024 card
->qdio
.out_qs
[i
]->bufs
[j
]->buffer
);
5027 memset(&init_data
, 0, sizeof(struct qdio_initialize
));
5028 init_data
.cdev
= CARD_DDEV(card
);
5029 init_data
.q_format
= qeth_get_qdio_q_format(card
);
5030 init_data
.qib_param_field_format
= 0;
5031 init_data
.qib_param_field
= qib_param_field
;
5032 init_data
.no_input_qs
= card
->qdio
.no_in_queues
;
5033 init_data
.no_output_qs
= card
->qdio
.no_out_queues
;
5034 init_data
.input_handler
= card
->discipline
->input_handler
;
5035 init_data
.output_handler
= card
->discipline
->output_handler
;
5036 init_data
.queue_start_poll_array
= queue_start_poll
;
5037 init_data
.int_parm
= (unsigned long) card
;
5038 init_data
.input_sbal_addr_array
= (void **) in_sbal_ptrs
;
5039 init_data
.output_sbal_addr_array
= (void **) out_sbal_ptrs
;
5040 init_data
.output_sbal_state_array
= card
->qdio
.out_bufstates
;
5041 init_data
.scan_threshold
=
5042 (card
->info
.type
== QETH_CARD_TYPE_IQD
) ? 1 : 32;
5044 if (atomic_cmpxchg(&card
->qdio
.state
, QETH_QDIO_ALLOCATED
,
5045 QETH_QDIO_ESTABLISHED
) == QETH_QDIO_ALLOCATED
) {
5046 rc
= qdio_allocate(&init_data
);
5048 atomic_set(&card
->qdio
.state
, QETH_QDIO_ALLOCATED
);
5051 rc
= qdio_establish(&init_data
);
5053 atomic_set(&card
->qdio
.state
, QETH_QDIO_ALLOCATED
);
5054 qdio_free(CARD_DDEV(card
));
5058 switch (card
->options
.cq
) {
5059 case QETH_CQ_ENABLED
:
5060 dev_info(&card
->gdev
->dev
, "Completion Queue support enabled");
5062 case QETH_CQ_DISABLED
:
5063 dev_info(&card
->gdev
->dev
, "Completion Queue support disabled");
5069 kfree(out_sbal_ptrs
);
5070 out_free_queue_start_poll
:
5071 kfree(queue_start_poll
);
5073 kfree(in_sbal_ptrs
);
5075 kfree(qib_param_field
);
5080 static void qeth_core_free_card(struct qeth_card
*card
)
5083 QETH_DBF_TEXT(SETUP
, 2, "freecrd");
5084 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
5085 qeth_clean_channel(&card
->read
);
5086 qeth_clean_channel(&card
->write
);
5088 free_netdev(card
->dev
);
5089 qeth_free_qdio_buffers(card
);
5090 unregister_service_level(&card
->qeth_service_level
);
5094 void qeth_trace_features(struct qeth_card
*card
)
5096 QETH_CARD_TEXT(card
, 2, "features");
5097 QETH_CARD_HEX(card
, 2, &card
->options
.ipa4
, sizeof(card
->options
.ipa4
));
5098 QETH_CARD_HEX(card
, 2, &card
->options
.ipa6
, sizeof(card
->options
.ipa6
));
5099 QETH_CARD_HEX(card
, 2, &card
->options
.adp
, sizeof(card
->options
.adp
));
5100 QETH_CARD_HEX(card
, 2, &card
->info
.diagass_support
,
5101 sizeof(card
->info
.diagass_support
));
5103 EXPORT_SYMBOL_GPL(qeth_trace_features
);
5105 static struct ccw_device_id qeth_ids
[] = {
5106 {CCW_DEVICE_DEVTYPE(0x1731, 0x01, 0x1732, 0x01),
5107 .driver_info
= QETH_CARD_TYPE_OSD
},
5108 {CCW_DEVICE_DEVTYPE(0x1731, 0x05, 0x1732, 0x05),
5109 .driver_info
= QETH_CARD_TYPE_IQD
},
5110 {CCW_DEVICE_DEVTYPE(0x1731, 0x06, 0x1732, 0x06),
5111 .driver_info
= QETH_CARD_TYPE_OSN
},
5112 {CCW_DEVICE_DEVTYPE(0x1731, 0x02, 0x1732, 0x03),
5113 .driver_info
= QETH_CARD_TYPE_OSM
},
5114 {CCW_DEVICE_DEVTYPE(0x1731, 0x02, 0x1732, 0x02),
5115 .driver_info
= QETH_CARD_TYPE_OSX
},
5118 MODULE_DEVICE_TABLE(ccw
, qeth_ids
);
5120 static struct ccw_driver qeth_ccw_driver
= {
5122 .owner
= THIS_MODULE
,
5126 .probe
= ccwgroup_probe_ccwdev
,
5127 .remove
= ccwgroup_remove_ccwdev
,
5130 int qeth_core_hardsetup_card(struct qeth_card
*card
)
5135 QETH_DBF_TEXT(SETUP
, 2, "hrdsetup");
5136 atomic_set(&card
->force_alloc_skb
, 0);
5137 qeth_update_from_chp_desc(card
);
5140 QETH_DBF_MESSAGE(2, "%s Retrying to do IDX activates.\n",
5141 dev_name(&card
->gdev
->dev
));
5142 rc
= qeth_qdio_clear_card(card
, card
->info
.type
!= QETH_CARD_TYPE_IQD
);
5143 ccw_device_set_offline(CARD_DDEV(card
));
5144 ccw_device_set_offline(CARD_WDEV(card
));
5145 ccw_device_set_offline(CARD_RDEV(card
));
5146 qdio_free(CARD_DDEV(card
));
5147 rc
= ccw_device_set_online(CARD_RDEV(card
));
5150 rc
= ccw_device_set_online(CARD_WDEV(card
));
5153 rc
= ccw_device_set_online(CARD_DDEV(card
));
5157 if (rc
== -ERESTARTSYS
) {
5158 QETH_DBF_TEXT(SETUP
, 2, "break1");
5161 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
5167 qeth_determine_capabilities(card
);
5168 qeth_init_tokens(card
);
5169 qeth_init_func_level(card
);
5170 rc
= qeth_idx_activate_channel(&card
->read
, qeth_idx_read_cb
);
5171 if (rc
== -ERESTARTSYS
) {
5172 QETH_DBF_TEXT(SETUP
, 2, "break2");
5175 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
5181 rc
= qeth_idx_activate_channel(&card
->write
, qeth_idx_write_cb
);
5182 if (rc
== -ERESTARTSYS
) {
5183 QETH_DBF_TEXT(SETUP
, 2, "break3");
5186 QETH_DBF_TEXT_(SETUP
, 2, "4err%d", rc
);
5192 card
->read_or_write_problem
= 0;
5193 rc
= qeth_mpc_initialize(card
);
5195 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
5199 rc
= qeth_send_startlan(card
);
5201 QETH_DBF_TEXT_(SETUP
, 2, "6err%d", rc
);
5202 if (rc
== IPA_RC_LAN_OFFLINE
) {
5203 dev_warn(&card
->gdev
->dev
,
5204 "The LAN is offline\n");
5205 card
->lan_online
= 0;
5211 card
->lan_online
= 1;
5213 card
->options
.ipa4
.supported_funcs
= 0;
5214 card
->options
.ipa6
.supported_funcs
= 0;
5215 card
->options
.adp
.supported_funcs
= 0;
5216 card
->options
.sbp
.supported_funcs
= 0;
5217 card
->info
.diagass_support
= 0;
5218 rc
= qeth_query_ipassists(card
, QETH_PROT_IPV4
);
5221 if (qeth_is_supported(card
, IPA_SETADAPTERPARMS
)) {
5222 rc
= qeth_query_setadapterparms(card
);
5224 QETH_DBF_TEXT_(SETUP
, 2, "7err%d", rc
);
5228 if (qeth_adp_supported(card
, IPA_SETADP_SET_DIAG_ASSIST
)) {
5229 rc
= qeth_query_setdiagass(card
);
5231 QETH_DBF_TEXT_(SETUP
, 2, "8err%d", rc
);
5237 dev_warn(&card
->gdev
->dev
, "The qeth device driver failed to recover "
5238 "an error on the device\n");
5239 QETH_DBF_MESSAGE(2, "%s Initialization in hardsetup failed! rc=%d\n",
5240 dev_name(&card
->gdev
->dev
), rc
);
5243 EXPORT_SYMBOL_GPL(qeth_core_hardsetup_card
);
5245 static void qeth_create_skb_frag(struct qdio_buffer_element
*element
,
5246 struct sk_buff
*skb
, int offset
, int data_len
)
5248 struct page
*page
= virt_to_page(element
->addr
);
5249 unsigned int next_frag
;
5251 /* first fill the linear space */
5253 unsigned int linear
= min(data_len
, skb_tailroom(skb
));
5255 skb_put_data(skb
, element
->addr
+ offset
, linear
);
5260 /* fall through to add page frag for remaining data */
5263 next_frag
= skb_shinfo(skb
)->nr_frags
;
5265 skb_add_rx_frag(skb
, next_frag
, page
, offset
, data_len
, data_len
);
5268 static inline int qeth_is_last_sbale(struct qdio_buffer_element
*sbale
)
5270 return (sbale
->eflags
& SBAL_EFLAGS_LAST_ENTRY
);
5273 struct sk_buff
*qeth_core_get_next_skb(struct qeth_card
*card
,
5274 struct qeth_qdio_buffer
*qethbuffer
,
5275 struct qdio_buffer_element
**__element
, int *__offset
,
5276 struct qeth_hdr
**hdr
)
5278 struct qdio_buffer_element
*element
= *__element
;
5279 struct qdio_buffer
*buffer
= qethbuffer
->buffer
;
5280 int offset
= *__offset
;
5281 struct sk_buff
*skb
;
5288 /* qeth_hdr must not cross element boundaries */
5289 while (element
->length
< offset
+ sizeof(struct qeth_hdr
)) {
5290 if (qeth_is_last_sbale(element
))
5295 *hdr
= element
->addr
+ offset
;
5297 offset
+= sizeof(struct qeth_hdr
);
5298 switch ((*hdr
)->hdr
.l2
.id
) {
5299 case QETH_HEADER_TYPE_LAYER2
:
5300 skb_len
= (*hdr
)->hdr
.l2
.pkt_length
;
5302 case QETH_HEADER_TYPE_LAYER3
:
5303 skb_len
= (*hdr
)->hdr
.l3
.length
;
5304 headroom
= ETH_HLEN
;
5306 case QETH_HEADER_TYPE_OSN
:
5307 skb_len
= (*hdr
)->hdr
.osn
.pdu_length
;
5308 headroom
= sizeof(struct qeth_hdr
);
5317 if (((skb_len
>= card
->options
.rx_sg_cb
) &&
5318 (!(card
->info
.type
== QETH_CARD_TYPE_OSN
)) &&
5319 (!atomic_read(&card
->force_alloc_skb
))) ||
5320 (card
->options
.cq
== QETH_CQ_ENABLED
))
5323 if (use_rx_sg
&& qethbuffer
->rx_skb
) {
5324 /* QETH_CQ_ENABLED only: */
5325 skb
= qethbuffer
->rx_skb
;
5326 qethbuffer
->rx_skb
= NULL
;
5328 unsigned int linear
= (use_rx_sg
) ? QETH_RX_PULL_LEN
: skb_len
;
5330 skb
= dev_alloc_skb(linear
+ headroom
);
5335 skb_reserve(skb
, headroom
);
5337 data_ptr
= element
->addr
+ offset
;
5339 data_len
= min(skb_len
, (int)(element
->length
- offset
));
5342 qeth_create_skb_frag(element
, skb
, offset
,
5345 skb_put_data(skb
, data_ptr
, data_len
);
5347 skb_len
-= data_len
;
5349 if (qeth_is_last_sbale(element
)) {
5350 QETH_CARD_TEXT(card
, 4, "unexeob");
5351 QETH_CARD_HEX(card
, 2, buffer
, sizeof(void *));
5352 dev_kfree_skb_any(skb
);
5353 card
->stats
.rx_errors
++;
5358 data_ptr
= element
->addr
;
5363 *__element
= element
;
5365 if (use_rx_sg
&& card
->options
.performance_stats
) {
5366 card
->perf_stats
.sg_skbs_rx
++;
5367 card
->perf_stats
.sg_frags_rx
+= skb_shinfo(skb
)->nr_frags
;
5371 if (net_ratelimit()) {
5372 QETH_CARD_TEXT(card
, 2, "noskbmem");
5374 card
->stats
.rx_dropped
++;
5377 EXPORT_SYMBOL_GPL(qeth_core_get_next_skb
);
5379 int qeth_poll(struct napi_struct
*napi
, int budget
)
5381 struct qeth_card
*card
= container_of(napi
, struct qeth_card
, napi
);
5383 struct qeth_qdio_buffer
*buffer
;
5385 int new_budget
= budget
;
5387 if (card
->options
.performance_stats
) {
5388 card
->perf_stats
.inbound_cnt
++;
5389 card
->perf_stats
.inbound_start_time
= qeth_get_micros();
5393 if (!card
->rx
.b_count
) {
5394 card
->rx
.qdio_err
= 0;
5395 card
->rx
.b_count
= qdio_get_next_buffers(
5396 card
->data
.ccwdev
, 0, &card
->rx
.b_index
,
5397 &card
->rx
.qdio_err
);
5398 if (card
->rx
.b_count
<= 0) {
5399 card
->rx
.b_count
= 0;
5402 card
->rx
.b_element
=
5403 &card
->qdio
.in_q
->bufs
[card
->rx
.b_index
]
5404 .buffer
->element
[0];
5405 card
->rx
.e_offset
= 0;
5408 while (card
->rx
.b_count
) {
5409 buffer
= &card
->qdio
.in_q
->bufs
[card
->rx
.b_index
];
5410 if (!(card
->rx
.qdio_err
&&
5411 qeth_check_qdio_errors(card
, buffer
->buffer
,
5412 card
->rx
.qdio_err
, "qinerr")))
5414 card
->discipline
->process_rx_buffer(
5415 card
, new_budget
, &done
);
5420 if (card
->options
.performance_stats
)
5421 card
->perf_stats
.bufs_rec
++;
5422 qeth_put_buffer_pool_entry(card
,
5423 buffer
->pool_entry
);
5424 qeth_queue_input_buffer(card
, card
->rx
.b_index
);
5426 if (card
->rx
.b_count
) {
5428 (card
->rx
.b_index
+ 1) %
5429 QDIO_MAX_BUFFERS_PER_Q
;
5430 card
->rx
.b_element
=
5432 ->bufs
[card
->rx
.b_index
]
5433 .buffer
->element
[0];
5434 card
->rx
.e_offset
= 0;
5438 if (work_done
>= budget
)
5441 new_budget
= budget
- work_done
;
5445 napi_complete_done(napi
, work_done
);
5446 if (qdio_start_irq(card
->data
.ccwdev
, 0))
5447 napi_schedule(&card
->napi
);
5449 if (card
->options
.performance_stats
)
5450 card
->perf_stats
.inbound_time
+= qeth_get_micros() -
5451 card
->perf_stats
.inbound_start_time
;
5454 EXPORT_SYMBOL_GPL(qeth_poll
);
5456 static int qeth_setassparms_inspect_rc(struct qeth_ipa_cmd
*cmd
)
5458 if (!cmd
->hdr
.return_code
)
5459 cmd
->hdr
.return_code
= cmd
->data
.setassparms
.hdr
.return_code
;
5460 return cmd
->hdr
.return_code
;
5463 int qeth_setassparms_cb(struct qeth_card
*card
,
5464 struct qeth_reply
*reply
, unsigned long data
)
5466 struct qeth_ipa_cmd
*cmd
;
5468 QETH_CARD_TEXT(card
, 4, "defadpcb");
5470 cmd
= (struct qeth_ipa_cmd
*) data
;
5471 if (cmd
->hdr
.return_code
== 0) {
5472 cmd
->hdr
.return_code
= cmd
->data
.setassparms
.hdr
.return_code
;
5473 if (cmd
->hdr
.prot_version
== QETH_PROT_IPV4
)
5474 card
->options
.ipa4
.enabled_funcs
= cmd
->hdr
.ipa_enabled
;
5475 if (cmd
->hdr
.prot_version
== QETH_PROT_IPV6
)
5476 card
->options
.ipa6
.enabled_funcs
= cmd
->hdr
.ipa_enabled
;
5480 EXPORT_SYMBOL_GPL(qeth_setassparms_cb
);
5482 struct qeth_cmd_buffer
*qeth_get_setassparms_cmd(struct qeth_card
*card
,
5483 enum qeth_ipa_funcs ipa_func
,
5484 __u16 cmd_code
, __u16 len
,
5485 enum qeth_prot_versions prot
)
5487 struct qeth_cmd_buffer
*iob
;
5488 struct qeth_ipa_cmd
*cmd
;
5490 QETH_CARD_TEXT(card
, 4, "getasscm");
5491 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SETASSPARMS
, prot
);
5494 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
5495 cmd
->data
.setassparms
.hdr
.assist_no
= ipa_func
;
5496 cmd
->data
.setassparms
.hdr
.length
= 8 + len
;
5497 cmd
->data
.setassparms
.hdr
.command_code
= cmd_code
;
5498 cmd
->data
.setassparms
.hdr
.return_code
= 0;
5499 cmd
->data
.setassparms
.hdr
.seq_no
= 0;
5504 EXPORT_SYMBOL_GPL(qeth_get_setassparms_cmd
);
5506 int qeth_send_setassparms(struct qeth_card
*card
,
5507 struct qeth_cmd_buffer
*iob
, __u16 len
, long data
,
5508 int (*reply_cb
)(struct qeth_card
*,
5509 struct qeth_reply
*, unsigned long),
5513 struct qeth_ipa_cmd
*cmd
;
5515 QETH_CARD_TEXT(card
, 4, "sendassp");
5517 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
5518 if (len
<= sizeof(__u32
))
5519 cmd
->data
.setassparms
.data
.flags_32bit
= (__u32
) data
;
5520 else /* (len > sizeof(__u32)) */
5521 memcpy(&cmd
->data
.setassparms
.data
, (void *) data
, len
);
5523 rc
= qeth_send_ipa_cmd(card
, iob
, reply_cb
, reply_param
);
5526 EXPORT_SYMBOL_GPL(qeth_send_setassparms
);
5528 int qeth_send_simple_setassparms(struct qeth_card
*card
,
5529 enum qeth_ipa_funcs ipa_func
,
5530 __u16 cmd_code
, long data
)
5534 struct qeth_cmd_buffer
*iob
;
5536 QETH_CARD_TEXT(card
, 4, "simassp4");
5538 length
= sizeof(__u32
);
5539 iob
= qeth_get_setassparms_cmd(card
, ipa_func
, cmd_code
,
5540 length
, QETH_PROT_IPV4
);
5543 rc
= qeth_send_setassparms(card
, iob
, length
, data
,
5544 qeth_setassparms_cb
, NULL
);
5547 EXPORT_SYMBOL_GPL(qeth_send_simple_setassparms
);
5549 static void qeth_unregister_dbf_views(void)
5552 for (x
= 0; x
< QETH_DBF_INFOS
; x
++) {
5553 debug_unregister(qeth_dbf
[x
].id
);
5554 qeth_dbf
[x
].id
= NULL
;
5558 void qeth_dbf_longtext(debug_info_t
*id
, int level
, char *fmt
, ...)
5560 char dbf_txt_buf
[32];
5563 if (!debug_level_enabled(id
, level
))
5565 va_start(args
, fmt
);
5566 vsnprintf(dbf_txt_buf
, sizeof(dbf_txt_buf
), fmt
, args
);
5568 debug_text_event(id
, level
, dbf_txt_buf
);
5570 EXPORT_SYMBOL_GPL(qeth_dbf_longtext
);
5572 static int qeth_register_dbf_views(void)
5577 for (x
= 0; x
< QETH_DBF_INFOS
; x
++) {
5578 /* register the areas */
5579 qeth_dbf
[x
].id
= debug_register(qeth_dbf
[x
].name
,
5583 if (qeth_dbf
[x
].id
== NULL
) {
5584 qeth_unregister_dbf_views();
5588 /* register a view */
5589 ret
= debug_register_view(qeth_dbf
[x
].id
, qeth_dbf
[x
].view
);
5591 qeth_unregister_dbf_views();
5595 /* set a passing level */
5596 debug_set_level(qeth_dbf
[x
].id
, qeth_dbf
[x
].level
);
5602 int qeth_core_load_discipline(struct qeth_card
*card
,
5603 enum qeth_discipline_id discipline
)
5607 mutex_lock(&qeth_mod_mutex
);
5608 switch (discipline
) {
5609 case QETH_DISCIPLINE_LAYER3
:
5610 card
->discipline
= try_then_request_module(
5611 symbol_get(qeth_l3_discipline
), "qeth_l3");
5613 case QETH_DISCIPLINE_LAYER2
:
5614 card
->discipline
= try_then_request_module(
5615 symbol_get(qeth_l2_discipline
), "qeth_l2");
5621 if (!card
->discipline
) {
5622 dev_err(&card
->gdev
->dev
, "There is no kernel module to "
5623 "support discipline %d\n", discipline
);
5626 mutex_unlock(&qeth_mod_mutex
);
5630 void qeth_core_free_discipline(struct qeth_card
*card
)
5632 if (card
->options
.layer2
)
5633 symbol_put(qeth_l2_discipline
);
5635 symbol_put(qeth_l3_discipline
);
5636 card
->discipline
= NULL
;
5639 const struct device_type qeth_generic_devtype
= {
5640 .name
= "qeth_generic",
5641 .groups
= qeth_generic_attr_groups
,
5643 EXPORT_SYMBOL_GPL(qeth_generic_devtype
);
5645 static const struct device_type qeth_osn_devtype
= {
5647 .groups
= qeth_osn_attr_groups
,
5650 #define DBF_NAME_LEN 20
5652 struct qeth_dbf_entry
{
5653 char dbf_name
[DBF_NAME_LEN
];
5654 debug_info_t
*dbf_info
;
5655 struct list_head dbf_list
;
5658 static LIST_HEAD(qeth_dbf_list
);
5659 static DEFINE_MUTEX(qeth_dbf_list_mutex
);
5661 static debug_info_t
*qeth_get_dbf_entry(char *name
)
5663 struct qeth_dbf_entry
*entry
;
5664 debug_info_t
*rc
= NULL
;
5666 mutex_lock(&qeth_dbf_list_mutex
);
5667 list_for_each_entry(entry
, &qeth_dbf_list
, dbf_list
) {
5668 if (strcmp(entry
->dbf_name
, name
) == 0) {
5669 rc
= entry
->dbf_info
;
5673 mutex_unlock(&qeth_dbf_list_mutex
);
5677 static int qeth_add_dbf_entry(struct qeth_card
*card
, char *name
)
5679 struct qeth_dbf_entry
*new_entry
;
5681 card
->debug
= debug_register(name
, 2, 1, 8);
5683 QETH_DBF_TEXT_(SETUP
, 2, "%s", "qcdbf");
5686 if (debug_register_view(card
->debug
, &debug_hex_ascii_view
))
5688 new_entry
= kzalloc(sizeof(struct qeth_dbf_entry
), GFP_KERNEL
);
5691 strncpy(new_entry
->dbf_name
, name
, DBF_NAME_LEN
);
5692 new_entry
->dbf_info
= card
->debug
;
5693 mutex_lock(&qeth_dbf_list_mutex
);
5694 list_add(&new_entry
->dbf_list
, &qeth_dbf_list
);
5695 mutex_unlock(&qeth_dbf_list_mutex
);
5700 debug_unregister(card
->debug
);
5705 static void qeth_clear_dbf_list(void)
5707 struct qeth_dbf_entry
*entry
, *tmp
;
5709 mutex_lock(&qeth_dbf_list_mutex
);
5710 list_for_each_entry_safe(entry
, tmp
, &qeth_dbf_list
, dbf_list
) {
5711 list_del(&entry
->dbf_list
);
5712 debug_unregister(entry
->dbf_info
);
5715 mutex_unlock(&qeth_dbf_list_mutex
);
5718 static int qeth_core_probe_device(struct ccwgroup_device
*gdev
)
5720 struct qeth_card
*card
;
5723 enum qeth_discipline_id enforced_disc
;
5724 unsigned long flags
;
5725 char dbf_name
[DBF_NAME_LEN
];
5727 QETH_DBF_TEXT(SETUP
, 2, "probedev");
5730 if (!get_device(dev
))
5733 QETH_DBF_TEXT_(SETUP
, 2, "%s", dev_name(&gdev
->dev
));
5735 card
= qeth_alloc_card();
5737 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", -ENOMEM
);
5742 snprintf(dbf_name
, sizeof(dbf_name
), "qeth_card_%s",
5743 dev_name(&gdev
->dev
));
5744 card
->debug
= qeth_get_dbf_entry(dbf_name
);
5746 rc
= qeth_add_dbf_entry(card
, dbf_name
);
5751 card
->read
.ccwdev
= gdev
->cdev
[0];
5752 card
->write
.ccwdev
= gdev
->cdev
[1];
5753 card
->data
.ccwdev
= gdev
->cdev
[2];
5754 dev_set_drvdata(&gdev
->dev
, card
);
5756 gdev
->cdev
[0]->handler
= qeth_irq
;
5757 gdev
->cdev
[1]->handler
= qeth_irq
;
5758 gdev
->cdev
[2]->handler
= qeth_irq
;
5760 qeth_determine_card_type(card
);
5761 rc
= qeth_setup_card(card
);
5763 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
5767 qeth_determine_capabilities(card
);
5768 enforced_disc
= qeth_enforce_discipline(card
);
5769 switch (enforced_disc
) {
5770 case QETH_DISCIPLINE_UNDETERMINED
:
5771 gdev
->dev
.type
= &qeth_generic_devtype
;
5774 card
->info
.layer_enforced
= true;
5775 rc
= qeth_core_load_discipline(card
, enforced_disc
);
5779 gdev
->dev
.type
= (card
->info
.type
!= QETH_CARD_TYPE_OSN
)
5780 ? card
->discipline
->devtype
5781 : &qeth_osn_devtype
;
5782 rc
= card
->discipline
->setup(card
->gdev
);
5788 write_lock_irqsave(&qeth_core_card_list
.rwlock
, flags
);
5789 list_add_tail(&card
->list
, &qeth_core_card_list
.list
);
5790 write_unlock_irqrestore(&qeth_core_card_list
.rwlock
, flags
);
5794 qeth_core_free_discipline(card
);
5796 qeth_core_free_card(card
);
5802 static void qeth_core_remove_device(struct ccwgroup_device
*gdev
)
5804 unsigned long flags
;
5805 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5807 QETH_DBF_TEXT(SETUP
, 2, "removedv");
5809 if (card
->discipline
) {
5810 card
->discipline
->remove(gdev
);
5811 qeth_core_free_discipline(card
);
5814 write_lock_irqsave(&qeth_core_card_list
.rwlock
, flags
);
5815 list_del(&card
->list
);
5816 write_unlock_irqrestore(&qeth_core_card_list
.rwlock
, flags
);
5817 qeth_core_free_card(card
);
5818 dev_set_drvdata(&gdev
->dev
, NULL
);
5819 put_device(&gdev
->dev
);
5823 static int qeth_core_set_online(struct ccwgroup_device
*gdev
)
5825 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5827 enum qeth_discipline_id def_discipline
;
5829 if (!card
->discipline
) {
5830 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
5831 def_discipline
= QETH_DISCIPLINE_LAYER3
;
5833 def_discipline
= QETH_DISCIPLINE_LAYER2
;
5834 rc
= qeth_core_load_discipline(card
, def_discipline
);
5837 rc
= card
->discipline
->setup(card
->gdev
);
5839 qeth_core_free_discipline(card
);
5843 rc
= card
->discipline
->set_online(gdev
);
5848 static int qeth_core_set_offline(struct ccwgroup_device
*gdev
)
5850 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5851 return card
->discipline
->set_offline(gdev
);
5854 static void qeth_core_shutdown(struct ccwgroup_device
*gdev
)
5856 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5857 qeth_set_allowed_threads(card
, 0, 1);
5858 if ((gdev
->state
== CCWGROUP_ONLINE
) && card
->info
.hwtrap
)
5859 qeth_hw_trap(card
, QETH_DIAGS_TRAP_DISARM
);
5860 qeth_qdio_clear_card(card
, 0);
5861 qeth_clear_qdio_buffers(card
);
5862 qdio_free(CARD_DDEV(card
));
5865 static int qeth_core_freeze(struct ccwgroup_device
*gdev
)
5867 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5868 if (card
->discipline
&& card
->discipline
->freeze
)
5869 return card
->discipline
->freeze(gdev
);
5873 static int qeth_core_thaw(struct ccwgroup_device
*gdev
)
5875 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5876 if (card
->discipline
&& card
->discipline
->thaw
)
5877 return card
->discipline
->thaw(gdev
);
5881 static int qeth_core_restore(struct ccwgroup_device
*gdev
)
5883 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5884 if (card
->discipline
&& card
->discipline
->restore
)
5885 return card
->discipline
->restore(gdev
);
5889 static struct ccwgroup_driver qeth_core_ccwgroup_driver
= {
5891 .owner
= THIS_MODULE
,
5894 .ccw_driver
= &qeth_ccw_driver
,
5895 .setup
= qeth_core_probe_device
,
5896 .remove
= qeth_core_remove_device
,
5897 .set_online
= qeth_core_set_online
,
5898 .set_offline
= qeth_core_set_offline
,
5899 .shutdown
= qeth_core_shutdown
,
5902 .freeze
= qeth_core_freeze
,
5903 .thaw
= qeth_core_thaw
,
5904 .restore
= qeth_core_restore
,
5907 static ssize_t
group_store(struct device_driver
*ddrv
, const char *buf
,
5912 err
= ccwgroup_create_dev(qeth_core_root_dev
,
5913 &qeth_core_ccwgroup_driver
, 3, buf
);
5915 return err
? err
: count
;
5917 static DRIVER_ATTR_WO(group
);
5919 static struct attribute
*qeth_drv_attrs
[] = {
5920 &driver_attr_group
.attr
,
5923 static struct attribute_group qeth_drv_attr_group
= {
5924 .attrs
= qeth_drv_attrs
,
5926 static const struct attribute_group
*qeth_drv_attr_groups
[] = {
5927 &qeth_drv_attr_group
,
5931 int qeth_do_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
5933 struct qeth_card
*card
= dev
->ml_priv
;
5934 struct mii_ioctl_data
*mii_data
;
5940 if (!qeth_card_hw_is_reachable(card
))
5943 if (card
->info
.type
== QETH_CARD_TYPE_OSN
)
5947 case SIOC_QETH_ADP_SET_SNMP_CONTROL
:
5948 rc
= qeth_snmp_command(card
, rq
->ifr_ifru
.ifru_data
);
5950 case SIOC_QETH_GET_CARD_TYPE
:
5951 if ((card
->info
.type
== QETH_CARD_TYPE_OSD
||
5952 card
->info
.type
== QETH_CARD_TYPE_OSM
||
5953 card
->info
.type
== QETH_CARD_TYPE_OSX
) &&
5954 !card
->info
.guestlan
)
5959 mii_data
= if_mii(rq
);
5960 mii_data
->phy_id
= 0;
5963 mii_data
= if_mii(rq
);
5964 if (mii_data
->phy_id
!= 0)
5967 mii_data
->val_out
= qeth_mdio_read(dev
,
5968 mii_data
->phy_id
, mii_data
->reg_num
);
5970 case SIOC_QETH_QUERY_OAT
:
5971 rc
= qeth_query_oat_command(card
, rq
->ifr_ifru
.ifru_data
);
5974 if (card
->discipline
->do_ioctl
)
5975 rc
= card
->discipline
->do_ioctl(dev
, rq
, cmd
);
5980 QETH_CARD_TEXT_(card
, 2, "ioce%x", rc
);
5983 EXPORT_SYMBOL_GPL(qeth_do_ioctl
);
5986 const char str
[ETH_GSTRING_LEN
];
5987 } qeth_ethtool_stats_keys
[] = {
5992 {"tx skbs no packing"},
5993 {"tx buffers no packing"},
5994 {"tx skbs packing"},
5995 {"tx buffers packing"},
5998 /* 10 */{"rx sg skbs"},
6000 {"rx sg page allocs"},
6001 {"tx large kbytes"},
6003 {"tx pk state ch n->p"},
6004 {"tx pk state ch p->n"},
6005 {"tx pk watermark low"},
6006 {"tx pk watermark high"},
6007 {"queue 0 buffer usage"},
6008 /* 20 */{"queue 1 buffer usage"},
6009 {"queue 2 buffer usage"},
6010 {"queue 3 buffer usage"},
6013 {"rx do_QDIO time"},
6014 {"rx do_QDIO count"},
6015 {"tx handler time"},
6016 {"tx handler count"},
6018 /* 30 */{"tx count"},
6019 {"tx do_QDIO time"},
6020 {"tx do_QDIO count"},
6024 {"cq handler count"},
6028 int qeth_core_get_sset_count(struct net_device
*dev
, int stringset
)
6030 switch (stringset
) {
6032 return (sizeof(qeth_ethtool_stats_keys
) / ETH_GSTRING_LEN
);
6037 EXPORT_SYMBOL_GPL(qeth_core_get_sset_count
);
6039 void qeth_core_get_ethtool_stats(struct net_device
*dev
,
6040 struct ethtool_stats
*stats
, u64
*data
)
6042 struct qeth_card
*card
= dev
->ml_priv
;
6043 data
[0] = card
->stats
.rx_packets
-
6044 card
->perf_stats
.initial_rx_packets
;
6045 data
[1] = card
->perf_stats
.bufs_rec
;
6046 data
[2] = card
->stats
.tx_packets
-
6047 card
->perf_stats
.initial_tx_packets
;
6048 data
[3] = card
->perf_stats
.bufs_sent
;
6049 data
[4] = card
->stats
.tx_packets
- card
->perf_stats
.initial_tx_packets
6050 - card
->perf_stats
.skbs_sent_pack
;
6051 data
[5] = card
->perf_stats
.bufs_sent
- card
->perf_stats
.bufs_sent_pack
;
6052 data
[6] = card
->perf_stats
.skbs_sent_pack
;
6053 data
[7] = card
->perf_stats
.bufs_sent_pack
;
6054 data
[8] = card
->perf_stats
.sg_skbs_sent
;
6055 data
[9] = card
->perf_stats
.sg_frags_sent
;
6056 data
[10] = card
->perf_stats
.sg_skbs_rx
;
6057 data
[11] = card
->perf_stats
.sg_frags_rx
;
6058 data
[12] = card
->perf_stats
.sg_alloc_page_rx
;
6059 data
[13] = (card
->perf_stats
.large_send_bytes
>> 10);
6060 data
[14] = card
->perf_stats
.large_send_cnt
;
6061 data
[15] = card
->perf_stats
.sc_dp_p
;
6062 data
[16] = card
->perf_stats
.sc_p_dp
;
6063 data
[17] = QETH_LOW_WATERMARK_PACK
;
6064 data
[18] = QETH_HIGH_WATERMARK_PACK
;
6065 data
[19] = atomic_read(&card
->qdio
.out_qs
[0]->used_buffers
);
6066 data
[20] = (card
->qdio
.no_out_queues
> 1) ?
6067 atomic_read(&card
->qdio
.out_qs
[1]->used_buffers
) : 0;
6068 data
[21] = (card
->qdio
.no_out_queues
> 2) ?
6069 atomic_read(&card
->qdio
.out_qs
[2]->used_buffers
) : 0;
6070 data
[22] = (card
->qdio
.no_out_queues
> 3) ?
6071 atomic_read(&card
->qdio
.out_qs
[3]->used_buffers
) : 0;
6072 data
[23] = card
->perf_stats
.inbound_time
;
6073 data
[24] = card
->perf_stats
.inbound_cnt
;
6074 data
[25] = card
->perf_stats
.inbound_do_qdio_time
;
6075 data
[26] = card
->perf_stats
.inbound_do_qdio_cnt
;
6076 data
[27] = card
->perf_stats
.outbound_handler_time
;
6077 data
[28] = card
->perf_stats
.outbound_handler_cnt
;
6078 data
[29] = card
->perf_stats
.outbound_time
;
6079 data
[30] = card
->perf_stats
.outbound_cnt
;
6080 data
[31] = card
->perf_stats
.outbound_do_qdio_time
;
6081 data
[32] = card
->perf_stats
.outbound_do_qdio_cnt
;
6082 data
[33] = card
->perf_stats
.tx_csum
;
6083 data
[34] = card
->perf_stats
.tx_lin
;
6084 data
[35] = card
->perf_stats
.tx_linfail
;
6085 data
[36] = card
->perf_stats
.cq_cnt
;
6086 data
[37] = card
->perf_stats
.cq_time
;
6088 EXPORT_SYMBOL_GPL(qeth_core_get_ethtool_stats
);
6090 void qeth_core_get_strings(struct net_device
*dev
, u32 stringset
, u8
*data
)
6092 switch (stringset
) {
6094 memcpy(data
, &qeth_ethtool_stats_keys
,
6095 sizeof(qeth_ethtool_stats_keys
));
6102 EXPORT_SYMBOL_GPL(qeth_core_get_strings
);
6104 void qeth_core_get_drvinfo(struct net_device
*dev
,
6105 struct ethtool_drvinfo
*info
)
6107 struct qeth_card
*card
= dev
->ml_priv
;
6109 strlcpy(info
->driver
, card
->options
.layer2
? "qeth_l2" : "qeth_l3",
6110 sizeof(info
->driver
));
6111 strlcpy(info
->version
, "1.0", sizeof(info
->version
));
6112 strlcpy(info
->fw_version
, card
->info
.mcl_level
,
6113 sizeof(info
->fw_version
));
6114 snprintf(info
->bus_info
, sizeof(info
->bus_info
), "%s/%s/%s",
6115 CARD_RDEV_ID(card
), CARD_WDEV_ID(card
), CARD_DDEV_ID(card
));
6117 EXPORT_SYMBOL_GPL(qeth_core_get_drvinfo
);
6119 /* Helper function to fill 'advertising' and 'supported' which are the same. */
6120 /* Autoneg and full-duplex are supported and advertised unconditionally. */
6121 /* Always advertise and support all speeds up to specified, and only one */
6122 /* specified port type. */
6123 static void qeth_set_cmd_adv_sup(struct ethtool_link_ksettings
*cmd
,
6124 int maxspeed
, int porttype
)
6126 ethtool_link_ksettings_zero_link_mode(cmd
, supported
);
6127 ethtool_link_ksettings_zero_link_mode(cmd
, advertising
);
6128 ethtool_link_ksettings_zero_link_mode(cmd
, lp_advertising
);
6130 ethtool_link_ksettings_add_link_mode(cmd
, supported
, Autoneg
);
6131 ethtool_link_ksettings_add_link_mode(cmd
, advertising
, Autoneg
);
6135 ethtool_link_ksettings_add_link_mode(cmd
, supported
, TP
);
6136 ethtool_link_ksettings_add_link_mode(cmd
, advertising
, TP
);
6139 ethtool_link_ksettings_add_link_mode(cmd
, supported
, FIBRE
);
6140 ethtool_link_ksettings_add_link_mode(cmd
, advertising
, FIBRE
);
6143 ethtool_link_ksettings_add_link_mode(cmd
, supported
, TP
);
6144 ethtool_link_ksettings_add_link_mode(cmd
, advertising
, TP
);
6148 /* fallthrough from high to low, to select all legal speeds: */
6151 ethtool_link_ksettings_add_link_mode(cmd
, supported
,
6153 ethtool_link_ksettings_add_link_mode(cmd
, advertising
,
6156 ethtool_link_ksettings_add_link_mode(cmd
, supported
,
6158 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
,
6165 ethtool_link_ksettings_add_link_mode(cmd
, supported
,
6167 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
,
6174 ethtool_link_ksettings_add_link_mode(cmd
, supported
,
6176 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 /* end fallthrough */
6185 ethtool_link_ksettings_add_link_mode(cmd
, supported
,
6187 ethtool_link_ksettings_add_link_mode(cmd
, advertising
,
6189 ethtool_link_ksettings_add_link_mode(cmd
, supported
,
6191 ethtool_link_ksettings_add_link_mode(cmd
, advertising
,
6197 int qeth_core_ethtool_get_link_ksettings(struct net_device
*netdev
,
6198 struct ethtool_link_ksettings
*cmd
)
6200 struct qeth_card
*card
= netdev
->ml_priv
;
6201 enum qeth_link_types link_type
;
6202 struct carrier_info carrier_info
;
6205 if ((card
->info
.type
== QETH_CARD_TYPE_IQD
) || (card
->info
.guestlan
))
6206 link_type
= QETH_LINK_TYPE_10GBIT_ETH
;
6208 link_type
= card
->info
.link_type
;
6210 cmd
->base
.duplex
= DUPLEX_FULL
;
6211 cmd
->base
.autoneg
= AUTONEG_ENABLE
;
6212 cmd
->base
.phy_address
= 0;
6213 cmd
->base
.mdio_support
= 0;
6214 cmd
->base
.eth_tp_mdix
= ETH_TP_MDI_INVALID
;
6215 cmd
->base
.eth_tp_mdix_ctrl
= ETH_TP_MDI_INVALID
;
6217 switch (link_type
) {
6218 case QETH_LINK_TYPE_FAST_ETH
:
6219 case QETH_LINK_TYPE_LANE_ETH100
:
6220 cmd
->base
.speed
= SPEED_100
;
6221 cmd
->base
.port
= PORT_TP
;
6223 case QETH_LINK_TYPE_GBIT_ETH
:
6224 case QETH_LINK_TYPE_LANE_ETH1000
:
6225 cmd
->base
.speed
= SPEED_1000
;
6226 cmd
->base
.port
= PORT_FIBRE
;
6228 case QETH_LINK_TYPE_10GBIT_ETH
:
6229 cmd
->base
.speed
= SPEED_10000
;
6230 cmd
->base
.port
= PORT_FIBRE
;
6233 cmd
->base
.speed
= SPEED_10
;
6234 cmd
->base
.port
= PORT_TP
;
6236 qeth_set_cmd_adv_sup(cmd
, cmd
->base
.speed
, cmd
->base
.port
);
6238 /* Check if we can obtain more accurate information. */
6239 /* If QUERY_CARD_INFO command is not supported or fails, */
6240 /* just return the heuristics that was filled above. */
6241 if (!qeth_card_hw_is_reachable(card
))
6243 rc
= qeth_query_card_info(card
, &carrier_info
);
6244 if (rc
== -EOPNOTSUPP
) /* for old hardware, return heuristic */
6246 if (rc
) /* report error from the hardware operation */
6248 /* on success, fill in the information got from the hardware */
6251 "card info: card_type=0x%02x, port_mode=0x%04x, port_speed=0x%08x\n",
6252 carrier_info
.card_type
,
6253 carrier_info
.port_mode
,
6254 carrier_info
.port_speed
);
6256 /* Update attributes for which we've obtained more authoritative */
6257 /* information, leave the rest the way they where filled above. */
6258 switch (carrier_info
.card_type
) {
6259 case CARD_INFO_TYPE_1G_COPPER_A
:
6260 case CARD_INFO_TYPE_1G_COPPER_B
:
6261 cmd
->base
.port
= PORT_TP
;
6262 qeth_set_cmd_adv_sup(cmd
, SPEED_1000
, cmd
->base
.port
);
6264 case CARD_INFO_TYPE_1G_FIBRE_A
:
6265 case CARD_INFO_TYPE_1G_FIBRE_B
:
6266 cmd
->base
.port
= PORT_FIBRE
;
6267 qeth_set_cmd_adv_sup(cmd
, SPEED_1000
, cmd
->base
.port
);
6269 case CARD_INFO_TYPE_10G_FIBRE_A
:
6270 case CARD_INFO_TYPE_10G_FIBRE_B
:
6271 cmd
->base
.port
= PORT_FIBRE
;
6272 qeth_set_cmd_adv_sup(cmd
, SPEED_10000
, cmd
->base
.port
);
6276 switch (carrier_info
.port_mode
) {
6277 case CARD_INFO_PORTM_FULLDUPLEX
:
6278 cmd
->base
.duplex
= DUPLEX_FULL
;
6280 case CARD_INFO_PORTM_HALFDUPLEX
:
6281 cmd
->base
.duplex
= DUPLEX_HALF
;
6285 switch (carrier_info
.port_speed
) {
6286 case CARD_INFO_PORTS_10M
:
6287 cmd
->base
.speed
= SPEED_10
;
6289 case CARD_INFO_PORTS_100M
:
6290 cmd
->base
.speed
= SPEED_100
;
6292 case CARD_INFO_PORTS_1G
:
6293 cmd
->base
.speed
= SPEED_1000
;
6295 case CARD_INFO_PORTS_10G
:
6296 cmd
->base
.speed
= SPEED_10000
;
6302 EXPORT_SYMBOL_GPL(qeth_core_ethtool_get_link_ksettings
);
6304 /* Callback to handle checksum offload command reply from OSA card.
6305 * Verify that required features have been enabled on the card.
6306 * Return error in hdr->return_code as this value is checked by caller.
6308 * Always returns zero to indicate no further messages from the OSA card.
6310 static int qeth_ipa_checksum_run_cmd_cb(struct qeth_card
*card
,
6311 struct qeth_reply
*reply
,
6314 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
6315 struct qeth_checksum_cmd
*chksum_cb
=
6316 (struct qeth_checksum_cmd
*)reply
->param
;
6318 QETH_CARD_TEXT(card
, 4, "chkdoccb");
6319 if (qeth_setassparms_inspect_rc(cmd
))
6322 memset(chksum_cb
, 0, sizeof(*chksum_cb
));
6323 if (cmd
->data
.setassparms
.hdr
.command_code
== IPA_CMD_ASS_START
) {
6324 chksum_cb
->supported
=
6325 cmd
->data
.setassparms
.data
.chksum
.supported
;
6326 QETH_CARD_TEXT_(card
, 3, "strt:%x", chksum_cb
->supported
);
6328 if (cmd
->data
.setassparms
.hdr
.command_code
== IPA_CMD_ASS_ENABLE
) {
6329 chksum_cb
->supported
=
6330 cmd
->data
.setassparms
.data
.chksum
.supported
;
6331 chksum_cb
->enabled
=
6332 cmd
->data
.setassparms
.data
.chksum
.enabled
;
6333 QETH_CARD_TEXT_(card
, 3, "supp:%x", chksum_cb
->supported
);
6334 QETH_CARD_TEXT_(card
, 3, "enab:%x", chksum_cb
->enabled
);
6339 /* Send command to OSA card and check results. */
6340 static int qeth_ipa_checksum_run_cmd(struct qeth_card
*card
,
6341 enum qeth_ipa_funcs ipa_func
,
6342 __u16 cmd_code
, long data
,
6343 struct qeth_checksum_cmd
*chksum_cb
)
6345 struct qeth_cmd_buffer
*iob
;
6348 QETH_CARD_TEXT(card
, 4, "chkdocmd");
6349 iob
= qeth_get_setassparms_cmd(card
, ipa_func
, cmd_code
,
6350 sizeof(__u32
), QETH_PROT_IPV4
);
6352 rc
= qeth_send_setassparms(card
, iob
, sizeof(__u32
), data
,
6353 qeth_ipa_checksum_run_cmd_cb
,
6358 static int qeth_send_checksum_on(struct qeth_card
*card
, int cstype
)
6360 const __u32 required_features
= QETH_IPA_CHECKSUM_IP_HDR
|
6361 QETH_IPA_CHECKSUM_UDP
|
6362 QETH_IPA_CHECKSUM_TCP
;
6363 struct qeth_checksum_cmd chksum_cb
;
6366 rc
= qeth_ipa_checksum_run_cmd(card
, cstype
, IPA_CMD_ASS_START
, 0,
6369 if ((required_features
& chksum_cb
.supported
) !=
6372 else if (!(QETH_IPA_CHECKSUM_LP2LP
& chksum_cb
.supported
) &&
6373 cstype
== IPA_INBOUND_CHECKSUM
)
6374 dev_warn(&card
->gdev
->dev
,
6375 "Hardware checksumming is performed only if %s and its peer use different OSA Express 3 ports\n",
6376 QETH_CARD_IFNAME(card
));
6379 qeth_send_simple_setassparms(card
, cstype
, IPA_CMD_ASS_STOP
, 0);
6380 dev_warn(&card
->gdev
->dev
,
6381 "Starting HW checksumming for %s failed, using SW checksumming\n",
6382 QETH_CARD_IFNAME(card
));
6385 rc
= qeth_ipa_checksum_run_cmd(card
, cstype
, IPA_CMD_ASS_ENABLE
,
6386 chksum_cb
.supported
, &chksum_cb
);
6388 if ((required_features
& chksum_cb
.enabled
) !=
6393 qeth_send_simple_setassparms(card
, cstype
, IPA_CMD_ASS_STOP
, 0);
6394 dev_warn(&card
->gdev
->dev
,
6395 "Enabling HW checksumming for %s failed, using SW checksumming\n",
6396 QETH_CARD_IFNAME(card
));
6400 dev_info(&card
->gdev
->dev
, "HW Checksumming (%sbound) enabled\n",
6401 cstype
== IPA_INBOUND_CHECKSUM
? "in" : "out");
6405 static int qeth_set_ipa_csum(struct qeth_card
*card
, int on
, int cstype
)
6407 int rc
= (on
) ? qeth_send_checksum_on(card
, cstype
)
6408 : qeth_send_simple_setassparms(card
, cstype
,
6409 IPA_CMD_ASS_STOP
, 0);
6410 return rc
? -EIO
: 0;
6413 static int qeth_set_ipa_tso(struct qeth_card
*card
, int on
)
6417 QETH_CARD_TEXT(card
, 3, "sttso");
6420 rc
= qeth_send_simple_setassparms(card
, IPA_OUTBOUND_TSO
,
6421 IPA_CMD_ASS_START
, 0);
6423 dev_warn(&card
->gdev
->dev
,
6424 "Starting outbound TCP segmentation offload for %s failed\n",
6425 QETH_CARD_IFNAME(card
));
6428 dev_info(&card
->gdev
->dev
, "Outbound TSO enabled\n");
6430 rc
= qeth_send_simple_setassparms(card
, IPA_OUTBOUND_TSO
,
6431 IPA_CMD_ASS_STOP
, 0);
6436 #define QETH_HW_FEATURES (NETIF_F_RXCSUM | NETIF_F_IP_CSUM | NETIF_F_TSO)
6439 * qeth_recover_features() - Restore device features after recovery
6440 * @dev: the recovering net_device
6442 * Caller must hold rtnl lock.
6444 void qeth_recover_features(struct net_device
*dev
)
6446 netdev_features_t features
= dev
->features
;
6447 struct qeth_card
*card
= dev
->ml_priv
;
6449 /* force-off any feature that needs an IPA sequence.
6450 * netdev_update_features() will restart them.
6452 dev
->features
&= ~QETH_HW_FEATURES
;
6453 netdev_update_features(dev
);
6455 if (features
== dev
->features
)
6457 dev_warn(&card
->gdev
->dev
,
6458 "Device recovery failed to restore all offload features\n");
6460 EXPORT_SYMBOL_GPL(qeth_recover_features
);
6462 int qeth_set_features(struct net_device
*dev
, netdev_features_t features
)
6464 struct qeth_card
*card
= dev
->ml_priv
;
6465 netdev_features_t changed
= dev
->features
^ features
;
6468 QETH_DBF_TEXT(SETUP
, 2, "setfeat");
6469 QETH_DBF_HEX(SETUP
, 2, &features
, sizeof(features
));
6471 if ((changed
& NETIF_F_IP_CSUM
)) {
6472 rc
= qeth_set_ipa_csum(card
,
6473 features
& NETIF_F_IP_CSUM
? 1 : 0,
6474 IPA_OUTBOUND_CHECKSUM
);
6476 changed
^= NETIF_F_IP_CSUM
;
6478 if ((changed
& NETIF_F_RXCSUM
)) {
6479 rc
= qeth_set_ipa_csum(card
,
6480 features
& NETIF_F_RXCSUM
? 1 : 0,
6481 IPA_INBOUND_CHECKSUM
);
6483 changed
^= NETIF_F_RXCSUM
;
6485 if ((changed
& NETIF_F_TSO
)) {
6486 rc
= qeth_set_ipa_tso(card
, features
& NETIF_F_TSO
? 1 : 0);
6488 changed
^= NETIF_F_TSO
;
6491 /* everything changed successfully? */
6492 if ((dev
->features
^ features
) == changed
)
6494 /* something went wrong. save changed features and return error */
6495 dev
->features
^= changed
;
6498 EXPORT_SYMBOL_GPL(qeth_set_features
);
6500 netdev_features_t
qeth_fix_features(struct net_device
*dev
,
6501 netdev_features_t features
)
6503 struct qeth_card
*card
= dev
->ml_priv
;
6505 QETH_DBF_TEXT(SETUP
, 2, "fixfeat");
6506 if (!qeth_is_supported(card
, IPA_OUTBOUND_CHECKSUM
))
6507 features
&= ~NETIF_F_IP_CSUM
;
6508 if (!qeth_is_supported(card
, IPA_INBOUND_CHECKSUM
))
6509 features
&= ~NETIF_F_RXCSUM
;
6510 if (!qeth_is_supported(card
, IPA_OUTBOUND_TSO
))
6511 features
&= ~NETIF_F_TSO
;
6512 /* if the card isn't up, remove features that require hw changes */
6513 if (card
->state
== CARD_STATE_DOWN
||
6514 card
->state
== CARD_STATE_RECOVER
)
6515 features
&= ~QETH_HW_FEATURES
;
6516 QETH_DBF_HEX(SETUP
, 2, &features
, sizeof(features
));
6519 EXPORT_SYMBOL_GPL(qeth_fix_features
);
6521 netdev_features_t
qeth_features_check(struct sk_buff
*skb
,
6522 struct net_device
*dev
,
6523 netdev_features_t features
)
6525 /* GSO segmentation builds skbs with
6526 * a (small) linear part for the headers, and
6527 * page frags for the data.
6528 * Compared to a linear skb, the header-only part consumes an
6529 * additional buffer element. This reduces buffer utilization, and
6530 * hurts throughput. So compress small segments into one element.
6532 if (netif_needs_gso(skb
, features
)) {
6533 /* match skb_segment(): */
6534 unsigned int doffset
= skb
->data
- skb_mac_header(skb
);
6535 unsigned int hsize
= skb_shinfo(skb
)->gso_size
;
6536 unsigned int hroom
= skb_headroom(skb
);
6538 /* linearize only if resulting skb allocations are order-0: */
6539 if (SKB_DATA_ALIGN(hroom
+ doffset
+ hsize
) <= SKB_MAX_HEAD(0))
6540 features
&= ~NETIF_F_SG
;
6543 return vlan_features_check(skb
, features
);
6545 EXPORT_SYMBOL_GPL(qeth_features_check
);
6547 static int __init
qeth_core_init(void)
6551 pr_info("loading core functions\n");
6552 INIT_LIST_HEAD(&qeth_core_card_list
.list
);
6553 INIT_LIST_HEAD(&qeth_dbf_list
);
6554 rwlock_init(&qeth_core_card_list
.rwlock
);
6555 mutex_init(&qeth_mod_mutex
);
6557 qeth_wq
= create_singlethread_workqueue("qeth_wq");
6559 rc
= qeth_register_dbf_views();
6562 qeth_core_root_dev
= root_device_register("qeth");
6563 rc
= PTR_ERR_OR_ZERO(qeth_core_root_dev
);
6566 qeth_core_header_cache
= kmem_cache_create("qeth_hdr",
6567 sizeof(struct qeth_hdr
) + ETH_HLEN
, 64, 0, NULL
);
6568 if (!qeth_core_header_cache
) {
6572 qeth_qdio_outbuf_cache
= kmem_cache_create("qeth_buf",
6573 sizeof(struct qeth_qdio_out_buffer
), 0, 0, NULL
);
6574 if (!qeth_qdio_outbuf_cache
) {
6578 rc
= ccw_driver_register(&qeth_ccw_driver
);
6581 qeth_core_ccwgroup_driver
.driver
.groups
= qeth_drv_attr_groups
;
6582 rc
= ccwgroup_driver_register(&qeth_core_ccwgroup_driver
);
6589 ccw_driver_unregister(&qeth_ccw_driver
);
6591 kmem_cache_destroy(qeth_qdio_outbuf_cache
);
6593 kmem_cache_destroy(qeth_core_header_cache
);
6595 root_device_unregister(qeth_core_root_dev
);
6597 qeth_unregister_dbf_views();
6599 pr_err("Initializing the qeth device driver failed\n");
6603 static void __exit
qeth_core_exit(void)
6605 qeth_clear_dbf_list();
6606 destroy_workqueue(qeth_wq
);
6607 ccwgroup_driver_unregister(&qeth_core_ccwgroup_driver
);
6608 ccw_driver_unregister(&qeth_ccw_driver
);
6609 kmem_cache_destroy(qeth_qdio_outbuf_cache
);
6610 kmem_cache_destroy(qeth_core_header_cache
);
6611 root_device_unregister(qeth_core_root_dev
);
6612 qeth_unregister_dbf_views();
6613 pr_info("core functions removed\n");
6616 module_init(qeth_core_init
);
6617 module_exit(qeth_core_exit
);
6618 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
6619 MODULE_DESCRIPTION("qeth core functions");
6620 MODULE_LICENSE("GPL");