2 * Copyright IBM Corp. 2007, 2009
3 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
4 * Frank Pavlic <fpavlic@de.ibm.com>,
5 * Thomas Spatzier <tspat@de.ibm.com>,
6 * Frank Blaschka <frank.blaschka@de.ibm.com>
9 #define KMSG_COMPONENT "qeth"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/module.h>
13 #include <linux/moduleparam.h>
14 #include <linux/string.h>
15 #include <linux/errno.h>
16 #include <linux/kernel.h>
18 #include <linux/tcp.h>
19 #include <linux/mii.h>
20 #include <linux/kthread.h>
21 #include <linux/slab.h>
22 #include <net/iucv/af_iucv.h>
23 #include <net/dsfield.h>
25 #include <asm/ebcdic.h>
26 #include <asm/chpid.h>
28 #include <asm/sysinfo.h>
29 #include <asm/compat.h>
31 #include "qeth_core.h"
33 struct qeth_dbf_info qeth_dbf
[QETH_DBF_INFOS
] = {
34 /* define dbf - Name, Pages, Areas, Maxlen, Level, View, Handle */
36 [QETH_DBF_SETUP
] = {"qeth_setup",
37 8, 1, 8, 5, &debug_hex_ascii_view
, NULL
},
38 [QETH_DBF_MSG
] = {"qeth_msg", 8, 1, 11 * sizeof(long), 3,
39 &debug_sprintf_view
, NULL
},
40 [QETH_DBF_CTRL
] = {"qeth_control",
41 8, 1, QETH_DBF_CTRL_LEN
, 5, &debug_hex_ascii_view
, NULL
},
43 EXPORT_SYMBOL_GPL(qeth_dbf
);
45 struct qeth_card_list_struct qeth_core_card_list
;
46 EXPORT_SYMBOL_GPL(qeth_core_card_list
);
47 struct kmem_cache
*qeth_core_header_cache
;
48 EXPORT_SYMBOL_GPL(qeth_core_header_cache
);
49 static struct kmem_cache
*qeth_qdio_outbuf_cache
;
51 static struct device
*qeth_core_root_dev
;
52 static unsigned int known_devices
[][6] = QETH_MODELLIST_ARRAY
;
53 static struct lock_class_key qdio_out_skb_queue_key
;
54 static struct mutex qeth_mod_mutex
;
56 static void qeth_send_control_data_cb(struct qeth_channel
*,
57 struct qeth_cmd_buffer
*);
58 static int qeth_issue_next_read(struct qeth_card
*);
59 static struct qeth_cmd_buffer
*qeth_get_buffer(struct qeth_channel
*);
60 static void qeth_setup_ccw(struct qeth_channel
*, unsigned char *, __u32
);
61 static void qeth_free_buffer_pool(struct qeth_card
*);
62 static int qeth_qdio_establish(struct qeth_card
*);
63 static void qeth_free_qdio_buffers(struct qeth_card
*);
64 static void qeth_notify_skbs(struct qeth_qdio_out_q
*queue
,
65 struct qeth_qdio_out_buffer
*buf
,
66 enum iucv_tx_notify notification
);
67 static void qeth_release_skbs(struct qeth_qdio_out_buffer
*buf
);
68 static void qeth_clear_output_buffer(struct qeth_qdio_out_q
*queue
,
69 struct qeth_qdio_out_buffer
*buf
,
70 enum qeth_qdio_buffer_states newbufstate
);
71 static int qeth_init_qdio_out_buf(struct qeth_qdio_out_q
*, int);
73 struct workqueue_struct
*qeth_wq
;
74 EXPORT_SYMBOL_GPL(qeth_wq
);
76 int qeth_card_hw_is_reachable(struct qeth_card
*card
)
78 return (card
->state
== CARD_STATE_SOFTSETUP
) ||
79 (card
->state
== CARD_STATE_UP
);
81 EXPORT_SYMBOL_GPL(qeth_card_hw_is_reachable
);
83 static void qeth_close_dev_handler(struct work_struct
*work
)
85 struct qeth_card
*card
;
87 card
= container_of(work
, struct qeth_card
, close_dev_work
);
88 QETH_CARD_TEXT(card
, 2, "cldevhdl");
92 ccwgroup_set_offline(card
->gdev
);
95 void qeth_close_dev(struct qeth_card
*card
)
97 QETH_CARD_TEXT(card
, 2, "cldevsubm");
98 queue_work(qeth_wq
, &card
->close_dev_work
);
100 EXPORT_SYMBOL_GPL(qeth_close_dev
);
102 static inline const char *qeth_get_cardname(struct qeth_card
*card
)
104 if (card
->info
.guestlan
) {
105 switch (card
->info
.type
) {
106 case QETH_CARD_TYPE_OSD
:
107 return " Virtual NIC QDIO";
108 case QETH_CARD_TYPE_IQD
:
109 return " Virtual NIC Hiper";
110 case QETH_CARD_TYPE_OSM
:
111 return " Virtual NIC QDIO - OSM";
112 case QETH_CARD_TYPE_OSX
:
113 return " Virtual NIC QDIO - OSX";
118 switch (card
->info
.type
) {
119 case QETH_CARD_TYPE_OSD
:
120 return " OSD Express";
121 case QETH_CARD_TYPE_IQD
:
122 return " HiperSockets";
123 case QETH_CARD_TYPE_OSN
:
125 case QETH_CARD_TYPE_OSM
:
127 case QETH_CARD_TYPE_OSX
:
136 /* max length to be returned: 14 */
137 const char *qeth_get_cardname_short(struct qeth_card
*card
)
139 if (card
->info
.guestlan
) {
140 switch (card
->info
.type
) {
141 case QETH_CARD_TYPE_OSD
:
142 return "Virt.NIC QDIO";
143 case QETH_CARD_TYPE_IQD
:
144 return "Virt.NIC Hiper";
145 case QETH_CARD_TYPE_OSM
:
146 return "Virt.NIC OSM";
147 case QETH_CARD_TYPE_OSX
:
148 return "Virt.NIC OSX";
153 switch (card
->info
.type
) {
154 case QETH_CARD_TYPE_OSD
:
155 switch (card
->info
.link_type
) {
156 case QETH_LINK_TYPE_FAST_ETH
:
158 case QETH_LINK_TYPE_HSTR
:
160 case QETH_LINK_TYPE_GBIT_ETH
:
162 case QETH_LINK_TYPE_10GBIT_ETH
:
164 case QETH_LINK_TYPE_LANE_ETH100
:
165 return "OSD_FE_LANE";
166 case QETH_LINK_TYPE_LANE_TR
:
167 return "OSD_TR_LANE";
168 case QETH_LINK_TYPE_LANE_ETH1000
:
169 return "OSD_GbE_LANE";
170 case QETH_LINK_TYPE_LANE
:
171 return "OSD_ATM_LANE";
173 return "OSD_Express";
175 case QETH_CARD_TYPE_IQD
:
176 return "HiperSockets";
177 case QETH_CARD_TYPE_OSN
:
179 case QETH_CARD_TYPE_OSM
:
181 case QETH_CARD_TYPE_OSX
:
190 void qeth_set_recovery_task(struct qeth_card
*card
)
192 card
->recovery_task
= current
;
194 EXPORT_SYMBOL_GPL(qeth_set_recovery_task
);
196 void qeth_clear_recovery_task(struct qeth_card
*card
)
198 card
->recovery_task
= NULL
;
200 EXPORT_SYMBOL_GPL(qeth_clear_recovery_task
);
202 static bool qeth_is_recovery_task(const struct qeth_card
*card
)
204 return card
->recovery_task
== current
;
207 void qeth_set_allowed_threads(struct qeth_card
*card
, unsigned long threads
,
208 int clear_start_mask
)
212 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
213 card
->thread_allowed_mask
= threads
;
214 if (clear_start_mask
)
215 card
->thread_start_mask
&= threads
;
216 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
217 wake_up(&card
->wait_q
);
219 EXPORT_SYMBOL_GPL(qeth_set_allowed_threads
);
221 int qeth_threads_running(struct qeth_card
*card
, unsigned long threads
)
226 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
227 rc
= (card
->thread_running_mask
& threads
);
228 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
231 EXPORT_SYMBOL_GPL(qeth_threads_running
);
233 int qeth_wait_for_threads(struct qeth_card
*card
, unsigned long threads
)
235 if (qeth_is_recovery_task(card
))
237 return wait_event_interruptible(card
->wait_q
,
238 qeth_threads_running(card
, threads
) == 0);
240 EXPORT_SYMBOL_GPL(qeth_wait_for_threads
);
242 void qeth_clear_working_pool_list(struct qeth_card
*card
)
244 struct qeth_buffer_pool_entry
*pool_entry
, *tmp
;
246 QETH_CARD_TEXT(card
, 5, "clwrklst");
247 list_for_each_entry_safe(pool_entry
, tmp
,
248 &card
->qdio
.in_buf_pool
.entry_list
, list
){
249 list_del(&pool_entry
->list
);
252 EXPORT_SYMBOL_GPL(qeth_clear_working_pool_list
);
254 static int qeth_alloc_buffer_pool(struct qeth_card
*card
)
256 struct qeth_buffer_pool_entry
*pool_entry
;
260 QETH_CARD_TEXT(card
, 5, "alocpool");
261 for (i
= 0; i
< card
->qdio
.init_pool
.buf_count
; ++i
) {
262 pool_entry
= kzalloc(sizeof(*pool_entry
), GFP_KERNEL
);
264 qeth_free_buffer_pool(card
);
267 for (j
= 0; j
< QETH_MAX_BUFFER_ELEMENTS(card
); ++j
) {
268 ptr
= (void *) __get_free_page(GFP_KERNEL
);
271 free_page((unsigned long)
272 pool_entry
->elements
[--j
]);
274 qeth_free_buffer_pool(card
);
277 pool_entry
->elements
[j
] = ptr
;
279 list_add(&pool_entry
->init_list
,
280 &card
->qdio
.init_pool
.entry_list
);
285 int qeth_realloc_buffer_pool(struct qeth_card
*card
, int bufcnt
)
287 QETH_CARD_TEXT(card
, 2, "realcbp");
289 if ((card
->state
!= CARD_STATE_DOWN
) &&
290 (card
->state
!= CARD_STATE_RECOVER
))
293 /* TODO: steel/add buffers from/to a running card's buffer pool (?) */
294 qeth_clear_working_pool_list(card
);
295 qeth_free_buffer_pool(card
);
296 card
->qdio
.in_buf_pool
.buf_count
= bufcnt
;
297 card
->qdio
.init_pool
.buf_count
= bufcnt
;
298 return qeth_alloc_buffer_pool(card
);
300 EXPORT_SYMBOL_GPL(qeth_realloc_buffer_pool
);
302 static void qeth_free_qdio_queue(struct qeth_qdio_q
*q
)
307 qdio_free_buffers(q
->qdio_bufs
, QDIO_MAX_BUFFERS_PER_Q
);
311 static struct qeth_qdio_q
*qeth_alloc_qdio_queue(void)
313 struct qeth_qdio_q
*q
= kzalloc(sizeof(*q
), GFP_KERNEL
);
319 if (qdio_alloc_buffers(q
->qdio_bufs
, QDIO_MAX_BUFFERS_PER_Q
)) {
324 for (i
= 0; i
< QDIO_MAX_BUFFERS_PER_Q
; ++i
)
325 q
->bufs
[i
].buffer
= q
->qdio_bufs
[i
];
327 QETH_DBF_HEX(SETUP
, 2, &q
, sizeof(void *));
331 static inline int qeth_cq_init(struct qeth_card
*card
)
335 if (card
->options
.cq
== QETH_CQ_ENABLED
) {
336 QETH_DBF_TEXT(SETUP
, 2, "cqinit");
337 qdio_reset_buffers(card
->qdio
.c_q
->qdio_bufs
,
338 QDIO_MAX_BUFFERS_PER_Q
);
339 card
->qdio
.c_q
->next_buf_to_init
= 127;
340 rc
= do_QDIO(CARD_DDEV(card
), QDIO_FLAG_SYNC_INPUT
,
341 card
->qdio
.no_in_queues
- 1, 0,
344 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
353 static inline int qeth_alloc_cq(struct qeth_card
*card
)
357 if (card
->options
.cq
== QETH_CQ_ENABLED
) {
359 struct qdio_outbuf_state
*outbuf_states
;
361 QETH_DBF_TEXT(SETUP
, 2, "cqon");
362 card
->qdio
.c_q
= qeth_alloc_qdio_queue();
363 if (!card
->qdio
.c_q
) {
367 card
->qdio
.no_in_queues
= 2;
368 card
->qdio
.out_bufstates
=
369 kzalloc(card
->qdio
.no_out_queues
*
370 QDIO_MAX_BUFFERS_PER_Q
*
371 sizeof(struct qdio_outbuf_state
), GFP_KERNEL
);
372 outbuf_states
= card
->qdio
.out_bufstates
;
373 if (outbuf_states
== NULL
) {
377 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
378 card
->qdio
.out_qs
[i
]->bufstates
= outbuf_states
;
379 outbuf_states
+= QDIO_MAX_BUFFERS_PER_Q
;
382 QETH_DBF_TEXT(SETUP
, 2, "nocq");
383 card
->qdio
.c_q
= NULL
;
384 card
->qdio
.no_in_queues
= 1;
386 QETH_DBF_TEXT_(SETUP
, 2, "iqc%d", card
->qdio
.no_in_queues
);
391 qeth_free_qdio_queue(card
->qdio
.c_q
);
392 card
->qdio
.c_q
= NULL
;
394 dev_err(&card
->gdev
->dev
, "Failed to create completion queue\n");
398 static inline void qeth_free_cq(struct qeth_card
*card
)
400 if (card
->qdio
.c_q
) {
401 --card
->qdio
.no_in_queues
;
402 qeth_free_qdio_queue(card
->qdio
.c_q
);
403 card
->qdio
.c_q
= NULL
;
405 kfree(card
->qdio
.out_bufstates
);
406 card
->qdio
.out_bufstates
= NULL
;
409 static inline enum iucv_tx_notify
qeth_compute_cq_notification(int sbalf15
,
411 enum iucv_tx_notify n
;
415 n
= delayed
? TX_NOTIFY_DELAYED_OK
: TX_NOTIFY_OK
;
421 n
= delayed
? TX_NOTIFY_DELAYED_UNREACHABLE
:
422 TX_NOTIFY_UNREACHABLE
;
425 n
= delayed
? TX_NOTIFY_DELAYED_GENERALERROR
:
426 TX_NOTIFY_GENERALERROR
;
433 static inline void qeth_cleanup_handled_pending(struct qeth_qdio_out_q
*q
,
434 int bidx
, int forced_cleanup
)
436 if (q
->card
->options
.cq
!= QETH_CQ_ENABLED
)
439 if (q
->bufs
[bidx
]->next_pending
!= NULL
) {
440 struct qeth_qdio_out_buffer
*head
= q
->bufs
[bidx
];
441 struct qeth_qdio_out_buffer
*c
= q
->bufs
[bidx
]->next_pending
;
444 if (forced_cleanup
||
445 atomic_read(&c
->state
) ==
446 QETH_QDIO_BUF_HANDLED_DELAYED
) {
447 struct qeth_qdio_out_buffer
*f
= c
;
448 QETH_CARD_TEXT(f
->q
->card
, 5, "fp");
449 QETH_CARD_TEXT_(f
->q
->card
, 5, "%lx", (long) f
);
450 /* release here to avoid interleaving between
451 outbound tasklet and inbound tasklet
452 regarding notifications and lifecycle */
453 qeth_release_skbs(c
);
456 WARN_ON_ONCE(head
->next_pending
!= f
);
457 head
->next_pending
= c
;
458 kmem_cache_free(qeth_qdio_outbuf_cache
, f
);
466 if (forced_cleanup
&& (atomic_read(&(q
->bufs
[bidx
]->state
)) ==
467 QETH_QDIO_BUF_HANDLED_DELAYED
)) {
468 /* for recovery situations */
469 q
->bufs
[bidx
]->aob
= q
->bufstates
[bidx
].aob
;
470 qeth_init_qdio_out_buf(q
, bidx
);
471 QETH_CARD_TEXT(q
->card
, 2, "clprecov");
476 static inline void qeth_qdio_handle_aob(struct qeth_card
*card
,
477 unsigned long phys_aob_addr
) {
479 struct qeth_qdio_out_buffer
*buffer
;
480 enum iucv_tx_notify notification
;
482 aob
= (struct qaob
*) phys_to_virt(phys_aob_addr
);
483 QETH_CARD_TEXT(card
, 5, "haob");
484 QETH_CARD_TEXT_(card
, 5, "%lx", phys_aob_addr
);
485 buffer
= (struct qeth_qdio_out_buffer
*) aob
->user1
;
486 QETH_CARD_TEXT_(card
, 5, "%lx", aob
->user1
);
488 if (atomic_cmpxchg(&buffer
->state
, QETH_QDIO_BUF_PRIMED
,
489 QETH_QDIO_BUF_IN_CQ
) == QETH_QDIO_BUF_PRIMED
) {
490 notification
= TX_NOTIFY_OK
;
492 WARN_ON_ONCE(atomic_read(&buffer
->state
) !=
493 QETH_QDIO_BUF_PENDING
);
494 atomic_set(&buffer
->state
, QETH_QDIO_BUF_IN_CQ
);
495 notification
= TX_NOTIFY_DELAYED_OK
;
498 if (aob
->aorc
!= 0) {
499 QETH_CARD_TEXT_(card
, 2, "aorc%02X", aob
->aorc
);
500 notification
= qeth_compute_cq_notification(aob
->aorc
, 1);
502 qeth_notify_skbs(buffer
->q
, buffer
, notification
);
505 qeth_clear_output_buffer(buffer
->q
, buffer
,
506 QETH_QDIO_BUF_HANDLED_DELAYED
);
508 /* from here on: do not touch buffer anymore */
509 qdio_release_aob(aob
);
512 static inline int qeth_is_cq(struct qeth_card
*card
, unsigned int queue
)
514 return card
->options
.cq
== QETH_CQ_ENABLED
&&
515 card
->qdio
.c_q
!= NULL
&&
517 queue
== card
->qdio
.no_in_queues
- 1;
521 static int qeth_issue_next_read(struct qeth_card
*card
)
524 struct qeth_cmd_buffer
*iob
;
526 QETH_CARD_TEXT(card
, 5, "issnxrd");
527 if (card
->read
.state
!= CH_STATE_UP
)
529 iob
= qeth_get_buffer(&card
->read
);
531 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
532 "failed to recover an error on the device\n");
533 QETH_DBF_MESSAGE(2, "%s issue_next_read failed: no iob "
534 "available\n", dev_name(&card
->gdev
->dev
));
537 qeth_setup_ccw(&card
->read
, iob
->data
, QETH_BUFSIZE
);
538 QETH_CARD_TEXT(card
, 6, "noirqpnd");
539 rc
= ccw_device_start(card
->read
.ccwdev
, &card
->read
.ccw
,
542 QETH_DBF_MESSAGE(2, "%s error in starting next read ccw! "
543 "rc=%i\n", dev_name(&card
->gdev
->dev
), rc
);
544 atomic_set(&card
->read
.irq_pending
, 0);
545 card
->read_or_write_problem
= 1;
546 qeth_schedule_recovery(card
);
547 wake_up(&card
->wait_q
);
552 static struct qeth_reply
*qeth_alloc_reply(struct qeth_card
*card
)
554 struct qeth_reply
*reply
;
556 reply
= kzalloc(sizeof(struct qeth_reply
), GFP_ATOMIC
);
558 atomic_set(&reply
->refcnt
, 1);
559 atomic_set(&reply
->received
, 0);
565 static void qeth_get_reply(struct qeth_reply
*reply
)
567 WARN_ON(atomic_read(&reply
->refcnt
) <= 0);
568 atomic_inc(&reply
->refcnt
);
571 static void qeth_put_reply(struct qeth_reply
*reply
)
573 WARN_ON(atomic_read(&reply
->refcnt
) <= 0);
574 if (atomic_dec_and_test(&reply
->refcnt
))
578 static void qeth_issue_ipa_msg(struct qeth_ipa_cmd
*cmd
, int rc
,
579 struct qeth_card
*card
)
582 int com
= cmd
->hdr
.command
;
583 ipa_name
= qeth_get_ipa_cmd_name(com
);
585 QETH_DBF_MESSAGE(2, "IPA: %s(x%X) for %s/%s returned "
587 ipa_name
, com
, dev_name(&card
->gdev
->dev
),
588 QETH_CARD_IFNAME(card
), rc
,
589 qeth_get_ipa_msg(rc
));
591 QETH_DBF_MESSAGE(5, "IPA: %s(x%X) for %s/%s succeeded\n",
592 ipa_name
, com
, dev_name(&card
->gdev
->dev
),
593 QETH_CARD_IFNAME(card
));
596 static struct qeth_ipa_cmd
*qeth_check_ipa_data(struct qeth_card
*card
,
597 struct qeth_cmd_buffer
*iob
)
599 struct qeth_ipa_cmd
*cmd
= NULL
;
601 QETH_CARD_TEXT(card
, 5, "chkipad");
602 if (IS_IPA(iob
->data
)) {
603 cmd
= (struct qeth_ipa_cmd
*) PDU_ENCAPSULATION(iob
->data
);
604 if (IS_IPA_REPLY(cmd
)) {
605 if (cmd
->hdr
.command
!= IPA_CMD_SETCCID
&&
606 cmd
->hdr
.command
!= IPA_CMD_DELCCID
&&
607 cmd
->hdr
.command
!= IPA_CMD_MODCCID
&&
608 cmd
->hdr
.command
!= IPA_CMD_SET_DIAG_ASS
)
609 qeth_issue_ipa_msg(cmd
,
610 cmd
->hdr
.return_code
, card
);
613 switch (cmd
->hdr
.command
) {
614 case IPA_CMD_STOPLAN
:
615 if (cmd
->hdr
.return_code
==
616 IPA_RC_VEPA_TO_VEB_TRANSITION
) {
617 dev_err(&card
->gdev
->dev
,
618 "Interface %s is down because the "
619 "adjacent port is no longer in "
620 "reflective relay mode\n",
621 QETH_CARD_IFNAME(card
));
622 qeth_close_dev(card
);
624 dev_warn(&card
->gdev
->dev
,
625 "The link for interface %s on CHPID"
627 QETH_CARD_IFNAME(card
),
629 qeth_issue_ipa_msg(cmd
,
630 cmd
->hdr
.return_code
, card
);
632 card
->lan_online
= 0;
633 if (card
->dev
&& netif_carrier_ok(card
->dev
))
634 netif_carrier_off(card
->dev
);
636 case IPA_CMD_STARTLAN
:
637 dev_info(&card
->gdev
->dev
,
638 "The link for %s on CHPID 0x%X has"
640 QETH_CARD_IFNAME(card
),
642 netif_carrier_on(card
->dev
);
643 card
->lan_online
= 1;
644 if (card
->info
.hwtrap
)
645 card
->info
.hwtrap
= 2;
646 qeth_schedule_recovery(card
);
648 case IPA_CMD_SETBRIDGEPORT_IQD
:
649 case IPA_CMD_SETBRIDGEPORT_OSA
:
650 case IPA_CMD_ADDRESS_CHANGE_NOTIF
:
651 if (card
->discipline
->control_event_handler
656 case IPA_CMD_MODCCID
:
658 case IPA_CMD_REGISTER_LOCAL_ADDR
:
659 QETH_CARD_TEXT(card
, 3, "irla");
661 case IPA_CMD_UNREGISTER_LOCAL_ADDR
:
662 QETH_CARD_TEXT(card
, 3, "urla");
665 QETH_DBF_MESSAGE(2, "Received data is IPA "
666 "but not a reply!\n");
674 void qeth_clear_ipacmd_list(struct qeth_card
*card
)
676 struct qeth_reply
*reply
, *r
;
679 QETH_CARD_TEXT(card
, 4, "clipalst");
681 spin_lock_irqsave(&card
->lock
, flags
);
682 list_for_each_entry_safe(reply
, r
, &card
->cmd_waiter_list
, list
) {
683 qeth_get_reply(reply
);
685 atomic_inc(&reply
->received
);
686 list_del_init(&reply
->list
);
687 wake_up(&reply
->wait_q
);
688 qeth_put_reply(reply
);
690 spin_unlock_irqrestore(&card
->lock
, flags
);
691 atomic_set(&card
->write
.irq_pending
, 0);
693 EXPORT_SYMBOL_GPL(qeth_clear_ipacmd_list
);
695 static int qeth_check_idx_response(struct qeth_card
*card
,
696 unsigned char *buffer
)
701 QETH_DBF_HEX(CTRL
, 2, buffer
, QETH_DBF_CTRL_LEN
);
702 if ((buffer
[2] & 0xc0) == 0xc0) {
703 QETH_DBF_MESSAGE(2, "received an IDX TERMINATE "
704 "with cause code 0x%02x%s\n",
706 ((buffer
[4] == 0x22) ?
707 " -- try another portname" : ""));
708 QETH_CARD_TEXT(card
, 2, "ckidxres");
709 QETH_CARD_TEXT(card
, 2, " idxterm");
710 QETH_CARD_TEXT_(card
, 2, " rc%d", -EIO
);
711 if (buffer
[4] == 0xf6) {
712 dev_err(&card
->gdev
->dev
,
713 "The qeth device is not configured "
714 "for the OSI layer required by z/VM\n");
722 static struct qeth_card
*CARD_FROM_CDEV(struct ccw_device
*cdev
)
724 struct qeth_card
*card
= dev_get_drvdata(&((struct ccwgroup_device
*)
725 dev_get_drvdata(&cdev
->dev
))->dev
);
729 static void qeth_setup_ccw(struct qeth_channel
*channel
, unsigned char *iob
,
732 struct qeth_card
*card
;
734 card
= CARD_FROM_CDEV(channel
->ccwdev
);
735 QETH_CARD_TEXT(card
, 4, "setupccw");
736 if (channel
== &card
->read
)
737 memcpy(&channel
->ccw
, READ_CCW
, sizeof(struct ccw1
));
739 memcpy(&channel
->ccw
, WRITE_CCW
, sizeof(struct ccw1
));
740 channel
->ccw
.count
= len
;
741 channel
->ccw
.cda
= (__u32
) __pa(iob
);
744 static struct qeth_cmd_buffer
*__qeth_get_buffer(struct qeth_channel
*channel
)
748 QETH_CARD_TEXT(CARD_FROM_CDEV(channel
->ccwdev
), 6, "getbuff");
749 index
= channel
->io_buf_no
;
751 if (channel
->iob
[index
].state
== BUF_STATE_FREE
) {
752 channel
->iob
[index
].state
= BUF_STATE_LOCKED
;
753 channel
->io_buf_no
= (channel
->io_buf_no
+ 1) %
755 memset(channel
->iob
[index
].data
, 0, QETH_BUFSIZE
);
756 return channel
->iob
+ index
;
758 index
= (index
+ 1) % QETH_CMD_BUFFER_NO
;
759 } while (index
!= channel
->io_buf_no
);
764 void qeth_release_buffer(struct qeth_channel
*channel
,
765 struct qeth_cmd_buffer
*iob
)
769 QETH_CARD_TEXT(CARD_FROM_CDEV(channel
->ccwdev
), 6, "relbuff");
770 spin_lock_irqsave(&channel
->iob_lock
, flags
);
771 memset(iob
->data
, 0, QETH_BUFSIZE
);
772 iob
->state
= BUF_STATE_FREE
;
773 iob
->callback
= qeth_send_control_data_cb
;
775 spin_unlock_irqrestore(&channel
->iob_lock
, flags
);
776 wake_up(&channel
->wait_q
);
778 EXPORT_SYMBOL_GPL(qeth_release_buffer
);
780 static struct qeth_cmd_buffer
*qeth_get_buffer(struct qeth_channel
*channel
)
782 struct qeth_cmd_buffer
*buffer
= NULL
;
785 spin_lock_irqsave(&channel
->iob_lock
, flags
);
786 buffer
= __qeth_get_buffer(channel
);
787 spin_unlock_irqrestore(&channel
->iob_lock
, flags
);
791 struct qeth_cmd_buffer
*qeth_wait_for_buffer(struct qeth_channel
*channel
)
793 struct qeth_cmd_buffer
*buffer
;
794 wait_event(channel
->wait_q
,
795 ((buffer
= qeth_get_buffer(channel
)) != NULL
));
798 EXPORT_SYMBOL_GPL(qeth_wait_for_buffer
);
800 void qeth_clear_cmd_buffers(struct qeth_channel
*channel
)
804 for (cnt
= 0; cnt
< QETH_CMD_BUFFER_NO
; cnt
++)
805 qeth_release_buffer(channel
, &channel
->iob
[cnt
]);
807 channel
->io_buf_no
= 0;
809 EXPORT_SYMBOL_GPL(qeth_clear_cmd_buffers
);
811 static void qeth_send_control_data_cb(struct qeth_channel
*channel
,
812 struct qeth_cmd_buffer
*iob
)
814 struct qeth_card
*card
;
815 struct qeth_reply
*reply
, *r
;
816 struct qeth_ipa_cmd
*cmd
;
821 card
= CARD_FROM_CDEV(channel
->ccwdev
);
822 QETH_CARD_TEXT(card
, 4, "sndctlcb");
823 rc
= qeth_check_idx_response(card
, iob
->data
);
828 qeth_clear_ipacmd_list(card
);
829 qeth_schedule_recovery(card
);
835 cmd
= qeth_check_ipa_data(card
, iob
);
836 if ((cmd
== NULL
) && (card
->state
!= CARD_STATE_DOWN
))
838 /*in case of OSN : check if cmd is set */
839 if (card
->info
.type
== QETH_CARD_TYPE_OSN
&&
841 cmd
->hdr
.command
!= IPA_CMD_STARTLAN
&&
842 card
->osn_info
.assist_cb
!= NULL
) {
843 card
->osn_info
.assist_cb(card
->dev
, cmd
);
847 spin_lock_irqsave(&card
->lock
, flags
);
848 list_for_each_entry_safe(reply
, r
, &card
->cmd_waiter_list
, list
) {
849 if ((reply
->seqno
== QETH_IDX_COMMAND_SEQNO
) ||
850 ((cmd
) && (reply
->seqno
== cmd
->hdr
.seqno
))) {
851 qeth_get_reply(reply
);
852 list_del_init(&reply
->list
);
853 spin_unlock_irqrestore(&card
->lock
, flags
);
855 if (reply
->callback
!= NULL
) {
857 reply
->offset
= (__u16
)((char *)cmd
-
859 keep_reply
= reply
->callback(card
,
863 keep_reply
= reply
->callback(card
,
868 reply
->rc
= (u16
) cmd
->hdr
.return_code
;
872 spin_lock_irqsave(&card
->lock
, flags
);
873 list_add_tail(&reply
->list
,
874 &card
->cmd_waiter_list
);
875 spin_unlock_irqrestore(&card
->lock
, flags
);
877 atomic_inc(&reply
->received
);
878 wake_up(&reply
->wait_q
);
880 qeth_put_reply(reply
);
884 spin_unlock_irqrestore(&card
->lock
, flags
);
886 memcpy(&card
->seqno
.pdu_hdr_ack
,
887 QETH_PDU_HEADER_SEQ_NO(iob
->data
),
889 qeth_release_buffer(channel
, iob
);
892 static int qeth_setup_channel(struct qeth_channel
*channel
)
896 QETH_DBF_TEXT(SETUP
, 2, "setupch");
897 for (cnt
= 0; cnt
< QETH_CMD_BUFFER_NO
; cnt
++) {
898 channel
->iob
[cnt
].data
=
899 kzalloc(QETH_BUFSIZE
, GFP_DMA
|GFP_KERNEL
);
900 if (channel
->iob
[cnt
].data
== NULL
)
902 channel
->iob
[cnt
].state
= BUF_STATE_FREE
;
903 channel
->iob
[cnt
].channel
= channel
;
904 channel
->iob
[cnt
].callback
= qeth_send_control_data_cb
;
905 channel
->iob
[cnt
].rc
= 0;
907 if (cnt
< QETH_CMD_BUFFER_NO
) {
909 kfree(channel
->iob
[cnt
].data
);
913 channel
->io_buf_no
= 0;
914 atomic_set(&channel
->irq_pending
, 0);
915 spin_lock_init(&channel
->iob_lock
);
917 init_waitqueue_head(&channel
->wait_q
);
921 static int qeth_set_thread_start_bit(struct qeth_card
*card
,
922 unsigned long thread
)
926 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
927 if (!(card
->thread_allowed_mask
& thread
) ||
928 (card
->thread_start_mask
& thread
)) {
929 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
932 card
->thread_start_mask
|= thread
;
933 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
937 void qeth_clear_thread_start_bit(struct qeth_card
*card
, unsigned long thread
)
941 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
942 card
->thread_start_mask
&= ~thread
;
943 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
944 wake_up(&card
->wait_q
);
946 EXPORT_SYMBOL_GPL(qeth_clear_thread_start_bit
);
948 void qeth_clear_thread_running_bit(struct qeth_card
*card
, unsigned long thread
)
952 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
953 card
->thread_running_mask
&= ~thread
;
954 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
955 wake_up(&card
->wait_q
);
957 EXPORT_SYMBOL_GPL(qeth_clear_thread_running_bit
);
959 static int __qeth_do_run_thread(struct qeth_card
*card
, unsigned long thread
)
964 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
965 if (card
->thread_start_mask
& thread
) {
966 if ((card
->thread_allowed_mask
& thread
) &&
967 !(card
->thread_running_mask
& thread
)) {
969 card
->thread_start_mask
&= ~thread
;
970 card
->thread_running_mask
|= thread
;
974 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
978 int qeth_do_run_thread(struct qeth_card
*card
, unsigned long thread
)
982 wait_event(card
->wait_q
,
983 (rc
= __qeth_do_run_thread(card
, thread
)) >= 0);
986 EXPORT_SYMBOL_GPL(qeth_do_run_thread
);
988 void qeth_schedule_recovery(struct qeth_card
*card
)
990 QETH_CARD_TEXT(card
, 2, "startrec");
991 if (qeth_set_thread_start_bit(card
, QETH_RECOVER_THREAD
) == 0)
992 schedule_work(&card
->kernel_thread_starter
);
994 EXPORT_SYMBOL_GPL(qeth_schedule_recovery
);
996 static int qeth_get_problem(struct ccw_device
*cdev
, struct irb
*irb
)
1000 struct qeth_card
*card
;
1002 sense
= (char *) irb
->ecw
;
1003 cstat
= irb
->scsw
.cmd
.cstat
;
1004 dstat
= irb
->scsw
.cmd
.dstat
;
1005 card
= CARD_FROM_CDEV(cdev
);
1007 if (cstat
& (SCHN_STAT_CHN_CTRL_CHK
| SCHN_STAT_INTF_CTRL_CHK
|
1008 SCHN_STAT_CHN_DATA_CHK
| SCHN_STAT_CHAIN_CHECK
|
1009 SCHN_STAT_PROT_CHECK
| SCHN_STAT_PROG_CHECK
)) {
1010 QETH_CARD_TEXT(card
, 2, "CGENCHK");
1011 dev_warn(&cdev
->dev
, "The qeth device driver "
1012 "failed to recover an error on the device\n");
1013 QETH_DBF_MESSAGE(2, "%s check on device dstat=x%x, cstat=x%x\n",
1014 dev_name(&cdev
->dev
), dstat
, cstat
);
1015 print_hex_dump(KERN_WARNING
, "qeth: irb ", DUMP_PREFIX_OFFSET
,
1020 if (dstat
& DEV_STAT_UNIT_CHECK
) {
1021 if (sense
[SENSE_RESETTING_EVENT_BYTE
] &
1022 SENSE_RESETTING_EVENT_FLAG
) {
1023 QETH_CARD_TEXT(card
, 2, "REVIND");
1026 if (sense
[SENSE_COMMAND_REJECT_BYTE
] &
1027 SENSE_COMMAND_REJECT_FLAG
) {
1028 QETH_CARD_TEXT(card
, 2, "CMDREJi");
1031 if ((sense
[2] == 0xaf) && (sense
[3] == 0xfe)) {
1032 QETH_CARD_TEXT(card
, 2, "AFFE");
1035 if ((!sense
[0]) && (!sense
[1]) && (!sense
[2]) && (!sense
[3])) {
1036 QETH_CARD_TEXT(card
, 2, "ZEROSEN");
1039 QETH_CARD_TEXT(card
, 2, "DGENCHK");
1045 static long __qeth_check_irb_error(struct ccw_device
*cdev
,
1046 unsigned long intparm
, struct irb
*irb
)
1048 struct qeth_card
*card
;
1050 card
= CARD_FROM_CDEV(cdev
);
1052 if (!card
|| !IS_ERR(irb
))
1055 switch (PTR_ERR(irb
)) {
1057 QETH_DBF_MESSAGE(2, "%s i/o-error on device\n",
1058 dev_name(&cdev
->dev
));
1059 QETH_CARD_TEXT(card
, 2, "ckirberr");
1060 QETH_CARD_TEXT_(card
, 2, " rc%d", -EIO
);
1063 dev_warn(&cdev
->dev
, "A hardware operation timed out"
1064 " on the device\n");
1065 QETH_CARD_TEXT(card
, 2, "ckirberr");
1066 QETH_CARD_TEXT_(card
, 2, " rc%d", -ETIMEDOUT
);
1067 if (intparm
== QETH_RCD_PARM
) {
1068 if (card
->data
.ccwdev
== cdev
) {
1069 card
->data
.state
= CH_STATE_DOWN
;
1070 wake_up(&card
->wait_q
);
1075 QETH_DBF_MESSAGE(2, "%s unknown error %ld on device\n",
1076 dev_name(&cdev
->dev
), PTR_ERR(irb
));
1077 QETH_CARD_TEXT(card
, 2, "ckirberr");
1078 QETH_CARD_TEXT(card
, 2, " rc???");
1080 return PTR_ERR(irb
);
1083 static void qeth_irq(struct ccw_device
*cdev
, unsigned long intparm
,
1088 struct qeth_cmd_buffer
*buffer
;
1089 struct qeth_channel
*channel
;
1090 struct qeth_card
*card
;
1091 struct qeth_cmd_buffer
*iob
;
1094 if (__qeth_check_irb_error(cdev
, intparm
, irb
))
1096 cstat
= irb
->scsw
.cmd
.cstat
;
1097 dstat
= irb
->scsw
.cmd
.dstat
;
1099 card
= CARD_FROM_CDEV(cdev
);
1103 QETH_CARD_TEXT(card
, 5, "irq");
1105 if (card
->read
.ccwdev
== cdev
) {
1106 channel
= &card
->read
;
1107 QETH_CARD_TEXT(card
, 5, "read");
1108 } else if (card
->write
.ccwdev
== cdev
) {
1109 channel
= &card
->write
;
1110 QETH_CARD_TEXT(card
, 5, "write");
1112 channel
= &card
->data
;
1113 QETH_CARD_TEXT(card
, 5, "data");
1115 atomic_set(&channel
->irq_pending
, 0);
1117 if (irb
->scsw
.cmd
.fctl
& (SCSW_FCTL_CLEAR_FUNC
))
1118 channel
->state
= CH_STATE_STOPPED
;
1120 if (irb
->scsw
.cmd
.fctl
& (SCSW_FCTL_HALT_FUNC
))
1121 channel
->state
= CH_STATE_HALTED
;
1123 /*let's wake up immediately on data channel*/
1124 if ((channel
== &card
->data
) && (intparm
!= 0) &&
1125 (intparm
!= QETH_RCD_PARM
))
1128 if (intparm
== QETH_CLEAR_CHANNEL_PARM
) {
1129 QETH_CARD_TEXT(card
, 6, "clrchpar");
1130 /* we don't have to handle this further */
1133 if (intparm
== QETH_HALT_CHANNEL_PARM
) {
1134 QETH_CARD_TEXT(card
, 6, "hltchpar");
1135 /* we don't have to handle this further */
1138 if ((dstat
& DEV_STAT_UNIT_EXCEP
) ||
1139 (dstat
& DEV_STAT_UNIT_CHECK
) ||
1141 if (irb
->esw
.esw0
.erw
.cons
) {
1142 dev_warn(&channel
->ccwdev
->dev
,
1143 "The qeth device driver failed to recover "
1144 "an error on the device\n");
1145 QETH_DBF_MESSAGE(2, "%s sense data available. cstat "
1146 "0x%X dstat 0x%X\n",
1147 dev_name(&channel
->ccwdev
->dev
), cstat
, dstat
);
1148 print_hex_dump(KERN_WARNING
, "qeth: irb ",
1149 DUMP_PREFIX_OFFSET
, 16, 1, irb
, 32, 1);
1150 print_hex_dump(KERN_WARNING
, "qeth: sense data ",
1151 DUMP_PREFIX_OFFSET
, 16, 1, irb
->ecw
, 32, 1);
1153 if (intparm
== QETH_RCD_PARM
) {
1154 channel
->state
= CH_STATE_DOWN
;
1157 rc
= qeth_get_problem(cdev
, irb
);
1159 qeth_clear_ipacmd_list(card
);
1160 qeth_schedule_recovery(card
);
1165 if (intparm
== QETH_RCD_PARM
) {
1166 channel
->state
= CH_STATE_RCD_DONE
;
1170 buffer
= (struct qeth_cmd_buffer
*) __va((addr_t
)intparm
);
1171 buffer
->state
= BUF_STATE_PROCESSED
;
1173 if (channel
== &card
->data
)
1175 if (channel
== &card
->read
&&
1176 channel
->state
== CH_STATE_UP
)
1177 qeth_issue_next_read(card
);
1180 index
= channel
->buf_no
;
1181 while (iob
[index
].state
== BUF_STATE_PROCESSED
) {
1182 if (iob
[index
].callback
!= NULL
)
1183 iob
[index
].callback(channel
, iob
+ index
);
1185 index
= (index
+ 1) % QETH_CMD_BUFFER_NO
;
1187 channel
->buf_no
= index
;
1189 wake_up(&card
->wait_q
);
1193 static void qeth_notify_skbs(struct qeth_qdio_out_q
*q
,
1194 struct qeth_qdio_out_buffer
*buf
,
1195 enum iucv_tx_notify notification
)
1197 struct sk_buff
*skb
;
1199 if (skb_queue_empty(&buf
->skb_list
))
1201 skb
= skb_peek(&buf
->skb_list
);
1203 QETH_CARD_TEXT_(q
->card
, 5, "skbn%d", notification
);
1204 QETH_CARD_TEXT_(q
->card
, 5, "%lx", (long) skb
);
1205 if (skb
->protocol
== ETH_P_AF_IUCV
) {
1207 struct iucv_sock
*iucv
= iucv_sk(skb
->sk
);
1208 iucv
->sk_txnotify(skb
, notification
);
1211 if (skb_queue_is_last(&buf
->skb_list
, skb
))
1214 skb
= skb_queue_next(&buf
->skb_list
, skb
);
1220 static void qeth_release_skbs(struct qeth_qdio_out_buffer
*buf
)
1222 struct sk_buff
*skb
;
1223 struct iucv_sock
*iucv
;
1224 int notify_general_error
= 0;
1226 if (atomic_read(&buf
->state
) == QETH_QDIO_BUF_PENDING
)
1227 notify_general_error
= 1;
1229 /* release may never happen from within CQ tasklet scope */
1230 WARN_ON_ONCE(atomic_read(&buf
->state
) == QETH_QDIO_BUF_IN_CQ
);
1232 skb
= skb_dequeue(&buf
->skb_list
);
1234 QETH_CARD_TEXT(buf
->q
->card
, 5, "skbr");
1235 QETH_CARD_TEXT_(buf
->q
->card
, 5, "%lx", (long) skb
);
1236 if (notify_general_error
&& skb
->protocol
== ETH_P_AF_IUCV
) {
1238 iucv
= iucv_sk(skb
->sk
);
1239 iucv
->sk_txnotify(skb
, TX_NOTIFY_GENERALERROR
);
1242 atomic_dec(&skb
->users
);
1243 dev_kfree_skb_any(skb
);
1244 skb
= skb_dequeue(&buf
->skb_list
);
1248 static void qeth_clear_output_buffer(struct qeth_qdio_out_q
*queue
,
1249 struct qeth_qdio_out_buffer
*buf
,
1250 enum qeth_qdio_buffer_states newbufstate
)
1254 /* is PCI flag set on buffer? */
1255 if (buf
->buffer
->element
[0].sflags
& SBAL_SFLAGS0_PCI_REQ
)
1256 atomic_dec(&queue
->set_pci_flags_count
);
1258 if (newbufstate
== QETH_QDIO_BUF_EMPTY
) {
1259 qeth_release_skbs(buf
);
1261 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(queue
->card
); ++i
) {
1262 if (buf
->buffer
->element
[i
].addr
&& buf
->is_header
[i
])
1263 kmem_cache_free(qeth_core_header_cache
,
1264 buf
->buffer
->element
[i
].addr
);
1265 buf
->is_header
[i
] = 0;
1266 buf
->buffer
->element
[i
].length
= 0;
1267 buf
->buffer
->element
[i
].addr
= NULL
;
1268 buf
->buffer
->element
[i
].eflags
= 0;
1269 buf
->buffer
->element
[i
].sflags
= 0;
1271 buf
->buffer
->element
[15].eflags
= 0;
1272 buf
->buffer
->element
[15].sflags
= 0;
1273 buf
->next_element_to_fill
= 0;
1274 atomic_set(&buf
->state
, newbufstate
);
1277 static void qeth_clear_outq_buffers(struct qeth_qdio_out_q
*q
, int free
)
1281 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
) {
1284 qeth_cleanup_handled_pending(q
, j
, 1);
1285 qeth_clear_output_buffer(q
, q
->bufs
[j
], QETH_QDIO_BUF_EMPTY
);
1287 kmem_cache_free(qeth_qdio_outbuf_cache
, q
->bufs
[j
]);
1293 void qeth_clear_qdio_buffers(struct qeth_card
*card
)
1297 QETH_CARD_TEXT(card
, 2, "clearqdbf");
1298 /* clear outbound buffers to free skbs */
1299 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
1300 if (card
->qdio
.out_qs
[i
]) {
1301 qeth_clear_outq_buffers(card
->qdio
.out_qs
[i
], 0);
1305 EXPORT_SYMBOL_GPL(qeth_clear_qdio_buffers
);
1307 static void qeth_free_buffer_pool(struct qeth_card
*card
)
1309 struct qeth_buffer_pool_entry
*pool_entry
, *tmp
;
1311 list_for_each_entry_safe(pool_entry
, tmp
,
1312 &card
->qdio
.init_pool
.entry_list
, init_list
){
1313 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(card
); ++i
)
1314 free_page((unsigned long)pool_entry
->elements
[i
]);
1315 list_del(&pool_entry
->init_list
);
1320 static void qeth_clean_channel(struct qeth_channel
*channel
)
1324 QETH_DBF_TEXT(SETUP
, 2, "freech");
1325 for (cnt
= 0; cnt
< QETH_CMD_BUFFER_NO
; cnt
++)
1326 kfree(channel
->iob
[cnt
].data
);
1329 static void qeth_set_single_write_queues(struct qeth_card
*card
)
1331 if ((atomic_read(&card
->qdio
.state
) != QETH_QDIO_UNINITIALIZED
) &&
1332 (card
->qdio
.no_out_queues
== 4))
1333 qeth_free_qdio_buffers(card
);
1335 card
->qdio
.no_out_queues
= 1;
1336 if (card
->qdio
.default_out_queue
!= 0)
1337 dev_info(&card
->gdev
->dev
, "Priority Queueing not supported\n");
1339 card
->qdio
.default_out_queue
= 0;
1342 static void qeth_set_multiple_write_queues(struct qeth_card
*card
)
1344 if ((atomic_read(&card
->qdio
.state
) != QETH_QDIO_UNINITIALIZED
) &&
1345 (card
->qdio
.no_out_queues
== 1)) {
1346 qeth_free_qdio_buffers(card
);
1347 card
->qdio
.default_out_queue
= 2;
1349 card
->qdio
.no_out_queues
= 4;
1352 static void qeth_update_from_chp_desc(struct qeth_card
*card
)
1354 struct ccw_device
*ccwdev
;
1355 struct channel_path_desc
*chp_dsc
;
1357 QETH_DBF_TEXT(SETUP
, 2, "chp_desc");
1359 ccwdev
= card
->data
.ccwdev
;
1360 chp_dsc
= ccw_device_get_chp_desc(ccwdev
, 0);
1364 card
->info
.func_level
= 0x4100 + chp_dsc
->desc
;
1365 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
1368 /* CHPP field bit 6 == 1 -> single queue */
1369 if ((chp_dsc
->chpp
& 0x02) == 0x02)
1370 qeth_set_single_write_queues(card
);
1372 qeth_set_multiple_write_queues(card
);
1375 QETH_DBF_TEXT_(SETUP
, 2, "nr:%x", card
->qdio
.no_out_queues
);
1376 QETH_DBF_TEXT_(SETUP
, 2, "lvl:%02x", card
->info
.func_level
);
1379 static void qeth_init_qdio_info(struct qeth_card
*card
)
1381 QETH_DBF_TEXT(SETUP
, 4, "intqdinf");
1382 atomic_set(&card
->qdio
.state
, QETH_QDIO_UNINITIALIZED
);
1384 card
->qdio
.in_buf_size
= QETH_IN_BUF_SIZE_DEFAULT
;
1385 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
1386 card
->qdio
.init_pool
.buf_count
= QETH_IN_BUF_COUNT_HSDEFAULT
;
1388 card
->qdio
.init_pool
.buf_count
= QETH_IN_BUF_COUNT_DEFAULT
;
1389 card
->qdio
.in_buf_pool
.buf_count
= card
->qdio
.init_pool
.buf_count
;
1390 INIT_LIST_HEAD(&card
->qdio
.in_buf_pool
.entry_list
);
1391 INIT_LIST_HEAD(&card
->qdio
.init_pool
.entry_list
);
1394 static void qeth_set_intial_options(struct qeth_card
*card
)
1396 card
->options
.route4
.type
= NO_ROUTER
;
1397 card
->options
.route6
.type
= NO_ROUTER
;
1398 card
->options
.fake_broadcast
= 0;
1399 card
->options
.add_hhlen
= DEFAULT_ADD_HHLEN
;
1400 card
->options
.performance_stats
= 0;
1401 card
->options
.rx_sg_cb
= QETH_RX_SG_CB
;
1402 card
->options
.isolation
= ISOLATION_MODE_NONE
;
1403 card
->options
.cq
= QETH_CQ_DISABLED
;
1406 static int qeth_do_start_thread(struct qeth_card
*card
, unsigned long thread
)
1408 unsigned long flags
;
1411 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
1412 QETH_CARD_TEXT_(card
, 4, " %02x%02x%02x",
1413 (u8
) card
->thread_start_mask
,
1414 (u8
) card
->thread_allowed_mask
,
1415 (u8
) card
->thread_running_mask
);
1416 rc
= (card
->thread_start_mask
& thread
);
1417 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
1421 static void qeth_start_kernel_thread(struct work_struct
*work
)
1423 struct task_struct
*ts
;
1424 struct qeth_card
*card
= container_of(work
, struct qeth_card
,
1425 kernel_thread_starter
);
1426 QETH_CARD_TEXT(card
, 2, "strthrd");
1428 if (card
->read
.state
!= CH_STATE_UP
&&
1429 card
->write
.state
!= CH_STATE_UP
)
1431 if (qeth_do_start_thread(card
, QETH_RECOVER_THREAD
)) {
1432 ts
= kthread_run(card
->discipline
->recover
, (void *)card
,
1435 qeth_clear_thread_start_bit(card
, QETH_RECOVER_THREAD
);
1436 qeth_clear_thread_running_bit(card
,
1437 QETH_RECOVER_THREAD
);
1442 static void qeth_buffer_reclaim_work(struct work_struct
*);
1443 static int qeth_setup_card(struct qeth_card
*card
)
1446 QETH_DBF_TEXT(SETUP
, 2, "setupcrd");
1447 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
1449 card
->read
.state
= CH_STATE_DOWN
;
1450 card
->write
.state
= CH_STATE_DOWN
;
1451 card
->data
.state
= CH_STATE_DOWN
;
1452 card
->state
= CARD_STATE_DOWN
;
1453 card
->lan_online
= 0;
1454 card
->read_or_write_problem
= 0;
1456 spin_lock_init(&card
->vlanlock
);
1457 spin_lock_init(&card
->mclock
);
1458 spin_lock_init(&card
->lock
);
1459 spin_lock_init(&card
->ip_lock
);
1460 spin_lock_init(&card
->thread_mask_lock
);
1461 mutex_init(&card
->conf_mutex
);
1462 mutex_init(&card
->discipline_mutex
);
1463 card
->thread_start_mask
= 0;
1464 card
->thread_allowed_mask
= 0;
1465 card
->thread_running_mask
= 0;
1466 INIT_WORK(&card
->kernel_thread_starter
, qeth_start_kernel_thread
);
1467 INIT_LIST_HEAD(&card
->ip_list
);
1468 INIT_LIST_HEAD(card
->ip_tbd_list
);
1469 INIT_LIST_HEAD(&card
->cmd_waiter_list
);
1470 init_waitqueue_head(&card
->wait_q
);
1471 /* initial options */
1472 qeth_set_intial_options(card
);
1473 /* IP address takeover */
1474 INIT_LIST_HEAD(&card
->ipato
.entries
);
1475 card
->ipato
.enabled
= 0;
1476 card
->ipato
.invert4
= 0;
1477 card
->ipato
.invert6
= 0;
1478 /* init QDIO stuff */
1479 qeth_init_qdio_info(card
);
1480 INIT_DELAYED_WORK(&card
->buffer_reclaim_work
, qeth_buffer_reclaim_work
);
1481 INIT_WORK(&card
->close_dev_work
, qeth_close_dev_handler
);
1485 static void qeth_core_sl_print(struct seq_file
*m
, struct service_level
*slr
)
1487 struct qeth_card
*card
= container_of(slr
, struct qeth_card
,
1488 qeth_service_level
);
1489 if (card
->info
.mcl_level
[0])
1490 seq_printf(m
, "qeth: %s firmware level %s\n",
1491 CARD_BUS_ID(card
), card
->info
.mcl_level
);
1494 static struct qeth_card
*qeth_alloc_card(void)
1496 struct qeth_card
*card
;
1498 QETH_DBF_TEXT(SETUP
, 2, "alloccrd");
1499 card
= kzalloc(sizeof(struct qeth_card
), GFP_DMA
|GFP_KERNEL
);
1502 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
1503 card
->ip_tbd_list
= kzalloc(sizeof(struct list_head
), GFP_KERNEL
);
1504 if (!card
->ip_tbd_list
) {
1505 QETH_DBF_TEXT(SETUP
, 0, "iptbdnom");
1508 if (qeth_setup_channel(&card
->read
))
1510 if (qeth_setup_channel(&card
->write
))
1512 card
->options
.layer2
= -1;
1513 card
->qeth_service_level
.seq_print
= qeth_core_sl_print
;
1514 register_service_level(&card
->qeth_service_level
);
1518 qeth_clean_channel(&card
->read
);
1520 kfree(card
->ip_tbd_list
);
1527 static int qeth_determine_card_type(struct qeth_card
*card
)
1531 QETH_DBF_TEXT(SETUP
, 2, "detcdtyp");
1533 card
->qdio
.do_prio_queueing
= QETH_PRIOQ_DEFAULT
;
1534 card
->qdio
.default_out_queue
= QETH_DEFAULT_QUEUE
;
1535 while (known_devices
[i
][QETH_DEV_MODEL_IND
]) {
1536 if ((CARD_RDEV(card
)->id
.dev_type
==
1537 known_devices
[i
][QETH_DEV_TYPE_IND
]) &&
1538 (CARD_RDEV(card
)->id
.dev_model
==
1539 known_devices
[i
][QETH_DEV_MODEL_IND
])) {
1540 card
->info
.type
= known_devices
[i
][QETH_DEV_MODEL_IND
];
1541 card
->qdio
.no_out_queues
=
1542 known_devices
[i
][QETH_QUEUE_NO_IND
];
1543 card
->qdio
.no_in_queues
= 1;
1544 card
->info
.is_multicast_different
=
1545 known_devices
[i
][QETH_MULTICAST_IND
];
1546 qeth_update_from_chp_desc(card
);
1551 card
->info
.type
= QETH_CARD_TYPE_UNKNOWN
;
1552 dev_err(&card
->gdev
->dev
, "The adapter hardware is of an "
1557 static int qeth_clear_channel(struct qeth_channel
*channel
)
1559 unsigned long flags
;
1560 struct qeth_card
*card
;
1563 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1564 QETH_CARD_TEXT(card
, 3, "clearch");
1565 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1566 rc
= ccw_device_clear(channel
->ccwdev
, QETH_CLEAR_CHANNEL_PARM
);
1567 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1571 rc
= wait_event_interruptible_timeout(card
->wait_q
,
1572 channel
->state
== CH_STATE_STOPPED
, QETH_TIMEOUT
);
1573 if (rc
== -ERESTARTSYS
)
1575 if (channel
->state
!= CH_STATE_STOPPED
)
1577 channel
->state
= CH_STATE_DOWN
;
1581 static int qeth_halt_channel(struct qeth_channel
*channel
)
1583 unsigned long flags
;
1584 struct qeth_card
*card
;
1587 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1588 QETH_CARD_TEXT(card
, 3, "haltch");
1589 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1590 rc
= ccw_device_halt(channel
->ccwdev
, QETH_HALT_CHANNEL_PARM
);
1591 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1595 rc
= wait_event_interruptible_timeout(card
->wait_q
,
1596 channel
->state
== CH_STATE_HALTED
, QETH_TIMEOUT
);
1597 if (rc
== -ERESTARTSYS
)
1599 if (channel
->state
!= CH_STATE_HALTED
)
1604 static int qeth_halt_channels(struct qeth_card
*card
)
1606 int rc1
= 0, rc2
= 0, rc3
= 0;
1608 QETH_CARD_TEXT(card
, 3, "haltchs");
1609 rc1
= qeth_halt_channel(&card
->read
);
1610 rc2
= qeth_halt_channel(&card
->write
);
1611 rc3
= qeth_halt_channel(&card
->data
);
1619 static int qeth_clear_channels(struct qeth_card
*card
)
1621 int rc1
= 0, rc2
= 0, rc3
= 0;
1623 QETH_CARD_TEXT(card
, 3, "clearchs");
1624 rc1
= qeth_clear_channel(&card
->read
);
1625 rc2
= qeth_clear_channel(&card
->write
);
1626 rc3
= qeth_clear_channel(&card
->data
);
1634 static int qeth_clear_halt_card(struct qeth_card
*card
, int halt
)
1638 QETH_CARD_TEXT(card
, 3, "clhacrd");
1641 rc
= qeth_halt_channels(card
);
1644 return qeth_clear_channels(card
);
1647 int qeth_qdio_clear_card(struct qeth_card
*card
, int use_halt
)
1651 QETH_CARD_TEXT(card
, 3, "qdioclr");
1652 switch (atomic_cmpxchg(&card
->qdio
.state
, QETH_QDIO_ESTABLISHED
,
1653 QETH_QDIO_CLEANING
)) {
1654 case QETH_QDIO_ESTABLISHED
:
1655 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
1656 rc
= qdio_shutdown(CARD_DDEV(card
),
1657 QDIO_FLAG_CLEANUP_USING_HALT
);
1659 rc
= qdio_shutdown(CARD_DDEV(card
),
1660 QDIO_FLAG_CLEANUP_USING_CLEAR
);
1662 QETH_CARD_TEXT_(card
, 3, "1err%d", rc
);
1663 atomic_set(&card
->qdio
.state
, QETH_QDIO_ALLOCATED
);
1665 case QETH_QDIO_CLEANING
:
1670 rc
= qeth_clear_halt_card(card
, use_halt
);
1672 QETH_CARD_TEXT_(card
, 3, "2err%d", rc
);
1673 card
->state
= CARD_STATE_DOWN
;
1676 EXPORT_SYMBOL_GPL(qeth_qdio_clear_card
);
1678 static int qeth_read_conf_data(struct qeth_card
*card
, void **buffer
,
1684 struct qeth_channel
*channel
= &card
->data
;
1685 unsigned long flags
;
1688 * scan for RCD command in extended SenseID data
1690 ciw
= ccw_device_get_ciw(channel
->ccwdev
, CIW_TYPE_RCD
);
1691 if (!ciw
|| ciw
->cmd
== 0)
1693 rcd_buf
= kzalloc(ciw
->count
, GFP_KERNEL
| GFP_DMA
);
1697 channel
->ccw
.cmd_code
= ciw
->cmd
;
1698 channel
->ccw
.cda
= (__u32
) __pa(rcd_buf
);
1699 channel
->ccw
.count
= ciw
->count
;
1700 channel
->ccw
.flags
= CCW_FLAG_SLI
;
1701 channel
->state
= CH_STATE_RCD
;
1702 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1703 ret
= ccw_device_start_timeout(channel
->ccwdev
, &channel
->ccw
,
1704 QETH_RCD_PARM
, LPM_ANYPATH
, 0,
1706 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1708 wait_event(card
->wait_q
,
1709 (channel
->state
== CH_STATE_RCD_DONE
||
1710 channel
->state
== CH_STATE_DOWN
));
1711 if (channel
->state
== CH_STATE_DOWN
)
1714 channel
->state
= CH_STATE_DOWN
;
1720 *length
= ciw
->count
;
1726 static void qeth_configure_unitaddr(struct qeth_card
*card
, char *prcd
)
1728 QETH_DBF_TEXT(SETUP
, 2, "cfgunit");
1729 card
->info
.chpid
= prcd
[30];
1730 card
->info
.unit_addr2
= prcd
[31];
1731 card
->info
.cula
= prcd
[63];
1732 card
->info
.guestlan
= ((prcd
[0x10] == _ascebc
['V']) &&
1733 (prcd
[0x11] == _ascebc
['M']));
1736 static void qeth_configure_blkt_default(struct qeth_card
*card
, char *prcd
)
1738 QETH_DBF_TEXT(SETUP
, 2, "cfgblkt");
1740 if (prcd
[74] == 0xF0 && prcd
[75] == 0xF0 &&
1741 prcd
[76] >= 0xF1 && prcd
[76] <= 0xF4) {
1742 card
->info
.blkt
.time_total
= 0;
1743 card
->info
.blkt
.inter_packet
= 0;
1744 card
->info
.blkt
.inter_packet_jumbo
= 0;
1746 card
->info
.blkt
.time_total
= 250;
1747 card
->info
.blkt
.inter_packet
= 5;
1748 card
->info
.blkt
.inter_packet_jumbo
= 15;
1752 static void qeth_init_tokens(struct qeth_card
*card
)
1754 card
->token
.issuer_rm_w
= 0x00010103UL
;
1755 card
->token
.cm_filter_w
= 0x00010108UL
;
1756 card
->token
.cm_connection_w
= 0x0001010aUL
;
1757 card
->token
.ulp_filter_w
= 0x0001010bUL
;
1758 card
->token
.ulp_connection_w
= 0x0001010dUL
;
1761 static void qeth_init_func_level(struct qeth_card
*card
)
1763 switch (card
->info
.type
) {
1764 case QETH_CARD_TYPE_IQD
:
1765 card
->info
.func_level
= QETH_IDX_FUNC_LEVEL_IQD
;
1767 case QETH_CARD_TYPE_OSD
:
1768 case QETH_CARD_TYPE_OSN
:
1769 card
->info
.func_level
= QETH_IDX_FUNC_LEVEL_OSD
;
1776 static int qeth_idx_activate_get_answer(struct qeth_channel
*channel
,
1777 void (*idx_reply_cb
)(struct qeth_channel
*,
1778 struct qeth_cmd_buffer
*))
1780 struct qeth_cmd_buffer
*iob
;
1781 unsigned long flags
;
1783 struct qeth_card
*card
;
1785 QETH_DBF_TEXT(SETUP
, 2, "idxanswr");
1786 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1787 iob
= qeth_get_buffer(channel
);
1790 iob
->callback
= idx_reply_cb
;
1791 memcpy(&channel
->ccw
, READ_CCW
, sizeof(struct ccw1
));
1792 channel
->ccw
.count
= QETH_BUFSIZE
;
1793 channel
->ccw
.cda
= (__u32
) __pa(iob
->data
);
1795 wait_event(card
->wait_q
,
1796 atomic_cmpxchg(&channel
->irq_pending
, 0, 1) == 0);
1797 QETH_DBF_TEXT(SETUP
, 6, "noirqpnd");
1798 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1799 rc
= ccw_device_start(channel
->ccwdev
,
1800 &channel
->ccw
, (addr_t
) iob
, 0, 0);
1801 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1804 QETH_DBF_MESSAGE(2, "Error2 in activating channel rc=%d\n", rc
);
1805 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
1806 atomic_set(&channel
->irq_pending
, 0);
1807 wake_up(&card
->wait_q
);
1810 rc
= wait_event_interruptible_timeout(card
->wait_q
,
1811 channel
->state
== CH_STATE_UP
, QETH_TIMEOUT
);
1812 if (rc
== -ERESTARTSYS
)
1814 if (channel
->state
!= CH_STATE_UP
) {
1816 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
1817 qeth_clear_cmd_buffers(channel
);
1823 static int qeth_idx_activate_channel(struct qeth_channel
*channel
,
1824 void (*idx_reply_cb
)(struct qeth_channel
*,
1825 struct qeth_cmd_buffer
*))
1827 struct qeth_card
*card
;
1828 struct qeth_cmd_buffer
*iob
;
1829 unsigned long flags
;
1833 struct ccw_dev_id temp_devid
;
1835 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1837 QETH_DBF_TEXT(SETUP
, 2, "idxactch");
1839 iob
= qeth_get_buffer(channel
);
1842 iob
->callback
= idx_reply_cb
;
1843 memcpy(&channel
->ccw
, WRITE_CCW
, sizeof(struct ccw1
));
1844 channel
->ccw
.count
= IDX_ACTIVATE_SIZE
;
1845 channel
->ccw
.cda
= (__u32
) __pa(iob
->data
);
1846 if (channel
== &card
->write
) {
1847 memcpy(iob
->data
, IDX_ACTIVATE_WRITE
, IDX_ACTIVATE_SIZE
);
1848 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob
->data
),
1849 &card
->seqno
.trans_hdr
, QETH_SEQ_NO_LENGTH
);
1850 card
->seqno
.trans_hdr
++;
1852 memcpy(iob
->data
, IDX_ACTIVATE_READ
, IDX_ACTIVATE_SIZE
);
1853 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob
->data
),
1854 &card
->seqno
.trans_hdr
, QETH_SEQ_NO_LENGTH
);
1856 tmp
= ((__u8
)card
->info
.portno
) | 0x80;
1857 memcpy(QETH_IDX_ACT_PNO(iob
->data
), &tmp
, 1);
1858 memcpy(QETH_IDX_ACT_ISSUER_RM_TOKEN(iob
->data
),
1859 &card
->token
.issuer_rm_w
, QETH_MPC_TOKEN_LENGTH
);
1860 memcpy(QETH_IDX_ACT_FUNC_LEVEL(iob
->data
),
1861 &card
->info
.func_level
, sizeof(__u16
));
1862 ccw_device_get_id(CARD_DDEV(card
), &temp_devid
);
1863 memcpy(QETH_IDX_ACT_QDIO_DEV_CUA(iob
->data
), &temp_devid
.devno
, 2);
1864 temp
= (card
->info
.cula
<< 8) + card
->info
.unit_addr2
;
1865 memcpy(QETH_IDX_ACT_QDIO_DEV_REALADDR(iob
->data
), &temp
, 2);
1867 wait_event(card
->wait_q
,
1868 atomic_cmpxchg(&channel
->irq_pending
, 0, 1) == 0);
1869 QETH_DBF_TEXT(SETUP
, 6, "noirqpnd");
1870 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1871 rc
= ccw_device_start(channel
->ccwdev
,
1872 &channel
->ccw
, (addr_t
) iob
, 0, 0);
1873 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1876 QETH_DBF_MESSAGE(2, "Error1 in activating channel. rc=%d\n",
1878 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
1879 atomic_set(&channel
->irq_pending
, 0);
1880 wake_up(&card
->wait_q
);
1883 rc
= wait_event_interruptible_timeout(card
->wait_q
,
1884 channel
->state
== CH_STATE_ACTIVATING
, QETH_TIMEOUT
);
1885 if (rc
== -ERESTARTSYS
)
1887 if (channel
->state
!= CH_STATE_ACTIVATING
) {
1888 dev_warn(&channel
->ccwdev
->dev
, "The qeth device driver"
1889 " failed to recover an error on the device\n");
1890 QETH_DBF_MESSAGE(2, "%s IDX activate timed out\n",
1891 dev_name(&channel
->ccwdev
->dev
));
1892 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", -ETIME
);
1893 qeth_clear_cmd_buffers(channel
);
1896 return qeth_idx_activate_get_answer(channel
, idx_reply_cb
);
1899 static int qeth_peer_func_level(int level
)
1901 if ((level
& 0xff) == 8)
1902 return (level
& 0xff) + 0x400;
1903 if (((level
>> 8) & 3) == 1)
1904 return (level
& 0xff) + 0x200;
1908 static void qeth_idx_write_cb(struct qeth_channel
*channel
,
1909 struct qeth_cmd_buffer
*iob
)
1911 struct qeth_card
*card
;
1914 QETH_DBF_TEXT(SETUP
, 2, "idxwrcb");
1916 if (channel
->state
== CH_STATE_DOWN
) {
1917 channel
->state
= CH_STATE_ACTIVATING
;
1920 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1922 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob
->data
))) {
1923 if (QETH_IDX_ACT_CAUSE_CODE(iob
->data
) == QETH_IDX_ACT_ERR_EXCL
)
1924 dev_err(&card
->write
.ccwdev
->dev
,
1925 "The adapter is used exclusively by another "
1928 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on write channel:"
1929 " negative reply\n",
1930 dev_name(&card
->write
.ccwdev
->dev
));
1933 memcpy(&temp
, QETH_IDX_ACT_FUNC_LEVEL(iob
->data
), 2);
1934 if ((temp
& ~0x0100) != qeth_peer_func_level(card
->info
.func_level
)) {
1935 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on write channel: "
1936 "function level mismatch (sent: 0x%x, received: "
1937 "0x%x)\n", dev_name(&card
->write
.ccwdev
->dev
),
1938 card
->info
.func_level
, temp
);
1941 channel
->state
= CH_STATE_UP
;
1943 qeth_release_buffer(channel
, iob
);
1946 static void qeth_idx_read_cb(struct qeth_channel
*channel
,
1947 struct qeth_cmd_buffer
*iob
)
1949 struct qeth_card
*card
;
1952 QETH_DBF_TEXT(SETUP
, 2, "idxrdcb");
1953 if (channel
->state
== CH_STATE_DOWN
) {
1954 channel
->state
= CH_STATE_ACTIVATING
;
1958 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1959 if (qeth_check_idx_response(card
, iob
->data
))
1962 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob
->data
))) {
1963 switch (QETH_IDX_ACT_CAUSE_CODE(iob
->data
)) {
1964 case QETH_IDX_ACT_ERR_EXCL
:
1965 dev_err(&card
->write
.ccwdev
->dev
,
1966 "The adapter is used exclusively by another "
1969 case QETH_IDX_ACT_ERR_AUTH
:
1970 case QETH_IDX_ACT_ERR_AUTH_USER
:
1971 dev_err(&card
->read
.ccwdev
->dev
,
1972 "Setting the device online failed because of "
1973 "insufficient authorization\n");
1976 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on read channel:"
1977 " negative reply\n",
1978 dev_name(&card
->read
.ccwdev
->dev
));
1980 QETH_CARD_TEXT_(card
, 2, "idxread%c",
1981 QETH_IDX_ACT_CAUSE_CODE(iob
->data
));
1985 memcpy(&temp
, QETH_IDX_ACT_FUNC_LEVEL(iob
->data
), 2);
1986 if (temp
!= qeth_peer_func_level(card
->info
.func_level
)) {
1987 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on read channel: function "
1988 "level mismatch (sent: 0x%x, received: 0x%x)\n",
1989 dev_name(&card
->read
.ccwdev
->dev
),
1990 card
->info
.func_level
, temp
);
1993 memcpy(&card
->token
.issuer_rm_r
,
1994 QETH_IDX_ACT_ISSUER_RM_TOKEN(iob
->data
),
1995 QETH_MPC_TOKEN_LENGTH
);
1996 memcpy(&card
->info
.mcl_level
[0],
1997 QETH_IDX_REPLY_LEVEL(iob
->data
), QETH_MCL_LENGTH
);
1998 channel
->state
= CH_STATE_UP
;
2000 qeth_release_buffer(channel
, iob
);
2003 void qeth_prepare_control_data(struct qeth_card
*card
, int len
,
2004 struct qeth_cmd_buffer
*iob
)
2006 qeth_setup_ccw(&card
->write
, iob
->data
, len
);
2007 iob
->callback
= qeth_release_buffer
;
2009 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob
->data
),
2010 &card
->seqno
.trans_hdr
, QETH_SEQ_NO_LENGTH
);
2011 card
->seqno
.trans_hdr
++;
2012 memcpy(QETH_PDU_HEADER_SEQ_NO(iob
->data
),
2013 &card
->seqno
.pdu_hdr
, QETH_SEQ_NO_LENGTH
);
2014 card
->seqno
.pdu_hdr
++;
2015 memcpy(QETH_PDU_HEADER_ACK_SEQ_NO(iob
->data
),
2016 &card
->seqno
.pdu_hdr_ack
, QETH_SEQ_NO_LENGTH
);
2017 QETH_DBF_HEX(CTRL
, 2, iob
->data
, QETH_DBF_CTRL_LEN
);
2019 EXPORT_SYMBOL_GPL(qeth_prepare_control_data
);
2022 * qeth_send_control_data() - send control command to the card
2023 * @card: qeth_card structure pointer
2024 * @len: size of the command buffer
2025 * @iob: qeth_cmd_buffer pointer
2026 * @reply_cb: callback function pointer
2027 * @cb_card: pointer to the qeth_card structure
2028 * @cb_reply: pointer to the qeth_reply structure
2029 * @cb_cmd: pointer to the original iob for non-IPA
2030 * commands, or to the qeth_ipa_cmd structure
2031 * for the IPA commands.
2032 * @reply_param: private pointer passed to the callback
2034 * Returns the value of the `return_code' field of the response
2035 * block returned from the hardware, or other error indication.
2036 * Value of zero indicates successful execution of the command.
2038 * Callback function gets called one or more times, with cb_cmd
2039 * pointing to the response returned by the hardware. Callback
2040 * function must return non-zero if more reply blocks are expected,
2041 * and zero if the last or only reply block is received. Callback
2042 * function can get the value of the reply_param pointer from the
2043 * field 'param' of the structure qeth_reply.
2046 int qeth_send_control_data(struct qeth_card
*card
, int len
,
2047 struct qeth_cmd_buffer
*iob
,
2048 int (*reply_cb
)(struct qeth_card
*cb_card
,
2049 struct qeth_reply
*cb_reply
,
2050 unsigned long cb_cmd
),
2054 unsigned long flags
;
2055 struct qeth_reply
*reply
= NULL
;
2056 unsigned long timeout
, event_timeout
;
2057 struct qeth_ipa_cmd
*cmd
;
2059 QETH_CARD_TEXT(card
, 2, "sendctl");
2061 if (card
->read_or_write_problem
) {
2062 qeth_release_buffer(iob
->channel
, iob
);
2065 reply
= qeth_alloc_reply(card
);
2069 reply
->callback
= reply_cb
;
2070 reply
->param
= reply_param
;
2071 if (card
->state
== CARD_STATE_DOWN
)
2072 reply
->seqno
= QETH_IDX_COMMAND_SEQNO
;
2074 reply
->seqno
= card
->seqno
.ipa
++;
2075 init_waitqueue_head(&reply
->wait_q
);
2076 spin_lock_irqsave(&card
->lock
, flags
);
2077 list_add_tail(&reply
->list
, &card
->cmd_waiter_list
);
2078 spin_unlock_irqrestore(&card
->lock
, flags
);
2079 QETH_DBF_HEX(CTRL
, 2, iob
->data
, QETH_DBF_CTRL_LEN
);
2081 while (atomic_cmpxchg(&card
->write
.irq_pending
, 0, 1)) ;
2082 qeth_prepare_control_data(card
, len
, iob
);
2084 if (IS_IPA(iob
->data
))
2085 event_timeout
= QETH_IPA_TIMEOUT
;
2087 event_timeout
= QETH_TIMEOUT
;
2088 timeout
= jiffies
+ event_timeout
;
2090 QETH_CARD_TEXT(card
, 6, "noirqpnd");
2091 spin_lock_irqsave(get_ccwdev_lock(card
->write
.ccwdev
), flags
);
2092 rc
= ccw_device_start(card
->write
.ccwdev
, &card
->write
.ccw
,
2093 (addr_t
) iob
, 0, 0);
2094 spin_unlock_irqrestore(get_ccwdev_lock(card
->write
.ccwdev
), flags
);
2096 QETH_DBF_MESSAGE(2, "%s qeth_send_control_data: "
2097 "ccw_device_start rc = %i\n",
2098 dev_name(&card
->write
.ccwdev
->dev
), rc
);
2099 QETH_CARD_TEXT_(card
, 2, " err%d", rc
);
2100 spin_lock_irqsave(&card
->lock
, flags
);
2101 list_del_init(&reply
->list
);
2102 qeth_put_reply(reply
);
2103 spin_unlock_irqrestore(&card
->lock
, flags
);
2104 qeth_release_buffer(iob
->channel
, iob
);
2105 atomic_set(&card
->write
.irq_pending
, 0);
2106 wake_up(&card
->wait_q
);
2110 /* we have only one long running ipassist, since we can ensure
2111 process context of this command we can sleep */
2112 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
2113 if ((cmd
->hdr
.command
== IPA_CMD_SETIP
) &&
2114 (cmd
->hdr
.prot_version
== QETH_PROT_IPV4
)) {
2115 if (!wait_event_timeout(reply
->wait_q
,
2116 atomic_read(&reply
->received
), event_timeout
))
2119 while (!atomic_read(&reply
->received
)) {
2120 if (time_after(jiffies
, timeout
))
2126 if (reply
->rc
== -EIO
)
2129 qeth_put_reply(reply
);
2134 spin_lock_irqsave(&reply
->card
->lock
, flags
);
2135 list_del_init(&reply
->list
);
2136 spin_unlock_irqrestore(&reply
->card
->lock
, flags
);
2137 atomic_inc(&reply
->received
);
2139 atomic_set(&card
->write
.irq_pending
, 0);
2140 qeth_release_buffer(iob
->channel
, iob
);
2141 card
->write
.buf_no
= (card
->write
.buf_no
+ 1) % QETH_CMD_BUFFER_NO
;
2143 qeth_put_reply(reply
);
2146 EXPORT_SYMBOL_GPL(qeth_send_control_data
);
2148 static int qeth_cm_enable_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
2151 struct qeth_cmd_buffer
*iob
;
2153 QETH_DBF_TEXT(SETUP
, 2, "cmenblcb");
2155 iob
= (struct qeth_cmd_buffer
*) data
;
2156 memcpy(&card
->token
.cm_filter_r
,
2157 QETH_CM_ENABLE_RESP_FILTER_TOKEN(iob
->data
),
2158 QETH_MPC_TOKEN_LENGTH
);
2159 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
2163 static int qeth_cm_enable(struct qeth_card
*card
)
2166 struct qeth_cmd_buffer
*iob
;
2168 QETH_DBF_TEXT(SETUP
, 2, "cmenable");
2170 iob
= qeth_wait_for_buffer(&card
->write
);
2171 memcpy(iob
->data
, CM_ENABLE
, CM_ENABLE_SIZE
);
2172 memcpy(QETH_CM_ENABLE_ISSUER_RM_TOKEN(iob
->data
),
2173 &card
->token
.issuer_rm_r
, QETH_MPC_TOKEN_LENGTH
);
2174 memcpy(QETH_CM_ENABLE_FILTER_TOKEN(iob
->data
),
2175 &card
->token
.cm_filter_w
, QETH_MPC_TOKEN_LENGTH
);
2177 rc
= qeth_send_control_data(card
, CM_ENABLE_SIZE
, iob
,
2178 qeth_cm_enable_cb
, NULL
);
2182 static int qeth_cm_setup_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
2186 struct qeth_cmd_buffer
*iob
;
2188 QETH_DBF_TEXT(SETUP
, 2, "cmsetpcb");
2190 iob
= (struct qeth_cmd_buffer
*) data
;
2191 memcpy(&card
->token
.cm_connection_r
,
2192 QETH_CM_SETUP_RESP_DEST_ADDR(iob
->data
),
2193 QETH_MPC_TOKEN_LENGTH
);
2194 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
2198 static int qeth_cm_setup(struct qeth_card
*card
)
2201 struct qeth_cmd_buffer
*iob
;
2203 QETH_DBF_TEXT(SETUP
, 2, "cmsetup");
2205 iob
= qeth_wait_for_buffer(&card
->write
);
2206 memcpy(iob
->data
, CM_SETUP
, CM_SETUP_SIZE
);
2207 memcpy(QETH_CM_SETUP_DEST_ADDR(iob
->data
),
2208 &card
->token
.issuer_rm_r
, QETH_MPC_TOKEN_LENGTH
);
2209 memcpy(QETH_CM_SETUP_CONNECTION_TOKEN(iob
->data
),
2210 &card
->token
.cm_connection_w
, QETH_MPC_TOKEN_LENGTH
);
2211 memcpy(QETH_CM_SETUP_FILTER_TOKEN(iob
->data
),
2212 &card
->token
.cm_filter_r
, QETH_MPC_TOKEN_LENGTH
);
2213 rc
= qeth_send_control_data(card
, CM_SETUP_SIZE
, iob
,
2214 qeth_cm_setup_cb
, NULL
);
2219 static inline int qeth_get_initial_mtu_for_card(struct qeth_card
*card
)
2221 switch (card
->info
.type
) {
2222 case QETH_CARD_TYPE_UNKNOWN
:
2224 case QETH_CARD_TYPE_IQD
:
2225 return card
->info
.max_mtu
;
2226 case QETH_CARD_TYPE_OSD
:
2227 switch (card
->info
.link_type
) {
2228 case QETH_LINK_TYPE_HSTR
:
2229 case QETH_LINK_TYPE_LANE_TR
:
2232 return card
->options
.layer2
? 1500 : 1492;
2234 case QETH_CARD_TYPE_OSM
:
2235 case QETH_CARD_TYPE_OSX
:
2236 return card
->options
.layer2
? 1500 : 1492;
2242 static inline int qeth_get_mtu_outof_framesize(int framesize
)
2244 switch (framesize
) {
2258 static inline int qeth_mtu_is_valid(struct qeth_card
*card
, int mtu
)
2260 switch (card
->info
.type
) {
2261 case QETH_CARD_TYPE_OSD
:
2262 case QETH_CARD_TYPE_OSM
:
2263 case QETH_CARD_TYPE_OSX
:
2264 case QETH_CARD_TYPE_IQD
:
2265 return ((mtu
>= 576) &&
2266 (mtu
<= card
->info
.max_mtu
));
2267 case QETH_CARD_TYPE_OSN
:
2268 case QETH_CARD_TYPE_UNKNOWN
:
2274 static int qeth_ulp_enable_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
2278 __u16 mtu
, framesize
;
2281 struct qeth_cmd_buffer
*iob
;
2283 QETH_DBF_TEXT(SETUP
, 2, "ulpenacb");
2285 iob
= (struct qeth_cmd_buffer
*) data
;
2286 memcpy(&card
->token
.ulp_filter_r
,
2287 QETH_ULP_ENABLE_RESP_FILTER_TOKEN(iob
->data
),
2288 QETH_MPC_TOKEN_LENGTH
);
2289 if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
2290 memcpy(&framesize
, QETH_ULP_ENABLE_RESP_MAX_MTU(iob
->data
), 2);
2291 mtu
= qeth_get_mtu_outof_framesize(framesize
);
2294 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
2297 if (card
->info
.initial_mtu
&& (card
->info
.initial_mtu
!= mtu
)) {
2298 /* frame size has changed */
2300 ((card
->dev
->mtu
== card
->info
.initial_mtu
) ||
2301 (card
->dev
->mtu
> mtu
)))
2302 card
->dev
->mtu
= mtu
;
2303 qeth_free_qdio_buffers(card
);
2305 card
->info
.initial_mtu
= mtu
;
2306 card
->info
.max_mtu
= mtu
;
2307 card
->qdio
.in_buf_size
= mtu
+ 2 * PAGE_SIZE
;
2309 card
->info
.max_mtu
= *(__u16
*)QETH_ULP_ENABLE_RESP_MAX_MTU(
2311 card
->info
.initial_mtu
= min(card
->info
.max_mtu
,
2312 qeth_get_initial_mtu_for_card(card
));
2313 card
->qdio
.in_buf_size
= QETH_IN_BUF_SIZE_DEFAULT
;
2316 memcpy(&len
, QETH_ULP_ENABLE_RESP_DIFINFO_LEN(iob
->data
), 2);
2317 if (len
>= QETH_MPC_DIFINFO_LEN_INDICATES_LINK_TYPE
) {
2319 QETH_ULP_ENABLE_RESP_LINK_TYPE(iob
->data
), 1);
2320 card
->info
.link_type
= link_type
;
2322 card
->info
.link_type
= 0;
2323 QETH_DBF_TEXT_(SETUP
, 2, "link%d", card
->info
.link_type
);
2324 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
2328 static int qeth_ulp_enable(struct qeth_card
*card
)
2332 struct qeth_cmd_buffer
*iob
;
2334 /*FIXME: trace view callbacks*/
2335 QETH_DBF_TEXT(SETUP
, 2, "ulpenabl");
2337 iob
= qeth_wait_for_buffer(&card
->write
);
2338 memcpy(iob
->data
, ULP_ENABLE
, ULP_ENABLE_SIZE
);
2340 *(QETH_ULP_ENABLE_LINKNUM(iob
->data
)) =
2341 (__u8
) card
->info
.portno
;
2342 if (card
->options
.layer2
)
2343 if (card
->info
.type
== QETH_CARD_TYPE_OSN
)
2344 prot_type
= QETH_PROT_OSN2
;
2346 prot_type
= QETH_PROT_LAYER2
;
2348 prot_type
= QETH_PROT_TCPIP
;
2350 memcpy(QETH_ULP_ENABLE_PROT_TYPE(iob
->data
), &prot_type
, 1);
2351 memcpy(QETH_ULP_ENABLE_DEST_ADDR(iob
->data
),
2352 &card
->token
.cm_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2353 memcpy(QETH_ULP_ENABLE_FILTER_TOKEN(iob
->data
),
2354 &card
->token
.ulp_filter_w
, QETH_MPC_TOKEN_LENGTH
);
2355 rc
= qeth_send_control_data(card
, ULP_ENABLE_SIZE
, iob
,
2356 qeth_ulp_enable_cb
, NULL
);
2361 static int qeth_ulp_setup_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
2364 struct qeth_cmd_buffer
*iob
;
2366 QETH_DBF_TEXT(SETUP
, 2, "ulpstpcb");
2368 iob
= (struct qeth_cmd_buffer
*) data
;
2369 memcpy(&card
->token
.ulp_connection_r
,
2370 QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob
->data
),
2371 QETH_MPC_TOKEN_LENGTH
);
2372 if (!strncmp("00S", QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob
->data
),
2374 QETH_DBF_TEXT(SETUP
, 2, "olmlimit");
2375 dev_err(&card
->gdev
->dev
, "A connection could not be "
2376 "established because of an OLM limit\n");
2379 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
2383 static int qeth_ulp_setup(struct qeth_card
*card
)
2387 struct qeth_cmd_buffer
*iob
;
2388 struct ccw_dev_id dev_id
;
2390 QETH_DBF_TEXT(SETUP
, 2, "ulpsetup");
2392 iob
= qeth_wait_for_buffer(&card
->write
);
2393 memcpy(iob
->data
, ULP_SETUP
, ULP_SETUP_SIZE
);
2395 memcpy(QETH_ULP_SETUP_DEST_ADDR(iob
->data
),
2396 &card
->token
.cm_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2397 memcpy(QETH_ULP_SETUP_CONNECTION_TOKEN(iob
->data
),
2398 &card
->token
.ulp_connection_w
, QETH_MPC_TOKEN_LENGTH
);
2399 memcpy(QETH_ULP_SETUP_FILTER_TOKEN(iob
->data
),
2400 &card
->token
.ulp_filter_r
, QETH_MPC_TOKEN_LENGTH
);
2402 ccw_device_get_id(CARD_DDEV(card
), &dev_id
);
2403 memcpy(QETH_ULP_SETUP_CUA(iob
->data
), &dev_id
.devno
, 2);
2404 temp
= (card
->info
.cula
<< 8) + card
->info
.unit_addr2
;
2405 memcpy(QETH_ULP_SETUP_REAL_DEVADDR(iob
->data
), &temp
, 2);
2406 rc
= qeth_send_control_data(card
, ULP_SETUP_SIZE
, iob
,
2407 qeth_ulp_setup_cb
, NULL
);
2411 static int qeth_init_qdio_out_buf(struct qeth_qdio_out_q
*q
, int bidx
)
2414 struct qeth_qdio_out_buffer
*newbuf
;
2417 newbuf
= kmem_cache_zalloc(qeth_qdio_outbuf_cache
, GFP_ATOMIC
);
2422 newbuf
->buffer
= q
->qdio_bufs
[bidx
];
2423 skb_queue_head_init(&newbuf
->skb_list
);
2424 lockdep_set_class(&newbuf
->skb_list
.lock
, &qdio_out_skb_queue_key
);
2427 newbuf
->next_pending
= q
->bufs
[bidx
];
2428 atomic_set(&newbuf
->state
, QETH_QDIO_BUF_EMPTY
);
2429 q
->bufs
[bidx
] = newbuf
;
2431 q
->bufstates
[bidx
].user
= newbuf
;
2432 QETH_CARD_TEXT_(q
->card
, 2, "nbs%d", bidx
);
2433 QETH_CARD_TEXT_(q
->card
, 2, "%lx", (long) newbuf
);
2434 QETH_CARD_TEXT_(q
->card
, 2, "%lx",
2435 (long) newbuf
->next_pending
);
2441 static void qeth_free_qdio_out_buf(struct qeth_qdio_out_q
*q
)
2446 qdio_free_buffers(q
->qdio_bufs
, QDIO_MAX_BUFFERS_PER_Q
);
2450 static struct qeth_qdio_out_q
*qeth_alloc_qdio_out_buf(void)
2452 struct qeth_qdio_out_q
*q
= kzalloc(sizeof(*q
), GFP_KERNEL
);
2457 if (qdio_alloc_buffers(q
->qdio_bufs
, QDIO_MAX_BUFFERS_PER_Q
)) {
2464 static int qeth_alloc_qdio_buffers(struct qeth_card
*card
)
2468 QETH_DBF_TEXT(SETUP
, 2, "allcqdbf");
2470 if (atomic_cmpxchg(&card
->qdio
.state
, QETH_QDIO_UNINITIALIZED
,
2471 QETH_QDIO_ALLOCATED
) != QETH_QDIO_UNINITIALIZED
)
2474 QETH_DBF_TEXT(SETUP
, 2, "inq");
2475 card
->qdio
.in_q
= qeth_alloc_qdio_queue();
2476 if (!card
->qdio
.in_q
)
2479 /* inbound buffer pool */
2480 if (qeth_alloc_buffer_pool(card
))
2485 kzalloc(card
->qdio
.no_out_queues
*
2486 sizeof(struct qeth_qdio_out_q
*), GFP_KERNEL
);
2487 if (!card
->qdio
.out_qs
)
2489 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
2490 card
->qdio
.out_qs
[i
] = qeth_alloc_qdio_out_buf();
2491 if (!card
->qdio
.out_qs
[i
])
2493 QETH_DBF_TEXT_(SETUP
, 2, "outq %i", i
);
2494 QETH_DBF_HEX(SETUP
, 2, &card
->qdio
.out_qs
[i
], sizeof(void *));
2495 card
->qdio
.out_qs
[i
]->queue_no
= i
;
2496 /* give outbound qeth_qdio_buffers their qdio_buffers */
2497 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
) {
2498 WARN_ON(card
->qdio
.out_qs
[i
]->bufs
[j
] != NULL
);
2499 if (qeth_init_qdio_out_buf(card
->qdio
.out_qs
[i
], j
))
2500 goto out_freeoutqbufs
;
2505 if (qeth_alloc_cq(card
))
2513 kmem_cache_free(qeth_qdio_outbuf_cache
,
2514 card
->qdio
.out_qs
[i
]->bufs
[j
]);
2515 card
->qdio
.out_qs
[i
]->bufs
[j
] = NULL
;
2519 qeth_free_qdio_out_buf(card
->qdio
.out_qs
[--i
]);
2520 qeth_clear_outq_buffers(card
->qdio
.out_qs
[i
], 1);
2522 kfree(card
->qdio
.out_qs
);
2523 card
->qdio
.out_qs
= NULL
;
2525 qeth_free_buffer_pool(card
);
2527 qeth_free_qdio_queue(card
->qdio
.in_q
);
2528 card
->qdio
.in_q
= NULL
;
2530 atomic_set(&card
->qdio
.state
, QETH_QDIO_UNINITIALIZED
);
2534 static void qeth_free_qdio_buffers(struct qeth_card
*card
)
2538 if (atomic_xchg(&card
->qdio
.state
, QETH_QDIO_UNINITIALIZED
) ==
2539 QETH_QDIO_UNINITIALIZED
)
2543 cancel_delayed_work_sync(&card
->buffer_reclaim_work
);
2544 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
) {
2545 if (card
->qdio
.in_q
->bufs
[j
].rx_skb
)
2546 dev_kfree_skb_any(card
->qdio
.in_q
->bufs
[j
].rx_skb
);
2548 qeth_free_qdio_queue(card
->qdio
.in_q
);
2549 card
->qdio
.in_q
= NULL
;
2550 /* inbound buffer pool */
2551 qeth_free_buffer_pool(card
);
2552 /* free outbound qdio_qs */
2553 if (card
->qdio
.out_qs
) {
2554 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
2555 qeth_clear_outq_buffers(card
->qdio
.out_qs
[i
], 1);
2556 qeth_free_qdio_out_buf(card
->qdio
.out_qs
[i
]);
2558 kfree(card
->qdio
.out_qs
);
2559 card
->qdio
.out_qs
= NULL
;
2563 static void qeth_create_qib_param_field(struct qeth_card
*card
,
2567 param_field
[0] = _ascebc
['P'];
2568 param_field
[1] = _ascebc
['C'];
2569 param_field
[2] = _ascebc
['I'];
2570 param_field
[3] = _ascebc
['T'];
2571 *((unsigned int *) (¶m_field
[4])) = QETH_PCI_THRESHOLD_A(card
);
2572 *((unsigned int *) (¶m_field
[8])) = QETH_PCI_THRESHOLD_B(card
);
2573 *((unsigned int *) (¶m_field
[12])) = QETH_PCI_TIMER_VALUE(card
);
2576 static void qeth_create_qib_param_field_blkt(struct qeth_card
*card
,
2579 param_field
[16] = _ascebc
['B'];
2580 param_field
[17] = _ascebc
['L'];
2581 param_field
[18] = _ascebc
['K'];
2582 param_field
[19] = _ascebc
['T'];
2583 *((unsigned int *) (¶m_field
[20])) = card
->info
.blkt
.time_total
;
2584 *((unsigned int *) (¶m_field
[24])) = card
->info
.blkt
.inter_packet
;
2585 *((unsigned int *) (¶m_field
[28])) =
2586 card
->info
.blkt
.inter_packet_jumbo
;
2589 static int qeth_qdio_activate(struct qeth_card
*card
)
2591 QETH_DBF_TEXT(SETUP
, 3, "qdioact");
2592 return qdio_activate(CARD_DDEV(card
));
2595 static int qeth_dm_act(struct qeth_card
*card
)
2598 struct qeth_cmd_buffer
*iob
;
2600 QETH_DBF_TEXT(SETUP
, 2, "dmact");
2602 iob
= qeth_wait_for_buffer(&card
->write
);
2603 memcpy(iob
->data
, DM_ACT
, DM_ACT_SIZE
);
2605 memcpy(QETH_DM_ACT_DEST_ADDR(iob
->data
),
2606 &card
->token
.cm_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2607 memcpy(QETH_DM_ACT_CONNECTION_TOKEN(iob
->data
),
2608 &card
->token
.ulp_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2609 rc
= qeth_send_control_data(card
, DM_ACT_SIZE
, iob
, NULL
, NULL
);
2613 static int qeth_mpc_initialize(struct qeth_card
*card
)
2617 QETH_DBF_TEXT(SETUP
, 2, "mpcinit");
2619 rc
= qeth_issue_next_read(card
);
2621 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
2624 rc
= qeth_cm_enable(card
);
2626 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
2629 rc
= qeth_cm_setup(card
);
2631 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
2634 rc
= qeth_ulp_enable(card
);
2636 QETH_DBF_TEXT_(SETUP
, 2, "4err%d", rc
);
2639 rc
= qeth_ulp_setup(card
);
2641 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
2644 rc
= qeth_alloc_qdio_buffers(card
);
2646 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
2649 rc
= qeth_qdio_establish(card
);
2651 QETH_DBF_TEXT_(SETUP
, 2, "6err%d", rc
);
2652 qeth_free_qdio_buffers(card
);
2655 rc
= qeth_qdio_activate(card
);
2657 QETH_DBF_TEXT_(SETUP
, 2, "7err%d", rc
);
2660 rc
= qeth_dm_act(card
);
2662 QETH_DBF_TEXT_(SETUP
, 2, "8err%d", rc
);
2668 qeth_qdio_clear_card(card
, card
->info
.type
!= QETH_CARD_TYPE_IQD
);
2669 qdio_free(CARD_DDEV(card
));
2673 void qeth_print_status_message(struct qeth_card
*card
)
2675 switch (card
->info
.type
) {
2676 case QETH_CARD_TYPE_OSD
:
2677 case QETH_CARD_TYPE_OSM
:
2678 case QETH_CARD_TYPE_OSX
:
2679 /* VM will use a non-zero first character
2680 * to indicate a HiperSockets like reporting
2681 * of the level OSA sets the first character to zero
2683 if (!card
->info
.mcl_level
[0]) {
2684 sprintf(card
->info
.mcl_level
, "%02x%02x",
2685 card
->info
.mcl_level
[2],
2686 card
->info
.mcl_level
[3]);
2690 case QETH_CARD_TYPE_IQD
:
2691 if ((card
->info
.guestlan
) ||
2692 (card
->info
.mcl_level
[0] & 0x80)) {
2693 card
->info
.mcl_level
[0] = (char) _ebcasc
[(__u8
)
2694 card
->info
.mcl_level
[0]];
2695 card
->info
.mcl_level
[1] = (char) _ebcasc
[(__u8
)
2696 card
->info
.mcl_level
[1]];
2697 card
->info
.mcl_level
[2] = (char) _ebcasc
[(__u8
)
2698 card
->info
.mcl_level
[2]];
2699 card
->info
.mcl_level
[3] = (char) _ebcasc
[(__u8
)
2700 card
->info
.mcl_level
[3]];
2701 card
->info
.mcl_level
[QETH_MCL_LENGTH
] = 0;
2705 memset(&card
->info
.mcl_level
[0], 0, QETH_MCL_LENGTH
+ 1);
2707 dev_info(&card
->gdev
->dev
,
2708 "Device is a%s card%s%s%s\nwith link type %s.\n",
2709 qeth_get_cardname(card
),
2710 (card
->info
.mcl_level
[0]) ? " (level: " : "",
2711 (card
->info
.mcl_level
[0]) ? card
->info
.mcl_level
: "",
2712 (card
->info
.mcl_level
[0]) ? ")" : "",
2713 qeth_get_cardname_short(card
));
2715 EXPORT_SYMBOL_GPL(qeth_print_status_message
);
2717 static void qeth_initialize_working_pool_list(struct qeth_card
*card
)
2719 struct qeth_buffer_pool_entry
*entry
;
2721 QETH_CARD_TEXT(card
, 5, "inwrklst");
2723 list_for_each_entry(entry
,
2724 &card
->qdio
.init_pool
.entry_list
, init_list
) {
2725 qeth_put_buffer_pool_entry(card
, entry
);
2729 static inline struct qeth_buffer_pool_entry
*qeth_find_free_buffer_pool_entry(
2730 struct qeth_card
*card
)
2732 struct list_head
*plh
;
2733 struct qeth_buffer_pool_entry
*entry
;
2737 if (list_empty(&card
->qdio
.in_buf_pool
.entry_list
))
2740 list_for_each(plh
, &card
->qdio
.in_buf_pool
.entry_list
) {
2741 entry
= list_entry(plh
, struct qeth_buffer_pool_entry
, list
);
2743 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(card
); ++i
) {
2744 if (page_count(virt_to_page(entry
->elements
[i
])) > 1) {
2750 list_del_init(&entry
->list
);
2755 /* no free buffer in pool so take first one and swap pages */
2756 entry
= list_entry(card
->qdio
.in_buf_pool
.entry_list
.next
,
2757 struct qeth_buffer_pool_entry
, list
);
2758 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(card
); ++i
) {
2759 if (page_count(virt_to_page(entry
->elements
[i
])) > 1) {
2760 page
= alloc_page(GFP_ATOMIC
);
2764 free_page((unsigned long)entry
->elements
[i
]);
2765 entry
->elements
[i
] = page_address(page
);
2766 if (card
->options
.performance_stats
)
2767 card
->perf_stats
.sg_alloc_page_rx
++;
2771 list_del_init(&entry
->list
);
2775 static int qeth_init_input_buffer(struct qeth_card
*card
,
2776 struct qeth_qdio_buffer
*buf
)
2778 struct qeth_buffer_pool_entry
*pool_entry
;
2781 if ((card
->options
.cq
== QETH_CQ_ENABLED
) && (!buf
->rx_skb
)) {
2782 buf
->rx_skb
= dev_alloc_skb(QETH_RX_PULL_LEN
+ ETH_HLEN
);
2787 pool_entry
= qeth_find_free_buffer_pool_entry(card
);
2792 * since the buffer is accessed only from the input_tasklet
2793 * there shouldn't be a need to synchronize; also, since we use
2794 * the QETH_IN_BUF_REQUEUE_THRESHOLD we should never run out off
2798 buf
->pool_entry
= pool_entry
;
2799 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(card
); ++i
) {
2800 buf
->buffer
->element
[i
].length
= PAGE_SIZE
;
2801 buf
->buffer
->element
[i
].addr
= pool_entry
->elements
[i
];
2802 if (i
== QETH_MAX_BUFFER_ELEMENTS(card
) - 1)
2803 buf
->buffer
->element
[i
].eflags
= SBAL_EFLAGS_LAST_ENTRY
;
2805 buf
->buffer
->element
[i
].eflags
= 0;
2806 buf
->buffer
->element
[i
].sflags
= 0;
2811 int qeth_init_qdio_queues(struct qeth_card
*card
)
2816 QETH_DBF_TEXT(SETUP
, 2, "initqdqs");
2819 qdio_reset_buffers(card
->qdio
.in_q
->qdio_bufs
,
2820 QDIO_MAX_BUFFERS_PER_Q
);
2821 qeth_initialize_working_pool_list(card
);
2822 /*give only as many buffers to hardware as we have buffer pool entries*/
2823 for (i
= 0; i
< card
->qdio
.in_buf_pool
.buf_count
- 1; ++i
)
2824 qeth_init_input_buffer(card
, &card
->qdio
.in_q
->bufs
[i
]);
2825 card
->qdio
.in_q
->next_buf_to_init
=
2826 card
->qdio
.in_buf_pool
.buf_count
- 1;
2827 rc
= do_QDIO(CARD_DDEV(card
), QDIO_FLAG_SYNC_INPUT
, 0, 0,
2828 card
->qdio
.in_buf_pool
.buf_count
- 1);
2830 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
2835 rc
= qeth_cq_init(card
);
2840 /* outbound queue */
2841 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
2842 qdio_reset_buffers(card
->qdio
.out_qs
[i
]->qdio_bufs
,
2843 QDIO_MAX_BUFFERS_PER_Q
);
2844 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
) {
2845 qeth_clear_output_buffer(card
->qdio
.out_qs
[i
],
2846 card
->qdio
.out_qs
[i
]->bufs
[j
],
2847 QETH_QDIO_BUF_EMPTY
);
2849 card
->qdio
.out_qs
[i
]->card
= card
;
2850 card
->qdio
.out_qs
[i
]->next_buf_to_fill
= 0;
2851 card
->qdio
.out_qs
[i
]->do_pack
= 0;
2852 atomic_set(&card
->qdio
.out_qs
[i
]->used_buffers
, 0);
2853 atomic_set(&card
->qdio
.out_qs
[i
]->set_pci_flags_count
, 0);
2854 atomic_set(&card
->qdio
.out_qs
[i
]->state
,
2855 QETH_OUT_Q_UNLOCKED
);
2859 EXPORT_SYMBOL_GPL(qeth_init_qdio_queues
);
2861 static inline __u8
qeth_get_ipa_adp_type(enum qeth_link_types link_type
)
2863 switch (link_type
) {
2864 case QETH_LINK_TYPE_HSTR
:
2871 static void qeth_fill_ipacmd_header(struct qeth_card
*card
,
2872 struct qeth_ipa_cmd
*cmd
, __u8 command
,
2873 enum qeth_prot_versions prot
)
2875 memset(cmd
, 0, sizeof(struct qeth_ipa_cmd
));
2876 cmd
->hdr
.command
= command
;
2877 cmd
->hdr
.initiator
= IPA_CMD_INITIATOR_HOST
;
2878 cmd
->hdr
.seqno
= card
->seqno
.ipa
;
2879 cmd
->hdr
.adapter_type
= qeth_get_ipa_adp_type(card
->info
.link_type
);
2880 cmd
->hdr
.rel_adapter_no
= (__u8
) card
->info
.portno
;
2881 if (card
->options
.layer2
)
2882 cmd
->hdr
.prim_version_no
= 2;
2884 cmd
->hdr
.prim_version_no
= 1;
2885 cmd
->hdr
.param_count
= 1;
2886 cmd
->hdr
.prot_version
= prot
;
2887 cmd
->hdr
.ipa_supported
= 0;
2888 cmd
->hdr
.ipa_enabled
= 0;
2891 struct qeth_cmd_buffer
*qeth_get_ipacmd_buffer(struct qeth_card
*card
,
2892 enum qeth_ipa_cmds ipacmd
, enum qeth_prot_versions prot
)
2894 struct qeth_cmd_buffer
*iob
;
2895 struct qeth_ipa_cmd
*cmd
;
2897 iob
= qeth_get_buffer(&card
->write
);
2899 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
2900 qeth_fill_ipacmd_header(card
, cmd
, ipacmd
, prot
);
2902 dev_warn(&card
->gdev
->dev
,
2903 "The qeth driver ran out of channel command buffers\n");
2904 QETH_DBF_MESSAGE(1, "%s The qeth driver ran out of channel command buffers",
2905 dev_name(&card
->gdev
->dev
));
2910 EXPORT_SYMBOL_GPL(qeth_get_ipacmd_buffer
);
2912 void qeth_prepare_ipa_cmd(struct qeth_card
*card
, struct qeth_cmd_buffer
*iob
,
2915 memcpy(iob
->data
, IPA_PDU_HEADER
, IPA_PDU_HEADER_SIZE
);
2916 memcpy(QETH_IPA_CMD_PROT_TYPE(iob
->data
), &prot_type
, 1);
2917 memcpy(QETH_IPA_CMD_DEST_ADDR(iob
->data
),
2918 &card
->token
.ulp_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2920 EXPORT_SYMBOL_GPL(qeth_prepare_ipa_cmd
);
2923 * qeth_send_ipa_cmd() - send an IPA command
2925 * See qeth_send_control_data() for explanation of the arguments.
2928 int qeth_send_ipa_cmd(struct qeth_card
*card
, struct qeth_cmd_buffer
*iob
,
2929 int (*reply_cb
)(struct qeth_card
*, struct qeth_reply
*,
2936 QETH_CARD_TEXT(card
, 4, "sendipa");
2938 if (card
->options
.layer2
)
2939 if (card
->info
.type
== QETH_CARD_TYPE_OSN
)
2940 prot_type
= QETH_PROT_OSN2
;
2942 prot_type
= QETH_PROT_LAYER2
;
2944 prot_type
= QETH_PROT_TCPIP
;
2945 qeth_prepare_ipa_cmd(card
, iob
, prot_type
);
2946 rc
= qeth_send_control_data(card
, IPA_CMD_LENGTH
,
2947 iob
, reply_cb
, reply_param
);
2949 qeth_clear_ipacmd_list(card
);
2950 qeth_schedule_recovery(card
);
2954 EXPORT_SYMBOL_GPL(qeth_send_ipa_cmd
);
2956 int qeth_send_startlan(struct qeth_card
*card
)
2959 struct qeth_cmd_buffer
*iob
;
2961 QETH_DBF_TEXT(SETUP
, 2, "strtlan");
2963 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_STARTLAN
, 0);
2966 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
2969 EXPORT_SYMBOL_GPL(qeth_send_startlan
);
2971 static int qeth_default_setadapterparms_cb(struct qeth_card
*card
,
2972 struct qeth_reply
*reply
, unsigned long data
)
2974 struct qeth_ipa_cmd
*cmd
;
2976 QETH_CARD_TEXT(card
, 4, "defadpcb");
2978 cmd
= (struct qeth_ipa_cmd
*) data
;
2979 if (cmd
->hdr
.return_code
== 0)
2980 cmd
->hdr
.return_code
=
2981 cmd
->data
.setadapterparms
.hdr
.return_code
;
2985 static int qeth_query_setadapterparms_cb(struct qeth_card
*card
,
2986 struct qeth_reply
*reply
, unsigned long data
)
2988 struct qeth_ipa_cmd
*cmd
;
2990 QETH_CARD_TEXT(card
, 3, "quyadpcb");
2992 cmd
= (struct qeth_ipa_cmd
*) data
;
2993 if (cmd
->data
.setadapterparms
.data
.query_cmds_supp
.lan_type
& 0x7f) {
2994 card
->info
.link_type
=
2995 cmd
->data
.setadapterparms
.data
.query_cmds_supp
.lan_type
;
2996 QETH_DBF_TEXT_(SETUP
, 2, "lnk %d", card
->info
.link_type
);
2998 card
->options
.adp
.supported_funcs
=
2999 cmd
->data
.setadapterparms
.data
.query_cmds_supp
.supported_cmds
;
3000 return qeth_default_setadapterparms_cb(card
, reply
, (unsigned long)cmd
);
3003 static struct qeth_cmd_buffer
*qeth_get_adapter_cmd(struct qeth_card
*card
,
3004 __u32 command
, __u32 cmdlen
)
3006 struct qeth_cmd_buffer
*iob
;
3007 struct qeth_ipa_cmd
*cmd
;
3009 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SETADAPTERPARMS
,
3012 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
3013 cmd
->data
.setadapterparms
.hdr
.cmdlength
= cmdlen
;
3014 cmd
->data
.setadapterparms
.hdr
.command_code
= command
;
3015 cmd
->data
.setadapterparms
.hdr
.used_total
= 1;
3016 cmd
->data
.setadapterparms
.hdr
.seq_no
= 1;
3022 int qeth_query_setadapterparms(struct qeth_card
*card
)
3025 struct qeth_cmd_buffer
*iob
;
3027 QETH_CARD_TEXT(card
, 3, "queryadp");
3028 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_QUERY_COMMANDS_SUPPORTED
,
3029 sizeof(struct qeth_ipacmd_setadpparms
));
3032 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_query_setadapterparms_cb
, NULL
);
3035 EXPORT_SYMBOL_GPL(qeth_query_setadapterparms
);
3037 static int qeth_query_ipassists_cb(struct qeth_card
*card
,
3038 struct qeth_reply
*reply
, unsigned long data
)
3040 struct qeth_ipa_cmd
*cmd
;
3042 QETH_DBF_TEXT(SETUP
, 2, "qipasscb");
3044 cmd
= (struct qeth_ipa_cmd
*) data
;
3046 switch (cmd
->hdr
.return_code
) {
3047 case IPA_RC_NOTSUPP
:
3048 case IPA_RC_L2_UNSUPPORTED_CMD
:
3049 QETH_DBF_TEXT(SETUP
, 2, "ipaunsup");
3050 card
->options
.ipa4
.supported_funcs
|= IPA_SETADAPTERPARMS
;
3051 card
->options
.ipa6
.supported_funcs
|= IPA_SETADAPTERPARMS
;
3054 if (cmd
->hdr
.return_code
) {
3055 QETH_DBF_MESSAGE(1, "%s IPA_CMD_QIPASSIST: Unhandled "
3057 dev_name(&card
->gdev
->dev
),
3058 cmd
->hdr
.return_code
);
3063 if (cmd
->hdr
.prot_version
== QETH_PROT_IPV4
) {
3064 card
->options
.ipa4
.supported_funcs
= cmd
->hdr
.ipa_supported
;
3065 card
->options
.ipa4
.enabled_funcs
= cmd
->hdr
.ipa_enabled
;
3066 } else if (cmd
->hdr
.prot_version
== QETH_PROT_IPV6
) {
3067 card
->options
.ipa6
.supported_funcs
= cmd
->hdr
.ipa_supported
;
3068 card
->options
.ipa6
.enabled_funcs
= cmd
->hdr
.ipa_enabled
;
3070 QETH_DBF_MESSAGE(1, "%s IPA_CMD_QIPASSIST: Flawed LIC detected"
3071 "\n", dev_name(&card
->gdev
->dev
));
3075 int qeth_query_ipassists(struct qeth_card
*card
, enum qeth_prot_versions prot
)
3078 struct qeth_cmd_buffer
*iob
;
3080 QETH_DBF_TEXT_(SETUP
, 2, "qipassi%i", prot
);
3081 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_QIPASSIST
, prot
);
3084 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_query_ipassists_cb
, NULL
);
3087 EXPORT_SYMBOL_GPL(qeth_query_ipassists
);
3089 static int qeth_query_switch_attributes_cb(struct qeth_card
*card
,
3090 struct qeth_reply
*reply
, unsigned long data
)
3092 struct qeth_ipa_cmd
*cmd
;
3093 struct qeth_switch_info
*sw_info
;
3094 struct qeth_query_switch_attributes
*attrs
;
3096 QETH_CARD_TEXT(card
, 2, "qswiatcb");
3097 cmd
= (struct qeth_ipa_cmd
*) data
;
3098 sw_info
= (struct qeth_switch_info
*)reply
->param
;
3099 if (cmd
->data
.setadapterparms
.hdr
.return_code
== 0) {
3100 attrs
= &cmd
->data
.setadapterparms
.data
.query_switch_attributes
;
3101 sw_info
->capabilities
= attrs
->capabilities
;
3102 sw_info
->settings
= attrs
->settings
;
3103 QETH_CARD_TEXT_(card
, 2, "%04x%04x", sw_info
->capabilities
,
3106 qeth_default_setadapterparms_cb(card
, reply
, (unsigned long) cmd
);
3111 int qeth_query_switch_attributes(struct qeth_card
*card
,
3112 struct qeth_switch_info
*sw_info
)
3114 struct qeth_cmd_buffer
*iob
;
3116 QETH_CARD_TEXT(card
, 2, "qswiattr");
3117 if (!qeth_adp_supported(card
, IPA_SETADP_QUERY_SWITCH_ATTRIBUTES
))
3119 if (!netif_carrier_ok(card
->dev
))
3121 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_QUERY_SWITCH_ATTRIBUTES
,
3122 sizeof(struct qeth_ipacmd_setadpparms_hdr
));
3125 return qeth_send_ipa_cmd(card
, iob
,
3126 qeth_query_switch_attributes_cb
, sw_info
);
3128 EXPORT_SYMBOL_GPL(qeth_query_switch_attributes
);
3130 static int qeth_query_setdiagass_cb(struct qeth_card
*card
,
3131 struct qeth_reply
*reply
, unsigned long data
)
3133 struct qeth_ipa_cmd
*cmd
;
3136 cmd
= (struct qeth_ipa_cmd
*)data
;
3137 rc
= cmd
->hdr
.return_code
;
3139 QETH_CARD_TEXT_(card
, 2, "diagq:%x", rc
);
3141 card
->info
.diagass_support
= cmd
->data
.diagass
.ext
;
3145 static int qeth_query_setdiagass(struct qeth_card
*card
)
3147 struct qeth_cmd_buffer
*iob
;
3148 struct qeth_ipa_cmd
*cmd
;
3150 QETH_DBF_TEXT(SETUP
, 2, "qdiagass");
3151 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SET_DIAG_ASS
, 0);
3154 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
3155 cmd
->data
.diagass
.subcmd_len
= 16;
3156 cmd
->data
.diagass
.subcmd
= QETH_DIAGS_CMD_QUERY
;
3157 return qeth_send_ipa_cmd(card
, iob
, qeth_query_setdiagass_cb
, NULL
);
3160 static void qeth_get_trap_id(struct qeth_card
*card
, struct qeth_trap_id
*tid
)
3162 unsigned long info
= get_zeroed_page(GFP_KERNEL
);
3163 struct sysinfo_2_2_2
*info222
= (struct sysinfo_2_2_2
*)info
;
3164 struct sysinfo_3_2_2
*info322
= (struct sysinfo_3_2_2
*)info
;
3165 struct ccw_dev_id ccwid
;
3168 tid
->chpid
= card
->info
.chpid
;
3169 ccw_device_get_id(CARD_RDEV(card
), &ccwid
);
3170 tid
->ssid
= ccwid
.ssid
;
3171 tid
->devno
= ccwid
.devno
;
3174 level
= stsi(NULL
, 0, 0, 0);
3175 if ((level
>= 2) && (stsi(info222
, 2, 2, 2) == 0))
3176 tid
->lparnr
= info222
->lpar_number
;
3177 if ((level
>= 3) && (stsi(info322
, 3, 2, 2) == 0)) {
3178 EBCASC(info322
->vm
[0].name
, sizeof(info322
->vm
[0].name
));
3179 memcpy(tid
->vmname
, info322
->vm
[0].name
, sizeof(tid
->vmname
));
3185 static int qeth_hw_trap_cb(struct qeth_card
*card
,
3186 struct qeth_reply
*reply
, unsigned long data
)
3188 struct qeth_ipa_cmd
*cmd
;
3191 cmd
= (struct qeth_ipa_cmd
*)data
;
3192 rc
= cmd
->hdr
.return_code
;
3194 QETH_CARD_TEXT_(card
, 2, "trapc:%x", rc
);
3198 int qeth_hw_trap(struct qeth_card
*card
, enum qeth_diags_trap_action action
)
3200 struct qeth_cmd_buffer
*iob
;
3201 struct qeth_ipa_cmd
*cmd
;
3203 QETH_DBF_TEXT(SETUP
, 2, "diagtrap");
3204 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SET_DIAG_ASS
, 0);
3207 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
3208 cmd
->data
.diagass
.subcmd_len
= 80;
3209 cmd
->data
.diagass
.subcmd
= QETH_DIAGS_CMD_TRAP
;
3210 cmd
->data
.diagass
.type
= 1;
3211 cmd
->data
.diagass
.action
= action
;
3213 case QETH_DIAGS_TRAP_ARM
:
3214 cmd
->data
.diagass
.options
= 0x0003;
3215 cmd
->data
.diagass
.ext
= 0x00010000 +
3216 sizeof(struct qeth_trap_id
);
3217 qeth_get_trap_id(card
,
3218 (struct qeth_trap_id
*)cmd
->data
.diagass
.cdata
);
3220 case QETH_DIAGS_TRAP_DISARM
:
3221 cmd
->data
.diagass
.options
= 0x0001;
3223 case QETH_DIAGS_TRAP_CAPTURE
:
3226 return qeth_send_ipa_cmd(card
, iob
, qeth_hw_trap_cb
, NULL
);
3228 EXPORT_SYMBOL_GPL(qeth_hw_trap
);
3230 int qeth_check_qdio_errors(struct qeth_card
*card
, struct qdio_buffer
*buf
,
3231 unsigned int qdio_error
, const char *dbftext
)
3234 QETH_CARD_TEXT(card
, 2, dbftext
);
3235 QETH_CARD_TEXT_(card
, 2, " F15=%02X",
3236 buf
->element
[15].sflags
);
3237 QETH_CARD_TEXT_(card
, 2, " F14=%02X",
3238 buf
->element
[14].sflags
);
3239 QETH_CARD_TEXT_(card
, 2, " qerr=%X", qdio_error
);
3240 if ((buf
->element
[15].sflags
) == 0x12) {
3241 card
->stats
.rx_dropped
++;
3248 EXPORT_SYMBOL_GPL(qeth_check_qdio_errors
);
3250 static void qeth_buffer_reclaim_work(struct work_struct
*work
)
3252 struct qeth_card
*card
= container_of(work
, struct qeth_card
,
3253 buffer_reclaim_work
.work
);
3255 QETH_CARD_TEXT_(card
, 2, "brw:%x", card
->reclaim_index
);
3256 qeth_queue_input_buffer(card
, card
->reclaim_index
);
3259 void qeth_queue_input_buffer(struct qeth_card
*card
, int index
)
3261 struct qeth_qdio_q
*queue
= card
->qdio
.in_q
;
3262 struct list_head
*lh
;
3268 count
= (index
< queue
->next_buf_to_init
)?
3269 card
->qdio
.in_buf_pool
.buf_count
-
3270 (queue
->next_buf_to_init
- index
) :
3271 card
->qdio
.in_buf_pool
.buf_count
-
3272 (queue
->next_buf_to_init
+ QDIO_MAX_BUFFERS_PER_Q
- index
);
3273 /* only requeue at a certain threshold to avoid SIGAs */
3274 if (count
>= QETH_IN_BUF_REQUEUE_THRESHOLD(card
)) {
3275 for (i
= queue
->next_buf_to_init
;
3276 i
< queue
->next_buf_to_init
+ count
; ++i
) {
3277 if (qeth_init_input_buffer(card
,
3278 &queue
->bufs
[i
% QDIO_MAX_BUFFERS_PER_Q
])) {
3285 if (newcount
< count
) {
3286 /* we are in memory shortage so we switch back to
3287 traditional skb allocation and drop packages */
3288 atomic_set(&card
->force_alloc_skb
, 3);
3291 atomic_add_unless(&card
->force_alloc_skb
, -1, 0);
3296 list_for_each(lh
, &card
->qdio
.in_buf_pool
.entry_list
)
3298 if (i
== card
->qdio
.in_buf_pool
.buf_count
) {
3299 QETH_CARD_TEXT(card
, 2, "qsarbw");
3300 card
->reclaim_index
= index
;
3301 schedule_delayed_work(
3302 &card
->buffer_reclaim_work
,
3303 QETH_RECLAIM_WORK_TIME
);
3309 * according to old code it should be avoided to requeue all
3310 * 128 buffers in order to benefit from PCI avoidance.
3311 * this function keeps at least one buffer (the buffer at
3312 * 'index') un-requeued -> this buffer is the first buffer that
3313 * will be requeued the next time
3315 if (card
->options
.performance_stats
) {
3316 card
->perf_stats
.inbound_do_qdio_cnt
++;
3317 card
->perf_stats
.inbound_do_qdio_start_time
=
3320 rc
= do_QDIO(CARD_DDEV(card
), QDIO_FLAG_SYNC_INPUT
, 0,
3321 queue
->next_buf_to_init
, count
);
3322 if (card
->options
.performance_stats
)
3323 card
->perf_stats
.inbound_do_qdio_time
+=
3325 card
->perf_stats
.inbound_do_qdio_start_time
;
3327 QETH_CARD_TEXT(card
, 2, "qinberr");
3329 queue
->next_buf_to_init
= (queue
->next_buf_to_init
+ count
) %
3330 QDIO_MAX_BUFFERS_PER_Q
;
3333 EXPORT_SYMBOL_GPL(qeth_queue_input_buffer
);
3335 static int qeth_handle_send_error(struct qeth_card
*card
,
3336 struct qeth_qdio_out_buffer
*buffer
, unsigned int qdio_err
)
3338 int sbalf15
= buffer
->buffer
->element
[15].sflags
;
3340 QETH_CARD_TEXT(card
, 6, "hdsnderr");
3341 if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
3348 qeth_check_qdio_errors(card
, buffer
->buffer
, qdio_err
, "qouterr");
3351 return QETH_SEND_ERROR_NONE
;
3353 if ((sbalf15
>= 15) && (sbalf15
<= 31))
3354 return QETH_SEND_ERROR_RETRY
;
3356 QETH_CARD_TEXT(card
, 1, "lnkfail");
3357 QETH_CARD_TEXT_(card
, 1, "%04x %02x",
3358 (u16
)qdio_err
, (u8
)sbalf15
);
3359 return QETH_SEND_ERROR_LINK_FAILURE
;
3363 * Switched to packing state if the number of used buffers on a queue
3364 * reaches a certain limit.
3366 static void qeth_switch_to_packing_if_needed(struct qeth_qdio_out_q
*queue
)
3368 if (!queue
->do_pack
) {
3369 if (atomic_read(&queue
->used_buffers
)
3370 >= QETH_HIGH_WATERMARK_PACK
){
3371 /* switch non-PACKING -> PACKING */
3372 QETH_CARD_TEXT(queue
->card
, 6, "np->pack");
3373 if (queue
->card
->options
.performance_stats
)
3374 queue
->card
->perf_stats
.sc_dp_p
++;
3381 * Switches from packing to non-packing mode. If there is a packing
3382 * buffer on the queue this buffer will be prepared to be flushed.
3383 * In that case 1 is returned to inform the caller. If no buffer
3384 * has to be flushed, zero is returned.
3386 static int qeth_switch_to_nonpacking_if_needed(struct qeth_qdio_out_q
*queue
)
3388 struct qeth_qdio_out_buffer
*buffer
;
3389 int flush_count
= 0;
3391 if (queue
->do_pack
) {
3392 if (atomic_read(&queue
->used_buffers
)
3393 <= QETH_LOW_WATERMARK_PACK
) {
3394 /* switch PACKING -> non-PACKING */
3395 QETH_CARD_TEXT(queue
->card
, 6, "pack->np");
3396 if (queue
->card
->options
.performance_stats
)
3397 queue
->card
->perf_stats
.sc_p_dp
++;
3399 /* flush packing buffers */
3400 buffer
= queue
->bufs
[queue
->next_buf_to_fill
];
3401 if ((atomic_read(&buffer
->state
) ==
3402 QETH_QDIO_BUF_EMPTY
) &&
3403 (buffer
->next_element_to_fill
> 0)) {
3404 atomic_set(&buffer
->state
,
3405 QETH_QDIO_BUF_PRIMED
);
3407 queue
->next_buf_to_fill
=
3408 (queue
->next_buf_to_fill
+ 1) %
3409 QDIO_MAX_BUFFERS_PER_Q
;
3418 * Called to flush a packing buffer if no more pci flags are on the queue.
3419 * Checks if there is a packing buffer and prepares it to be flushed.
3420 * In that case returns 1, otherwise zero.
3422 static int qeth_flush_buffers_on_no_pci(struct qeth_qdio_out_q
*queue
)
3424 struct qeth_qdio_out_buffer
*buffer
;
3426 buffer
= queue
->bufs
[queue
->next_buf_to_fill
];
3427 if ((atomic_read(&buffer
->state
) == QETH_QDIO_BUF_EMPTY
) &&
3428 (buffer
->next_element_to_fill
> 0)) {
3429 /* it's a packing buffer */
3430 atomic_set(&buffer
->state
, QETH_QDIO_BUF_PRIMED
);
3431 queue
->next_buf_to_fill
=
3432 (queue
->next_buf_to_fill
+ 1) % QDIO_MAX_BUFFERS_PER_Q
;
3438 static void qeth_flush_buffers(struct qeth_qdio_out_q
*queue
, int index
,
3441 struct qeth_qdio_out_buffer
*buf
;
3444 unsigned int qdio_flags
;
3446 for (i
= index
; i
< index
+ count
; ++i
) {
3447 int bidx
= i
% QDIO_MAX_BUFFERS_PER_Q
;
3448 buf
= queue
->bufs
[bidx
];
3449 buf
->buffer
->element
[buf
->next_element_to_fill
- 1].eflags
|=
3450 SBAL_EFLAGS_LAST_ENTRY
;
3452 if (queue
->bufstates
)
3453 queue
->bufstates
[bidx
].user
= buf
;
3455 if (queue
->card
->info
.type
== QETH_CARD_TYPE_IQD
)
3458 if (!queue
->do_pack
) {
3459 if ((atomic_read(&queue
->used_buffers
) >=
3460 (QETH_HIGH_WATERMARK_PACK
-
3461 QETH_WATERMARK_PACK_FUZZ
)) &&
3462 !atomic_read(&queue
->set_pci_flags_count
)) {
3463 /* it's likely that we'll go to packing
3465 atomic_inc(&queue
->set_pci_flags_count
);
3466 buf
->buffer
->element
[0].sflags
|= SBAL_SFLAGS0_PCI_REQ
;
3469 if (!atomic_read(&queue
->set_pci_flags_count
)) {
3471 * there's no outstanding PCI any more, so we
3472 * have to request a PCI to be sure the the PCI
3473 * will wake at some time in the future then we
3474 * can flush packed buffers that might still be
3475 * hanging around, which can happen if no
3476 * further send was requested by the stack
3478 atomic_inc(&queue
->set_pci_flags_count
);
3479 buf
->buffer
->element
[0].sflags
|= SBAL_SFLAGS0_PCI_REQ
;
3484 queue
->card
->dev
->trans_start
= jiffies
;
3485 if (queue
->card
->options
.performance_stats
) {
3486 queue
->card
->perf_stats
.outbound_do_qdio_cnt
++;
3487 queue
->card
->perf_stats
.outbound_do_qdio_start_time
=
3490 qdio_flags
= QDIO_FLAG_SYNC_OUTPUT
;
3491 if (atomic_read(&queue
->set_pci_flags_count
))
3492 qdio_flags
|= QDIO_FLAG_PCI_OUT
;
3493 rc
= do_QDIO(CARD_DDEV(queue
->card
), qdio_flags
,
3494 queue
->queue_no
, index
, count
);
3495 if (queue
->card
->options
.performance_stats
)
3496 queue
->card
->perf_stats
.outbound_do_qdio_time
+=
3498 queue
->card
->perf_stats
.outbound_do_qdio_start_time
;
3499 atomic_add(count
, &queue
->used_buffers
);
3501 queue
->card
->stats
.tx_errors
+= count
;
3502 /* ignore temporary SIGA errors without busy condition */
3505 QETH_CARD_TEXT(queue
->card
, 2, "flushbuf");
3506 QETH_CARD_TEXT_(queue
->card
, 2, " q%d", queue
->queue_no
);
3507 QETH_CARD_TEXT_(queue
->card
, 2, " idx%d", index
);
3508 QETH_CARD_TEXT_(queue
->card
, 2, " c%d", count
);
3509 QETH_CARD_TEXT_(queue
->card
, 2, " err%d", rc
);
3511 /* this must not happen under normal circumstances. if it
3512 * happens something is really wrong -> recover */
3513 qeth_schedule_recovery(queue
->card
);
3516 if (queue
->card
->options
.performance_stats
)
3517 queue
->card
->perf_stats
.bufs_sent
+= count
;
3520 static void qeth_check_outbound_queue(struct qeth_qdio_out_q
*queue
)
3524 int q_was_packing
= 0;
3527 * check if weed have to switch to non-packing mode or if
3528 * we have to get a pci flag out on the queue
3530 if ((atomic_read(&queue
->used_buffers
) <= QETH_LOW_WATERMARK_PACK
) ||
3531 !atomic_read(&queue
->set_pci_flags_count
)) {
3532 if (atomic_xchg(&queue
->state
, QETH_OUT_Q_LOCKED_FLUSH
) ==
3533 QETH_OUT_Q_UNLOCKED
) {
3535 * If we get in here, there was no action in
3536 * do_send_packet. So, we check if there is a
3537 * packing buffer to be flushed here.
3539 netif_stop_queue(queue
->card
->dev
);
3540 index
= queue
->next_buf_to_fill
;
3541 q_was_packing
= queue
->do_pack
;
3542 /* queue->do_pack may change */
3544 flush_cnt
+= qeth_switch_to_nonpacking_if_needed(queue
);
3546 !atomic_read(&queue
->set_pci_flags_count
))
3548 qeth_flush_buffers_on_no_pci(queue
);
3549 if (queue
->card
->options
.performance_stats
&&
3551 queue
->card
->perf_stats
.bufs_sent_pack
+=
3554 qeth_flush_buffers(queue
, index
, flush_cnt
);
3555 atomic_set(&queue
->state
, QETH_OUT_Q_UNLOCKED
);
3560 void qeth_qdio_start_poll(struct ccw_device
*ccwdev
, int queue
,
3561 unsigned long card_ptr
)
3563 struct qeth_card
*card
= (struct qeth_card
*)card_ptr
;
3565 if (card
->dev
&& (card
->dev
->flags
& IFF_UP
))
3566 napi_schedule(&card
->napi
);
3568 EXPORT_SYMBOL_GPL(qeth_qdio_start_poll
);
3570 int qeth_configure_cq(struct qeth_card
*card
, enum qeth_cq cq
)
3574 if (card
->options
.cq
== QETH_CQ_NOTAVAILABLE
) {
3578 if (card
->options
.cq
== cq
) {
3583 if (card
->state
!= CARD_STATE_DOWN
&&
3584 card
->state
!= CARD_STATE_RECOVER
) {
3589 qeth_free_qdio_buffers(card
);
3590 card
->options
.cq
= cq
;
3597 EXPORT_SYMBOL_GPL(qeth_configure_cq
);
3600 static void qeth_qdio_cq_handler(struct qeth_card
*card
,
3601 unsigned int qdio_err
,
3602 unsigned int queue
, int first_element
, int count
) {
3603 struct qeth_qdio_q
*cq
= card
->qdio
.c_q
;
3607 if (!qeth_is_cq(card
, queue
))
3610 QETH_CARD_TEXT_(card
, 5, "qcqhe%d", first_element
);
3611 QETH_CARD_TEXT_(card
, 5, "qcqhc%d", count
);
3612 QETH_CARD_TEXT_(card
, 5, "qcqherr%d", qdio_err
);
3615 netif_stop_queue(card
->dev
);
3616 qeth_schedule_recovery(card
);
3620 if (card
->options
.performance_stats
) {
3621 card
->perf_stats
.cq_cnt
++;
3622 card
->perf_stats
.cq_start_time
= qeth_get_micros();
3625 for (i
= first_element
; i
< first_element
+ count
; ++i
) {
3626 int bidx
= i
% QDIO_MAX_BUFFERS_PER_Q
;
3627 struct qdio_buffer
*buffer
= cq
->qdio_bufs
[bidx
];
3631 while (buffer
->element
[e
].addr
) {
3632 unsigned long phys_aob_addr
;
3634 phys_aob_addr
= (unsigned long) buffer
->element
[e
].addr
;
3635 qeth_qdio_handle_aob(card
, phys_aob_addr
);
3636 buffer
->element
[e
].addr
= NULL
;
3637 buffer
->element
[e
].eflags
= 0;
3638 buffer
->element
[e
].sflags
= 0;
3639 buffer
->element
[e
].length
= 0;
3644 buffer
->element
[15].eflags
= 0;
3645 buffer
->element
[15].sflags
= 0;
3647 rc
= do_QDIO(CARD_DDEV(card
), QDIO_FLAG_SYNC_INPUT
, queue
,
3648 card
->qdio
.c_q
->next_buf_to_init
,
3651 dev_warn(&card
->gdev
->dev
,
3652 "QDIO reported an error, rc=%i\n", rc
);
3653 QETH_CARD_TEXT(card
, 2, "qcqherr");
3655 card
->qdio
.c_q
->next_buf_to_init
= (card
->qdio
.c_q
->next_buf_to_init
3656 + count
) % QDIO_MAX_BUFFERS_PER_Q
;
3658 netif_wake_queue(card
->dev
);
3660 if (card
->options
.performance_stats
) {
3661 int delta_t
= qeth_get_micros();
3662 delta_t
-= card
->perf_stats
.cq_start_time
;
3663 card
->perf_stats
.cq_time
+= delta_t
;
3669 void qeth_qdio_input_handler(struct ccw_device
*ccwdev
, unsigned int qdio_err
,
3670 unsigned int queue
, int first_elem
, int count
,
3671 unsigned long card_ptr
)
3673 struct qeth_card
*card
= (struct qeth_card
*)card_ptr
;
3675 QETH_CARD_TEXT_(card
, 2, "qihq%d", queue
);
3676 QETH_CARD_TEXT_(card
, 2, "qiec%d", qdio_err
);
3678 if (qeth_is_cq(card
, queue
))
3679 qeth_qdio_cq_handler(card
, qdio_err
, queue
, first_elem
, count
);
3681 qeth_schedule_recovery(card
);
3685 EXPORT_SYMBOL_GPL(qeth_qdio_input_handler
);
3687 void qeth_qdio_output_handler(struct ccw_device
*ccwdev
,
3688 unsigned int qdio_error
, int __queue
, int first_element
,
3689 int count
, unsigned long card_ptr
)
3691 struct qeth_card
*card
= (struct qeth_card
*) card_ptr
;
3692 struct qeth_qdio_out_q
*queue
= card
->qdio
.out_qs
[__queue
];
3693 struct qeth_qdio_out_buffer
*buffer
;
3696 QETH_CARD_TEXT(card
, 6, "qdouhdl");
3697 if (qdio_error
& QDIO_ERROR_FATAL
) {
3698 QETH_CARD_TEXT(card
, 2, "achkcond");
3699 netif_stop_queue(card
->dev
);
3700 qeth_schedule_recovery(card
);
3703 if (card
->options
.performance_stats
) {
3704 card
->perf_stats
.outbound_handler_cnt
++;
3705 card
->perf_stats
.outbound_handler_start_time
=
3708 for (i
= first_element
; i
< (first_element
+ count
); ++i
) {
3709 int bidx
= i
% QDIO_MAX_BUFFERS_PER_Q
;
3710 buffer
= queue
->bufs
[bidx
];
3711 qeth_handle_send_error(card
, buffer
, qdio_error
);
3713 if (queue
->bufstates
&&
3714 (queue
->bufstates
[bidx
].flags
&
3715 QDIO_OUTBUF_STATE_FLAG_PENDING
) != 0) {
3716 WARN_ON_ONCE(card
->options
.cq
!= QETH_CQ_ENABLED
);
3718 if (atomic_cmpxchg(&buffer
->state
,
3719 QETH_QDIO_BUF_PRIMED
,
3720 QETH_QDIO_BUF_PENDING
) ==
3721 QETH_QDIO_BUF_PRIMED
) {
3722 qeth_notify_skbs(queue
, buffer
,
3725 buffer
->aob
= queue
->bufstates
[bidx
].aob
;
3726 QETH_CARD_TEXT_(queue
->card
, 5, "pel%d", bidx
);
3727 QETH_CARD_TEXT(queue
->card
, 5, "aob");
3728 QETH_CARD_TEXT_(queue
->card
, 5, "%lx",
3729 virt_to_phys(buffer
->aob
));
3730 if (qeth_init_qdio_out_buf(queue
, bidx
)) {
3731 QETH_CARD_TEXT(card
, 2, "outofbuf");
3732 qeth_schedule_recovery(card
);
3735 if (card
->options
.cq
== QETH_CQ_ENABLED
) {
3736 enum iucv_tx_notify n
;
3738 n
= qeth_compute_cq_notification(
3739 buffer
->buffer
->element
[15].sflags
, 0);
3740 qeth_notify_skbs(queue
, buffer
, n
);
3743 qeth_clear_output_buffer(queue
, buffer
,
3744 QETH_QDIO_BUF_EMPTY
);
3746 qeth_cleanup_handled_pending(queue
, bidx
, 0);
3748 atomic_sub(count
, &queue
->used_buffers
);
3749 /* check if we need to do something on this outbound queue */
3750 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
)
3751 qeth_check_outbound_queue(queue
);
3753 netif_wake_queue(queue
->card
->dev
);
3754 if (card
->options
.performance_stats
)
3755 card
->perf_stats
.outbound_handler_time
+= qeth_get_micros() -
3756 card
->perf_stats
.outbound_handler_start_time
;
3758 EXPORT_SYMBOL_GPL(qeth_qdio_output_handler
);
3761 * Note: Function assumes that we have 4 outbound queues.
3763 int qeth_get_priority_queue(struct qeth_card
*card
, struct sk_buff
*skb
,
3764 int ipv
, int cast_type
)
3769 if (cast_type
&& card
->info
.is_multicast_different
)
3770 return card
->info
.is_multicast_different
&
3771 (card
->qdio
.no_out_queues
- 1);
3773 switch (card
->qdio
.do_prio_queueing
) {
3774 case QETH_PRIO_Q_ING_TOS
:
3775 case QETH_PRIO_Q_ING_PREC
:
3778 tos
= ipv4_get_dsfield(ip_hdr(skb
));
3781 tos
= ipv6_get_dsfield(ipv6_hdr(skb
));
3784 return card
->qdio
.default_out_queue
;
3786 if (card
->qdio
.do_prio_queueing
== QETH_PRIO_Q_ING_PREC
)
3787 return ~tos
>> 6 & 3;
3788 if (tos
& IPTOS_MINCOST
)
3790 if (tos
& IPTOS_RELIABILITY
)
3792 if (tos
& IPTOS_THROUGHPUT
)
3794 if (tos
& IPTOS_LOWDELAY
)
3797 case QETH_PRIO_Q_ING_SKB
:
3798 if (skb
->priority
> 5)
3800 return ~skb
->priority
>> 1 & 3;
3801 case QETH_PRIO_Q_ING_VLAN
:
3802 tci
= &((struct ethhdr
*)skb
->data
)->h_proto
;
3803 if (*tci
== ETH_P_8021Q
)
3804 return ~*(tci
+ 1) >> (VLAN_PRIO_SHIFT
+ 1) & 3;
3809 return card
->qdio
.default_out_queue
;
3811 EXPORT_SYMBOL_GPL(qeth_get_priority_queue
);
3813 int qeth_get_elements_for_frags(struct sk_buff
*skb
)
3815 int cnt
, length
, e
, elements
= 0;
3816 struct skb_frag_struct
*frag
;
3819 for (cnt
= 0; cnt
< skb_shinfo(skb
)->nr_frags
; cnt
++) {
3820 frag
= &skb_shinfo(skb
)->frags
[cnt
];
3821 data
= (char *)page_to_phys(skb_frag_page(frag
)) +
3823 length
= frag
->size
;
3824 e
= PFN_UP((unsigned long)data
+ length
- 1) -
3825 PFN_DOWN((unsigned long)data
);
3830 EXPORT_SYMBOL_GPL(qeth_get_elements_for_frags
);
3832 int qeth_get_elements_no(struct qeth_card
*card
,
3833 struct sk_buff
*skb
, int elems
)
3835 int dlen
= skb
->len
- skb
->data_len
;
3836 int elements_needed
= PFN_UP((unsigned long)skb
->data
+ dlen
- 1) -
3837 PFN_DOWN((unsigned long)skb
->data
);
3839 elements_needed
+= qeth_get_elements_for_frags(skb
);
3841 if ((elements_needed
+ elems
) > QETH_MAX_BUFFER_ELEMENTS(card
)) {
3842 QETH_DBF_MESSAGE(2, "Invalid size of IP packet "
3843 "(Number=%d / Length=%d). Discarded.\n",
3844 (elements_needed
+elems
), skb
->len
);
3847 return elements_needed
;
3849 EXPORT_SYMBOL_GPL(qeth_get_elements_no
);
3851 int qeth_hdr_chk_and_bounce(struct sk_buff
*skb
, struct qeth_hdr
**hdr
, int len
)
3853 int hroom
, inpage
, rest
;
3855 if (((unsigned long)skb
->data
& PAGE_MASK
) !=
3856 (((unsigned long)skb
->data
+ len
- 1) & PAGE_MASK
)) {
3857 hroom
= skb_headroom(skb
);
3858 inpage
= PAGE_SIZE
- ((unsigned long) skb
->data
% PAGE_SIZE
);
3859 rest
= len
- inpage
;
3862 memmove(skb
->data
- rest
, skb
->data
, skb
->len
- skb
->data_len
);
3865 *hdr
= (struct qeth_hdr
*)skb
->data
;
3866 QETH_DBF_MESSAGE(2, "skb bounce len: %d rest: %d\n", len
, rest
);
3870 EXPORT_SYMBOL_GPL(qeth_hdr_chk_and_bounce
);
3872 static inline void __qeth_fill_buffer(struct sk_buff
*skb
,
3873 struct qdio_buffer
*buffer
, int is_tso
, int *next_element_to_fill
,
3876 int length
= skb
->len
- skb
->data_len
;
3881 struct skb_frag_struct
*frag
;
3883 element
= *next_element_to_fill
;
3885 first_lap
= (is_tso
== 0 ? 1 : 0);
3888 data
= skb
->data
+ offset
;
3893 while (length
> 0) {
3894 /* length_here is the remaining amount of data in this page */
3895 length_here
= PAGE_SIZE
- ((unsigned long) data
% PAGE_SIZE
);
3896 if (length
< length_here
)
3897 length_here
= length
;
3899 buffer
->element
[element
].addr
= data
;
3900 buffer
->element
[element
].length
= length_here
;
3901 length
-= length_here
;
3904 if (skb_shinfo(skb
)->nr_frags
)
3905 buffer
->element
[element
].eflags
=
3906 SBAL_EFLAGS_FIRST_FRAG
;
3908 buffer
->element
[element
].eflags
= 0;
3910 buffer
->element
[element
].eflags
=
3911 SBAL_EFLAGS_MIDDLE_FRAG
;
3914 buffer
->element
[element
].eflags
=
3915 SBAL_EFLAGS_FIRST_FRAG
;
3917 buffer
->element
[element
].eflags
=
3918 SBAL_EFLAGS_MIDDLE_FRAG
;
3920 data
+= length_here
;
3925 for (cnt
= 0; cnt
< skb_shinfo(skb
)->nr_frags
; cnt
++) {
3926 frag
= &skb_shinfo(skb
)->frags
[cnt
];
3927 data
= (char *)page_to_phys(skb_frag_page(frag
)) +
3929 length
= frag
->size
;
3930 while (length
> 0) {
3931 length_here
= PAGE_SIZE
-
3932 ((unsigned long) data
% PAGE_SIZE
);
3933 if (length
< length_here
)
3934 length_here
= length
;
3936 buffer
->element
[element
].addr
= data
;
3937 buffer
->element
[element
].length
= length_here
;
3938 buffer
->element
[element
].eflags
=
3939 SBAL_EFLAGS_MIDDLE_FRAG
;
3940 length
-= length_here
;
3941 data
+= length_here
;
3946 if (buffer
->element
[element
- 1].eflags
)
3947 buffer
->element
[element
- 1].eflags
= SBAL_EFLAGS_LAST_FRAG
;
3948 *next_element_to_fill
= element
;
3951 static inline int qeth_fill_buffer(struct qeth_qdio_out_q
*queue
,
3952 struct qeth_qdio_out_buffer
*buf
, struct sk_buff
*skb
,
3953 struct qeth_hdr
*hdr
, int offset
, int hd_len
)
3955 struct qdio_buffer
*buffer
;
3956 int flush_cnt
= 0, hdr_len
, large_send
= 0;
3958 buffer
= buf
->buffer
;
3959 atomic_inc(&skb
->users
);
3960 skb_queue_tail(&buf
->skb_list
, skb
);
3962 /*check first on TSO ....*/
3963 if (hdr
->hdr
.l3
.id
== QETH_HEADER_TYPE_TSO
) {
3964 int element
= buf
->next_element_to_fill
;
3966 hdr_len
= sizeof(struct qeth_hdr_tso
) +
3967 ((struct qeth_hdr_tso
*)hdr
)->ext
.dg_hdr_len
;
3968 /*fill first buffer entry only with header information */
3969 buffer
->element
[element
].addr
= skb
->data
;
3970 buffer
->element
[element
].length
= hdr_len
;
3971 buffer
->element
[element
].eflags
= SBAL_EFLAGS_FIRST_FRAG
;
3972 buf
->next_element_to_fill
++;
3973 skb
->data
+= hdr_len
;
3974 skb
->len
-= hdr_len
;
3979 int element
= buf
->next_element_to_fill
;
3980 buffer
->element
[element
].addr
= hdr
;
3981 buffer
->element
[element
].length
= sizeof(struct qeth_hdr
) +
3983 buffer
->element
[element
].eflags
= SBAL_EFLAGS_FIRST_FRAG
;
3984 buf
->is_header
[element
] = 1;
3985 buf
->next_element_to_fill
++;
3988 __qeth_fill_buffer(skb
, buffer
, large_send
,
3989 (int *)&buf
->next_element_to_fill
, offset
);
3991 if (!queue
->do_pack
) {
3992 QETH_CARD_TEXT(queue
->card
, 6, "fillbfnp");
3993 /* set state to PRIMED -> will be flushed */
3994 atomic_set(&buf
->state
, QETH_QDIO_BUF_PRIMED
);
3997 QETH_CARD_TEXT(queue
->card
, 6, "fillbfpa");
3998 if (queue
->card
->options
.performance_stats
)
3999 queue
->card
->perf_stats
.skbs_sent_pack
++;
4000 if (buf
->next_element_to_fill
>=
4001 QETH_MAX_BUFFER_ELEMENTS(queue
->card
)) {
4003 * packed buffer if full -> set state PRIMED
4004 * -> will be flushed
4006 atomic_set(&buf
->state
, QETH_QDIO_BUF_PRIMED
);
4013 int qeth_do_send_packet_fast(struct qeth_card
*card
,
4014 struct qeth_qdio_out_q
*queue
, struct sk_buff
*skb
,
4015 struct qeth_hdr
*hdr
, int elements_needed
,
4016 int offset
, int hd_len
)
4018 struct qeth_qdio_out_buffer
*buffer
;
4021 /* spin until we get the queue ... */
4022 while (atomic_cmpxchg(&queue
->state
, QETH_OUT_Q_UNLOCKED
,
4023 QETH_OUT_Q_LOCKED
) != QETH_OUT_Q_UNLOCKED
);
4024 /* ... now we've got the queue */
4025 index
= queue
->next_buf_to_fill
;
4026 buffer
= queue
->bufs
[queue
->next_buf_to_fill
];
4028 * check if buffer is empty to make sure that we do not 'overtake'
4029 * ourselves and try to fill a buffer that is already primed
4031 if (atomic_read(&buffer
->state
) != QETH_QDIO_BUF_EMPTY
)
4033 queue
->next_buf_to_fill
= (queue
->next_buf_to_fill
+ 1) %
4034 QDIO_MAX_BUFFERS_PER_Q
;
4035 atomic_set(&queue
->state
, QETH_OUT_Q_UNLOCKED
);
4036 qeth_fill_buffer(queue
, buffer
, skb
, hdr
, offset
, hd_len
);
4037 qeth_flush_buffers(queue
, index
, 1);
4040 atomic_set(&queue
->state
, QETH_OUT_Q_UNLOCKED
);
4043 EXPORT_SYMBOL_GPL(qeth_do_send_packet_fast
);
4045 int qeth_do_send_packet(struct qeth_card
*card
, struct qeth_qdio_out_q
*queue
,
4046 struct sk_buff
*skb
, struct qeth_hdr
*hdr
,
4047 int elements_needed
)
4049 struct qeth_qdio_out_buffer
*buffer
;
4051 int flush_count
= 0;
4056 /* spin until we get the queue ... */
4057 while (atomic_cmpxchg(&queue
->state
, QETH_OUT_Q_UNLOCKED
,
4058 QETH_OUT_Q_LOCKED
) != QETH_OUT_Q_UNLOCKED
);
4059 start_index
= queue
->next_buf_to_fill
;
4060 buffer
= queue
->bufs
[queue
->next_buf_to_fill
];
4062 * check if buffer is empty to make sure that we do not 'overtake'
4063 * ourselves and try to fill a buffer that is already primed
4065 if (atomic_read(&buffer
->state
) != QETH_QDIO_BUF_EMPTY
) {
4066 atomic_set(&queue
->state
, QETH_OUT_Q_UNLOCKED
);
4069 /* check if we need to switch packing state of this queue */
4070 qeth_switch_to_packing_if_needed(queue
);
4071 if (queue
->do_pack
) {
4073 /* does packet fit in current buffer? */
4074 if ((QETH_MAX_BUFFER_ELEMENTS(card
) -
4075 buffer
->next_element_to_fill
) < elements_needed
) {
4076 /* ... no -> set state PRIMED */
4077 atomic_set(&buffer
->state
, QETH_QDIO_BUF_PRIMED
);
4079 queue
->next_buf_to_fill
=
4080 (queue
->next_buf_to_fill
+ 1) %
4081 QDIO_MAX_BUFFERS_PER_Q
;
4082 buffer
= queue
->bufs
[queue
->next_buf_to_fill
];
4083 /* we did a step forward, so check buffer state
4085 if (atomic_read(&buffer
->state
) !=
4086 QETH_QDIO_BUF_EMPTY
) {
4087 qeth_flush_buffers(queue
, start_index
,
4089 atomic_set(&queue
->state
,
4090 QETH_OUT_Q_UNLOCKED
);
4095 tmp
= qeth_fill_buffer(queue
, buffer
, skb
, hdr
, -1, 0);
4096 queue
->next_buf_to_fill
= (queue
->next_buf_to_fill
+ tmp
) %
4097 QDIO_MAX_BUFFERS_PER_Q
;
4100 qeth_flush_buffers(queue
, start_index
, flush_count
);
4101 else if (!atomic_read(&queue
->set_pci_flags_count
))
4102 atomic_xchg(&queue
->state
, QETH_OUT_Q_LOCKED_FLUSH
);
4104 * queue->state will go from LOCKED -> UNLOCKED or from
4105 * LOCKED_FLUSH -> LOCKED if output_handler wanted to 'notify' us
4106 * (switch packing state or flush buffer to get another pci flag out).
4107 * In that case we will enter this loop
4109 while (atomic_dec_return(&queue
->state
)) {
4111 start_index
= queue
->next_buf_to_fill
;
4112 /* check if we can go back to non-packing state */
4113 flush_count
+= qeth_switch_to_nonpacking_if_needed(queue
);
4115 * check if we need to flush a packing buffer to get a pci
4116 * flag out on the queue
4118 if (!flush_count
&& !atomic_read(&queue
->set_pci_flags_count
))
4119 flush_count
+= qeth_flush_buffers_on_no_pci(queue
);
4121 qeth_flush_buffers(queue
, start_index
, flush_count
);
4123 /* at this point the queue is UNLOCKED again */
4124 if (queue
->card
->options
.performance_stats
&& do_pack
)
4125 queue
->card
->perf_stats
.bufs_sent_pack
+= flush_count
;
4129 EXPORT_SYMBOL_GPL(qeth_do_send_packet
);
4131 static int qeth_setadp_promisc_mode_cb(struct qeth_card
*card
,
4132 struct qeth_reply
*reply
, unsigned long data
)
4134 struct qeth_ipa_cmd
*cmd
;
4135 struct qeth_ipacmd_setadpparms
*setparms
;
4137 QETH_CARD_TEXT(card
, 4, "prmadpcb");
4139 cmd
= (struct qeth_ipa_cmd
*) data
;
4140 setparms
= &(cmd
->data
.setadapterparms
);
4142 qeth_default_setadapterparms_cb(card
, reply
, (unsigned long)cmd
);
4143 if (cmd
->hdr
.return_code
) {
4144 QETH_CARD_TEXT_(card
, 4, "prmrc%x", cmd
->hdr
.return_code
);
4145 setparms
->data
.mode
= SET_PROMISC_MODE_OFF
;
4147 card
->info
.promisc_mode
= setparms
->data
.mode
;
4151 void qeth_setadp_promisc_mode(struct qeth_card
*card
)
4153 enum qeth_ipa_promisc_modes mode
;
4154 struct net_device
*dev
= card
->dev
;
4155 struct qeth_cmd_buffer
*iob
;
4156 struct qeth_ipa_cmd
*cmd
;
4158 QETH_CARD_TEXT(card
, 4, "setprom");
4160 if (((dev
->flags
& IFF_PROMISC
) &&
4161 (card
->info
.promisc_mode
== SET_PROMISC_MODE_ON
)) ||
4162 (!(dev
->flags
& IFF_PROMISC
) &&
4163 (card
->info
.promisc_mode
== SET_PROMISC_MODE_OFF
)))
4165 mode
= SET_PROMISC_MODE_OFF
;
4166 if (dev
->flags
& IFF_PROMISC
)
4167 mode
= SET_PROMISC_MODE_ON
;
4168 QETH_CARD_TEXT_(card
, 4, "mode:%x", mode
);
4170 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_SET_PROMISC_MODE
,
4171 sizeof(struct qeth_ipacmd_setadpparms_hdr
) + 8);
4174 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+ IPA_PDU_HEADER_SIZE
);
4175 cmd
->data
.setadapterparms
.data
.mode
= mode
;
4176 qeth_send_ipa_cmd(card
, iob
, qeth_setadp_promisc_mode_cb
, NULL
);
4178 EXPORT_SYMBOL_GPL(qeth_setadp_promisc_mode
);
4180 int qeth_change_mtu(struct net_device
*dev
, int new_mtu
)
4182 struct qeth_card
*card
;
4185 card
= dev
->ml_priv
;
4187 QETH_CARD_TEXT(card
, 4, "chgmtu");
4188 sprintf(dbf_text
, "%8x", new_mtu
);
4189 QETH_CARD_TEXT(card
, 4, dbf_text
);
4193 if (new_mtu
> 65535)
4195 if ((!qeth_is_supported(card
, IPA_IP_FRAGMENTATION
)) &&
4196 (!qeth_mtu_is_valid(card
, new_mtu
)))
4201 EXPORT_SYMBOL_GPL(qeth_change_mtu
);
4203 struct net_device_stats
*qeth_get_stats(struct net_device
*dev
)
4205 struct qeth_card
*card
;
4207 card
= dev
->ml_priv
;
4209 QETH_CARD_TEXT(card
, 5, "getstat");
4211 return &card
->stats
;
4213 EXPORT_SYMBOL_GPL(qeth_get_stats
);
4215 static int qeth_setadpparms_change_macaddr_cb(struct qeth_card
*card
,
4216 struct qeth_reply
*reply
, unsigned long data
)
4218 struct qeth_ipa_cmd
*cmd
;
4220 QETH_CARD_TEXT(card
, 4, "chgmaccb");
4222 cmd
= (struct qeth_ipa_cmd
*) data
;
4223 if (!card
->options
.layer2
||
4224 !(card
->info
.mac_bits
& QETH_LAYER2_MAC_READ
)) {
4225 memcpy(card
->dev
->dev_addr
,
4226 &cmd
->data
.setadapterparms
.data
.change_addr
.addr
,
4228 card
->info
.mac_bits
|= QETH_LAYER2_MAC_READ
;
4230 qeth_default_setadapterparms_cb(card
, reply
, (unsigned long) cmd
);
4234 int qeth_setadpparms_change_macaddr(struct qeth_card
*card
)
4237 struct qeth_cmd_buffer
*iob
;
4238 struct qeth_ipa_cmd
*cmd
;
4240 QETH_CARD_TEXT(card
, 4, "chgmac");
4242 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_ALTER_MAC_ADDRESS
,
4243 sizeof(struct qeth_ipacmd_setadpparms_hdr
) +
4244 sizeof(struct qeth_change_addr
));
4247 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
4248 cmd
->data
.setadapterparms
.data
.change_addr
.cmd
= CHANGE_ADDR_READ_MAC
;
4249 cmd
->data
.setadapterparms
.data
.change_addr
.addr_size
= OSA_ADDR_LEN
;
4250 memcpy(&cmd
->data
.setadapterparms
.data
.change_addr
.addr
,
4251 card
->dev
->dev_addr
, OSA_ADDR_LEN
);
4252 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_setadpparms_change_macaddr_cb
,
4256 EXPORT_SYMBOL_GPL(qeth_setadpparms_change_macaddr
);
4258 static int qeth_setadpparms_set_access_ctrl_cb(struct qeth_card
*card
,
4259 struct qeth_reply
*reply
, unsigned long data
)
4261 struct qeth_ipa_cmd
*cmd
;
4262 struct qeth_set_access_ctrl
*access_ctrl_req
;
4263 int fallback
= *(int *)reply
->param
;
4265 QETH_CARD_TEXT(card
, 4, "setaccb");
4267 cmd
= (struct qeth_ipa_cmd
*) data
;
4268 access_ctrl_req
= &cmd
->data
.setadapterparms
.data
.set_access_ctrl
;
4269 QETH_DBF_TEXT_(SETUP
, 2, "setaccb");
4270 QETH_DBF_TEXT_(SETUP
, 2, "%s", card
->gdev
->dev
.kobj
.name
);
4271 QETH_DBF_TEXT_(SETUP
, 2, "rc=%d",
4272 cmd
->data
.setadapterparms
.hdr
.return_code
);
4273 if (cmd
->data
.setadapterparms
.hdr
.return_code
!=
4274 SET_ACCESS_CTRL_RC_SUCCESS
)
4275 QETH_DBF_MESSAGE(3, "ERR:SET_ACCESS_CTRL(%s,%d)==%d\n",
4276 card
->gdev
->dev
.kobj
.name
,
4277 access_ctrl_req
->subcmd_code
,
4278 cmd
->data
.setadapterparms
.hdr
.return_code
);
4279 switch (cmd
->data
.setadapterparms
.hdr
.return_code
) {
4280 case SET_ACCESS_CTRL_RC_SUCCESS
:
4281 if (card
->options
.isolation
== ISOLATION_MODE_NONE
) {
4282 dev_info(&card
->gdev
->dev
,
4283 "QDIO data connection isolation is deactivated\n");
4285 dev_info(&card
->gdev
->dev
,
4286 "QDIO data connection isolation is activated\n");
4289 case SET_ACCESS_CTRL_RC_ALREADY_NOT_ISOLATED
:
4290 QETH_DBF_MESSAGE(2, "%s QDIO data connection isolation already "
4291 "deactivated\n", dev_name(&card
->gdev
->dev
));
4293 card
->options
.isolation
= card
->options
.prev_isolation
;
4295 case SET_ACCESS_CTRL_RC_ALREADY_ISOLATED
:
4296 QETH_DBF_MESSAGE(2, "%s QDIO data connection isolation already"
4297 " activated\n", dev_name(&card
->gdev
->dev
));
4299 card
->options
.isolation
= card
->options
.prev_isolation
;
4301 case SET_ACCESS_CTRL_RC_NOT_SUPPORTED
:
4302 dev_err(&card
->gdev
->dev
, "Adapter does not "
4303 "support QDIO data connection isolation\n");
4305 case SET_ACCESS_CTRL_RC_NONE_SHARED_ADAPTER
:
4306 dev_err(&card
->gdev
->dev
,
4307 "Adapter is dedicated. "
4308 "QDIO data connection isolation not supported\n");
4310 card
->options
.isolation
= card
->options
.prev_isolation
;
4312 case SET_ACCESS_CTRL_RC_ACTIVE_CHECKSUM_OFF
:
4313 dev_err(&card
->gdev
->dev
,
4314 "TSO does not permit QDIO data connection isolation\n");
4316 card
->options
.isolation
= card
->options
.prev_isolation
;
4318 case SET_ACCESS_CTRL_RC_REFLREL_UNSUPPORTED
:
4319 dev_err(&card
->gdev
->dev
, "The adjacent switch port does not "
4320 "support reflective relay mode\n");
4322 card
->options
.isolation
= card
->options
.prev_isolation
;
4324 case SET_ACCESS_CTRL_RC_REFLREL_FAILED
:
4325 dev_err(&card
->gdev
->dev
, "The reflective relay mode cannot be "
4326 "enabled at the adjacent switch port");
4328 card
->options
.isolation
= card
->options
.prev_isolation
;
4330 case SET_ACCESS_CTRL_RC_REFLREL_DEACT_FAILED
:
4331 dev_warn(&card
->gdev
->dev
, "Turning off reflective relay mode "
4332 "at the adjacent switch failed\n");
4335 /* this should never happen */
4337 card
->options
.isolation
= card
->options
.prev_isolation
;
4340 qeth_default_setadapterparms_cb(card
, reply
, (unsigned long) cmd
);
4344 static int qeth_setadpparms_set_access_ctrl(struct qeth_card
*card
,
4345 enum qeth_ipa_isolation_modes isolation
, int fallback
)
4348 struct qeth_cmd_buffer
*iob
;
4349 struct qeth_ipa_cmd
*cmd
;
4350 struct qeth_set_access_ctrl
*access_ctrl_req
;
4352 QETH_CARD_TEXT(card
, 4, "setacctl");
4354 QETH_DBF_TEXT_(SETUP
, 2, "setacctl");
4355 QETH_DBF_TEXT_(SETUP
, 2, "%s", card
->gdev
->dev
.kobj
.name
);
4357 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_SET_ACCESS_CONTROL
,
4358 sizeof(struct qeth_ipacmd_setadpparms_hdr
) +
4359 sizeof(struct qeth_set_access_ctrl
));
4362 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
4363 access_ctrl_req
= &cmd
->data
.setadapterparms
.data
.set_access_ctrl
;
4364 access_ctrl_req
->subcmd_code
= isolation
;
4366 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_setadpparms_set_access_ctrl_cb
,
4368 QETH_DBF_TEXT_(SETUP
, 2, "rc=%d", rc
);
4372 int qeth_set_access_ctrl_online(struct qeth_card
*card
, int fallback
)
4376 QETH_CARD_TEXT(card
, 4, "setactlo");
4378 if ((card
->info
.type
== QETH_CARD_TYPE_OSD
||
4379 card
->info
.type
== QETH_CARD_TYPE_OSX
) &&
4380 qeth_adp_supported(card
, IPA_SETADP_SET_ACCESS_CONTROL
)) {
4381 rc
= qeth_setadpparms_set_access_ctrl(card
,
4382 card
->options
.isolation
, fallback
);
4385 "IPA(SET_ACCESS_CTRL,%s,%d) sent failed\n",
4386 card
->gdev
->dev
.kobj
.name
,
4390 } else if (card
->options
.isolation
!= ISOLATION_MODE_NONE
) {
4391 card
->options
.isolation
= ISOLATION_MODE_NONE
;
4393 dev_err(&card
->gdev
->dev
, "Adapter does not "
4394 "support QDIO data connection isolation\n");
4399 EXPORT_SYMBOL_GPL(qeth_set_access_ctrl_online
);
4401 void qeth_tx_timeout(struct net_device
*dev
)
4403 struct qeth_card
*card
;
4405 card
= dev
->ml_priv
;
4406 QETH_CARD_TEXT(card
, 4, "txtimeo");
4407 card
->stats
.tx_errors
++;
4408 qeth_schedule_recovery(card
);
4410 EXPORT_SYMBOL_GPL(qeth_tx_timeout
);
4412 int qeth_mdio_read(struct net_device
*dev
, int phy_id
, int regnum
)
4414 struct qeth_card
*card
= dev
->ml_priv
;
4418 case MII_BMCR
: /* Basic mode control register */
4420 if ((card
->info
.link_type
!= QETH_LINK_TYPE_GBIT_ETH
) &&
4421 (card
->info
.link_type
!= QETH_LINK_TYPE_OSN
) &&
4422 (card
->info
.link_type
!= QETH_LINK_TYPE_10GBIT_ETH
))
4423 rc
|= BMCR_SPEED100
;
4425 case MII_BMSR
: /* Basic mode status register */
4426 rc
= BMSR_ERCAP
| BMSR_ANEGCOMPLETE
| BMSR_LSTATUS
|
4427 BMSR_10HALF
| BMSR_10FULL
| BMSR_100HALF
| BMSR_100FULL
|
4430 case MII_PHYSID1
: /* PHYS ID 1 */
4431 rc
= (dev
->dev_addr
[0] << 16) | (dev
->dev_addr
[1] << 8) |
4433 rc
= (rc
>> 5) & 0xFFFF;
4435 case MII_PHYSID2
: /* PHYS ID 2 */
4436 rc
= (dev
->dev_addr
[2] << 10) & 0xFFFF;
4438 case MII_ADVERTISE
: /* Advertisement control reg */
4441 case MII_LPA
: /* Link partner ability reg */
4442 rc
= LPA_10HALF
| LPA_10FULL
| LPA_100HALF
| LPA_100FULL
|
4443 LPA_100BASE4
| LPA_LPACK
;
4445 case MII_EXPANSION
: /* Expansion register */
4447 case MII_DCOUNTER
: /* disconnect counter */
4449 case MII_FCSCOUNTER
: /* false carrier counter */
4451 case MII_NWAYTEST
: /* N-way auto-neg test register */
4453 case MII_RERRCOUNTER
: /* rx error counter */
4454 rc
= card
->stats
.rx_errors
;
4456 case MII_SREVISION
: /* silicon revision */
4458 case MII_RESV1
: /* reserved 1 */
4460 case MII_LBRERROR
: /* loopback, rx, bypass error */
4462 case MII_PHYADDR
: /* physical address */
4464 case MII_RESV2
: /* reserved 2 */
4466 case MII_TPISTATUS
: /* TPI status for 10mbps */
4468 case MII_NCONFIG
: /* network interface config */
4475 EXPORT_SYMBOL_GPL(qeth_mdio_read
);
4477 static int qeth_send_ipa_snmp_cmd(struct qeth_card
*card
,
4478 struct qeth_cmd_buffer
*iob
, int len
,
4479 int (*reply_cb
)(struct qeth_card
*, struct qeth_reply
*,
4485 QETH_CARD_TEXT(card
, 4, "sendsnmp");
4487 memcpy(iob
->data
, IPA_PDU_HEADER
, IPA_PDU_HEADER_SIZE
);
4488 memcpy(QETH_IPA_CMD_DEST_ADDR(iob
->data
),
4489 &card
->token
.ulp_connection_r
, QETH_MPC_TOKEN_LENGTH
);
4490 /* adjust PDU length fields in IPA_PDU_HEADER */
4491 s1
= (u32
) IPA_PDU_HEADER_SIZE
+ len
;
4493 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob
->data
), &s1
, 2);
4494 memcpy(QETH_IPA_PDU_LEN_PDU1(iob
->data
), &s2
, 2);
4495 memcpy(QETH_IPA_PDU_LEN_PDU2(iob
->data
), &s2
, 2);
4496 memcpy(QETH_IPA_PDU_LEN_PDU3(iob
->data
), &s2
, 2);
4497 return qeth_send_control_data(card
, IPA_PDU_HEADER_SIZE
+ len
, iob
,
4498 reply_cb
, reply_param
);
4501 static int qeth_snmp_command_cb(struct qeth_card
*card
,
4502 struct qeth_reply
*reply
, unsigned long sdata
)
4504 struct qeth_ipa_cmd
*cmd
;
4505 struct qeth_arp_query_info
*qinfo
;
4506 struct qeth_snmp_cmd
*snmp
;
4507 unsigned char *data
;
4510 QETH_CARD_TEXT(card
, 3, "snpcmdcb");
4512 cmd
= (struct qeth_ipa_cmd
*) sdata
;
4513 data
= (unsigned char *)((char *)cmd
- reply
->offset
);
4514 qinfo
= (struct qeth_arp_query_info
*) reply
->param
;
4515 snmp
= &cmd
->data
.setadapterparms
.data
.snmp
;
4517 if (cmd
->hdr
.return_code
) {
4518 QETH_CARD_TEXT_(card
, 4, "scer1%x", cmd
->hdr
.return_code
);
4521 if (cmd
->data
.setadapterparms
.hdr
.return_code
) {
4522 cmd
->hdr
.return_code
=
4523 cmd
->data
.setadapterparms
.hdr
.return_code
;
4524 QETH_CARD_TEXT_(card
, 4, "scer2%x", cmd
->hdr
.return_code
);
4527 data_len
= *((__u16
*)QETH_IPA_PDU_LEN_PDU1(data
));
4528 if (cmd
->data
.setadapterparms
.hdr
.seq_no
== 1)
4529 data_len
-= (__u16
)((char *)&snmp
->data
- (char *)cmd
);
4531 data_len
-= (__u16
)((char *)&snmp
->request
- (char *)cmd
);
4533 /* check if there is enough room in userspace */
4534 if ((qinfo
->udata_len
- qinfo
->udata_offset
) < data_len
) {
4535 QETH_CARD_TEXT_(card
, 4, "scer3%i", -ENOMEM
);
4536 cmd
->hdr
.return_code
= IPA_RC_ENOMEM
;
4539 QETH_CARD_TEXT_(card
, 4, "snore%i",
4540 cmd
->data
.setadapterparms
.hdr
.used_total
);
4541 QETH_CARD_TEXT_(card
, 4, "sseqn%i",
4542 cmd
->data
.setadapterparms
.hdr
.seq_no
);
4543 /*copy entries to user buffer*/
4544 if (cmd
->data
.setadapterparms
.hdr
.seq_no
== 1) {
4545 memcpy(qinfo
->udata
+ qinfo
->udata_offset
,
4547 data_len
+ offsetof(struct qeth_snmp_cmd
, data
));
4548 qinfo
->udata_offset
+= offsetof(struct qeth_snmp_cmd
, data
);
4550 memcpy(qinfo
->udata
+ qinfo
->udata_offset
,
4551 (char *)&snmp
->request
, data_len
);
4553 qinfo
->udata_offset
+= data_len
;
4554 /* check if all replies received ... */
4555 QETH_CARD_TEXT_(card
, 4, "srtot%i",
4556 cmd
->data
.setadapterparms
.hdr
.used_total
);
4557 QETH_CARD_TEXT_(card
, 4, "srseq%i",
4558 cmd
->data
.setadapterparms
.hdr
.seq_no
);
4559 if (cmd
->data
.setadapterparms
.hdr
.seq_no
<
4560 cmd
->data
.setadapterparms
.hdr
.used_total
)
4565 int qeth_snmp_command(struct qeth_card
*card
, char __user
*udata
)
4567 struct qeth_cmd_buffer
*iob
;
4568 struct qeth_ipa_cmd
*cmd
;
4569 struct qeth_snmp_ureq
*ureq
;
4570 unsigned int req_len
;
4571 struct qeth_arp_query_info qinfo
= {0, };
4574 QETH_CARD_TEXT(card
, 3, "snmpcmd");
4576 if (card
->info
.guestlan
)
4579 if ((!qeth_adp_supported(card
, IPA_SETADP_SET_SNMP_CONTROL
)) &&
4580 (!card
->options
.layer2
)) {
4583 /* skip 4 bytes (data_len struct member) to get req_len */
4584 if (copy_from_user(&req_len
, udata
+ sizeof(int), sizeof(int)))
4586 if (req_len
> (QETH_BUFSIZE
- IPA_PDU_HEADER_SIZE
-
4587 sizeof(struct qeth_ipacmd_hdr
) -
4588 sizeof(struct qeth_ipacmd_setadpparms_hdr
)))
4590 ureq
= memdup_user(udata
, req_len
+ sizeof(struct qeth_snmp_ureq_hdr
));
4592 QETH_CARD_TEXT(card
, 2, "snmpnome");
4593 return PTR_ERR(ureq
);
4595 qinfo
.udata_len
= ureq
->hdr
.data_len
;
4596 qinfo
.udata
= kzalloc(qinfo
.udata_len
, GFP_KERNEL
);
4601 qinfo
.udata_offset
= sizeof(struct qeth_snmp_ureq_hdr
);
4603 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_SET_SNMP_CONTROL
,
4604 QETH_SNMP_SETADP_CMDLENGTH
+ req_len
);
4609 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
4610 memcpy(&cmd
->data
.setadapterparms
.data
.snmp
, &ureq
->cmd
, req_len
);
4611 rc
= qeth_send_ipa_snmp_cmd(card
, iob
, QETH_SETADP_BASE_LEN
+ req_len
,
4612 qeth_snmp_command_cb
, (void *)&qinfo
);
4614 QETH_DBF_MESSAGE(2, "SNMP command failed on %s: (0x%x)\n",
4615 QETH_CARD_IFNAME(card
), rc
);
4617 if (copy_to_user(udata
, qinfo
.udata
, qinfo
.udata_len
))
4625 EXPORT_SYMBOL_GPL(qeth_snmp_command
);
4627 static int qeth_setadpparms_query_oat_cb(struct qeth_card
*card
,
4628 struct qeth_reply
*reply
, unsigned long data
)
4630 struct qeth_ipa_cmd
*cmd
;
4631 struct qeth_qoat_priv
*priv
;
4635 QETH_CARD_TEXT(card
, 3, "qoatcb");
4637 cmd
= (struct qeth_ipa_cmd
*)data
;
4638 priv
= (struct qeth_qoat_priv
*)reply
->param
;
4639 resdatalen
= cmd
->data
.setadapterparms
.hdr
.cmdlength
;
4640 resdata
= (char *)data
+ 28;
4642 if (resdatalen
> (priv
->buffer_len
- priv
->response_len
)) {
4643 cmd
->hdr
.return_code
= IPA_RC_FFFF
;
4647 memcpy((priv
->buffer
+ priv
->response_len
), resdata
,
4649 priv
->response_len
+= resdatalen
;
4651 if (cmd
->data
.setadapterparms
.hdr
.seq_no
<
4652 cmd
->data
.setadapterparms
.hdr
.used_total
)
4657 int qeth_query_oat_command(struct qeth_card
*card
, char __user
*udata
)
4660 struct qeth_cmd_buffer
*iob
;
4661 struct qeth_ipa_cmd
*cmd
;
4662 struct qeth_query_oat
*oat_req
;
4663 struct qeth_query_oat_data oat_data
;
4664 struct qeth_qoat_priv priv
;
4667 QETH_CARD_TEXT(card
, 3, "qoatcmd");
4669 if (!qeth_adp_supported(card
, IPA_SETADP_QUERY_OAT
)) {
4674 if (copy_from_user(&oat_data
, udata
,
4675 sizeof(struct qeth_query_oat_data
))) {
4680 priv
.buffer_len
= oat_data
.buffer_len
;
4681 priv
.response_len
= 0;
4682 priv
.buffer
= kzalloc(oat_data
.buffer_len
, GFP_KERNEL
);
4688 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_QUERY_OAT
,
4689 sizeof(struct qeth_ipacmd_setadpparms_hdr
) +
4690 sizeof(struct qeth_query_oat
));
4695 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
4696 oat_req
= &cmd
->data
.setadapterparms
.data
.query_oat
;
4697 oat_req
->subcmd_code
= oat_data
.command
;
4699 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_setadpparms_query_oat_cb
,
4702 if (is_compat_task())
4703 tmp
= compat_ptr(oat_data
.ptr
);
4705 tmp
= (void __user
*)(unsigned long)oat_data
.ptr
;
4707 if (copy_to_user(tmp
, priv
.buffer
,
4708 priv
.response_len
)) {
4713 oat_data
.response_len
= priv
.response_len
;
4715 if (copy_to_user(udata
, &oat_data
,
4716 sizeof(struct qeth_query_oat_data
)))
4719 if (rc
== IPA_RC_FFFF
)
4727 EXPORT_SYMBOL_GPL(qeth_query_oat_command
);
4729 static int qeth_query_card_info_cb(struct qeth_card
*card
,
4730 struct qeth_reply
*reply
, unsigned long data
)
4732 struct qeth_ipa_cmd
*cmd
;
4733 struct qeth_query_card_info
*card_info
;
4734 struct carrier_info
*carrier_info
;
4736 QETH_CARD_TEXT(card
, 2, "qcrdincb");
4737 carrier_info
= (struct carrier_info
*)reply
->param
;
4738 cmd
= (struct qeth_ipa_cmd
*)data
;
4739 card_info
= &cmd
->data
.setadapterparms
.data
.card_info
;
4740 if (cmd
->data
.setadapterparms
.hdr
.return_code
== 0) {
4741 carrier_info
->card_type
= card_info
->card_type
;
4742 carrier_info
->port_mode
= card_info
->port_mode
;
4743 carrier_info
->port_speed
= card_info
->port_speed
;
4746 qeth_default_setadapterparms_cb(card
, reply
, (unsigned long) cmd
);
4750 static int qeth_query_card_info(struct qeth_card
*card
,
4751 struct carrier_info
*carrier_info
)
4753 struct qeth_cmd_buffer
*iob
;
4755 QETH_CARD_TEXT(card
, 2, "qcrdinfo");
4756 if (!qeth_adp_supported(card
, IPA_SETADP_QUERY_CARD_INFO
))
4758 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_QUERY_CARD_INFO
,
4759 sizeof(struct qeth_ipacmd_setadpparms_hdr
));
4762 return qeth_send_ipa_cmd(card
, iob
, qeth_query_card_info_cb
,
4763 (void *)carrier_info
);
4766 static inline int qeth_get_qdio_q_format(struct qeth_card
*card
)
4768 switch (card
->info
.type
) {
4769 case QETH_CARD_TYPE_IQD
:
4776 static void qeth_determine_capabilities(struct qeth_card
*card
)
4781 struct ccw_device
*ddev
;
4782 int ddev_offline
= 0;
4784 QETH_DBF_TEXT(SETUP
, 2, "detcapab");
4785 ddev
= CARD_DDEV(card
);
4786 if (!ddev
->online
) {
4788 rc
= ccw_device_set_online(ddev
);
4790 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
4795 rc
= qeth_read_conf_data(card
, (void **) &prcd
, &length
);
4797 QETH_DBF_MESSAGE(2, "%s qeth_read_conf_data returned %i\n",
4798 dev_name(&card
->gdev
->dev
), rc
);
4799 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
4802 qeth_configure_unitaddr(card
, prcd
);
4804 qeth_configure_blkt_default(card
, prcd
);
4807 rc
= qdio_get_ssqd_desc(ddev
, &card
->ssqd
);
4809 QETH_DBF_TEXT_(SETUP
, 2, "6err%d", rc
);
4811 QETH_DBF_TEXT_(SETUP
, 2, "qfmt%d", card
->ssqd
.qfmt
);
4812 QETH_DBF_TEXT_(SETUP
, 2, "%d", card
->ssqd
.qdioac1
);
4813 QETH_DBF_TEXT_(SETUP
, 2, "%d", card
->ssqd
.qdioac3
);
4814 QETH_DBF_TEXT_(SETUP
, 2, "icnt%d", card
->ssqd
.icnt
);
4815 if (!((card
->ssqd
.qfmt
!= QDIO_IQDIO_QFMT
) ||
4816 ((card
->ssqd
.qdioac1
& CHSC_AC1_INITIATE_INPUTQ
) == 0) ||
4817 ((card
->ssqd
.qdioac3
& CHSC_AC3_FORMAT2_CQ_AVAILABLE
) == 0))) {
4818 dev_info(&card
->gdev
->dev
,
4819 "Completion Queueing supported\n");
4821 card
->options
.cq
= QETH_CQ_NOTAVAILABLE
;
4826 if (ddev_offline
== 1)
4827 ccw_device_set_offline(ddev
);
4832 static inline void qeth_qdio_establish_cq(struct qeth_card
*card
,
4833 struct qdio_buffer
**in_sbal_ptrs
,
4834 void (**queue_start_poll
) (struct ccw_device
*, int, unsigned long)) {
4837 if (card
->options
.cq
== QETH_CQ_ENABLED
) {
4838 int offset
= QDIO_MAX_BUFFERS_PER_Q
*
4839 (card
->qdio
.no_in_queues
- 1);
4840 i
= QDIO_MAX_BUFFERS_PER_Q
* (card
->qdio
.no_in_queues
- 1);
4841 for (i
= 0; i
< QDIO_MAX_BUFFERS_PER_Q
; ++i
) {
4842 in_sbal_ptrs
[offset
+ i
] = (struct qdio_buffer
*)
4843 virt_to_phys(card
->qdio
.c_q
->bufs
[i
].buffer
);
4846 queue_start_poll
[card
->qdio
.no_in_queues
- 1] = NULL
;
4850 static int qeth_qdio_establish(struct qeth_card
*card
)
4852 struct qdio_initialize init_data
;
4853 char *qib_param_field
;
4854 struct qdio_buffer
**in_sbal_ptrs
;
4855 void (**queue_start_poll
) (struct ccw_device
*, int, unsigned long);
4856 struct qdio_buffer
**out_sbal_ptrs
;
4860 QETH_DBF_TEXT(SETUP
, 2, "qdioest");
4862 qib_param_field
= kzalloc(QDIO_MAX_BUFFERS_PER_Q
* sizeof(char),
4864 if (!qib_param_field
) {
4866 goto out_free_nothing
;
4869 qeth_create_qib_param_field(card
, qib_param_field
);
4870 qeth_create_qib_param_field_blkt(card
, qib_param_field
);
4872 in_sbal_ptrs
= kzalloc(card
->qdio
.no_in_queues
*
4873 QDIO_MAX_BUFFERS_PER_Q
* sizeof(void *),
4875 if (!in_sbal_ptrs
) {
4877 goto out_free_qib_param
;
4879 for (i
= 0; i
< QDIO_MAX_BUFFERS_PER_Q
; ++i
) {
4880 in_sbal_ptrs
[i
] = (struct qdio_buffer
*)
4881 virt_to_phys(card
->qdio
.in_q
->bufs
[i
].buffer
);
4884 queue_start_poll
= kzalloc(sizeof(void *) * card
->qdio
.no_in_queues
,
4886 if (!queue_start_poll
) {
4888 goto out_free_in_sbals
;
4890 for (i
= 0; i
< card
->qdio
.no_in_queues
; ++i
)
4891 queue_start_poll
[i
] = card
->discipline
->start_poll
;
4893 qeth_qdio_establish_cq(card
, in_sbal_ptrs
, queue_start_poll
);
4896 kzalloc(card
->qdio
.no_out_queues
* QDIO_MAX_BUFFERS_PER_Q
*
4897 sizeof(void *), GFP_KERNEL
);
4898 if (!out_sbal_ptrs
) {
4900 goto out_free_queue_start_poll
;
4902 for (i
= 0, k
= 0; i
< card
->qdio
.no_out_queues
; ++i
)
4903 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
, ++k
) {
4904 out_sbal_ptrs
[k
] = (struct qdio_buffer
*)virt_to_phys(
4905 card
->qdio
.out_qs
[i
]->bufs
[j
]->buffer
);
4908 memset(&init_data
, 0, sizeof(struct qdio_initialize
));
4909 init_data
.cdev
= CARD_DDEV(card
);
4910 init_data
.q_format
= qeth_get_qdio_q_format(card
);
4911 init_data
.qib_param_field_format
= 0;
4912 init_data
.qib_param_field
= qib_param_field
;
4913 init_data
.no_input_qs
= card
->qdio
.no_in_queues
;
4914 init_data
.no_output_qs
= card
->qdio
.no_out_queues
;
4915 init_data
.input_handler
= card
->discipline
->input_handler
;
4916 init_data
.output_handler
= card
->discipline
->output_handler
;
4917 init_data
.queue_start_poll_array
= queue_start_poll
;
4918 init_data
.int_parm
= (unsigned long) card
;
4919 init_data
.input_sbal_addr_array
= (void **) in_sbal_ptrs
;
4920 init_data
.output_sbal_addr_array
= (void **) out_sbal_ptrs
;
4921 init_data
.output_sbal_state_array
= card
->qdio
.out_bufstates
;
4922 init_data
.scan_threshold
=
4923 (card
->info
.type
== QETH_CARD_TYPE_IQD
) ? 1 : 32;
4925 if (atomic_cmpxchg(&card
->qdio
.state
, QETH_QDIO_ALLOCATED
,
4926 QETH_QDIO_ESTABLISHED
) == QETH_QDIO_ALLOCATED
) {
4927 rc
= qdio_allocate(&init_data
);
4929 atomic_set(&card
->qdio
.state
, QETH_QDIO_ALLOCATED
);
4932 rc
= qdio_establish(&init_data
);
4934 atomic_set(&card
->qdio
.state
, QETH_QDIO_ALLOCATED
);
4935 qdio_free(CARD_DDEV(card
));
4939 switch (card
->options
.cq
) {
4940 case QETH_CQ_ENABLED
:
4941 dev_info(&card
->gdev
->dev
, "Completion Queue support enabled");
4943 case QETH_CQ_DISABLED
:
4944 dev_info(&card
->gdev
->dev
, "Completion Queue support disabled");
4950 kfree(out_sbal_ptrs
);
4951 out_free_queue_start_poll
:
4952 kfree(queue_start_poll
);
4954 kfree(in_sbal_ptrs
);
4956 kfree(qib_param_field
);
4961 static void qeth_core_free_card(struct qeth_card
*card
)
4964 QETH_DBF_TEXT(SETUP
, 2, "freecrd");
4965 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
4966 qeth_clean_channel(&card
->read
);
4967 qeth_clean_channel(&card
->write
);
4969 free_netdev(card
->dev
);
4970 kfree(card
->ip_tbd_list
);
4971 qeth_free_qdio_buffers(card
);
4972 unregister_service_level(&card
->qeth_service_level
);
4976 void qeth_trace_features(struct qeth_card
*card
)
4978 QETH_CARD_TEXT(card
, 2, "features");
4979 QETH_CARD_HEX(card
, 2, &card
->options
.ipa4
, sizeof(card
->options
.ipa4
));
4980 QETH_CARD_HEX(card
, 2, &card
->options
.ipa6
, sizeof(card
->options
.ipa6
));
4981 QETH_CARD_HEX(card
, 2, &card
->options
.adp
, sizeof(card
->options
.adp
));
4982 QETH_CARD_HEX(card
, 2, &card
->info
.diagass_support
,
4983 sizeof(card
->info
.diagass_support
));
4985 EXPORT_SYMBOL_GPL(qeth_trace_features
);
4987 static struct ccw_device_id qeth_ids
[] = {
4988 {CCW_DEVICE_DEVTYPE(0x1731, 0x01, 0x1732, 0x01),
4989 .driver_info
= QETH_CARD_TYPE_OSD
},
4990 {CCW_DEVICE_DEVTYPE(0x1731, 0x05, 0x1732, 0x05),
4991 .driver_info
= QETH_CARD_TYPE_IQD
},
4992 {CCW_DEVICE_DEVTYPE(0x1731, 0x06, 0x1732, 0x06),
4993 .driver_info
= QETH_CARD_TYPE_OSN
},
4994 {CCW_DEVICE_DEVTYPE(0x1731, 0x02, 0x1732, 0x03),
4995 .driver_info
= QETH_CARD_TYPE_OSM
},
4996 {CCW_DEVICE_DEVTYPE(0x1731, 0x02, 0x1732, 0x02),
4997 .driver_info
= QETH_CARD_TYPE_OSX
},
5000 MODULE_DEVICE_TABLE(ccw
, qeth_ids
);
5002 static struct ccw_driver qeth_ccw_driver
= {
5004 .owner
= THIS_MODULE
,
5008 .probe
= ccwgroup_probe_ccwdev
,
5009 .remove
= ccwgroup_remove_ccwdev
,
5012 int qeth_core_hardsetup_card(struct qeth_card
*card
)
5017 QETH_DBF_TEXT(SETUP
, 2, "hrdsetup");
5018 atomic_set(&card
->force_alloc_skb
, 0);
5019 qeth_update_from_chp_desc(card
);
5022 QETH_DBF_MESSAGE(2, "%s Retrying to do IDX activates.\n",
5023 dev_name(&card
->gdev
->dev
));
5024 rc
= qeth_qdio_clear_card(card
, card
->info
.type
!= QETH_CARD_TYPE_IQD
);
5025 ccw_device_set_offline(CARD_DDEV(card
));
5026 ccw_device_set_offline(CARD_WDEV(card
));
5027 ccw_device_set_offline(CARD_RDEV(card
));
5028 qdio_free(CARD_DDEV(card
));
5029 rc
= ccw_device_set_online(CARD_RDEV(card
));
5032 rc
= ccw_device_set_online(CARD_WDEV(card
));
5035 rc
= ccw_device_set_online(CARD_DDEV(card
));
5039 if (rc
== -ERESTARTSYS
) {
5040 QETH_DBF_TEXT(SETUP
, 2, "break1");
5043 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
5049 qeth_determine_capabilities(card
);
5050 qeth_init_tokens(card
);
5051 qeth_init_func_level(card
);
5052 rc
= qeth_idx_activate_channel(&card
->read
, qeth_idx_read_cb
);
5053 if (rc
== -ERESTARTSYS
) {
5054 QETH_DBF_TEXT(SETUP
, 2, "break2");
5057 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
5063 rc
= qeth_idx_activate_channel(&card
->write
, qeth_idx_write_cb
);
5064 if (rc
== -ERESTARTSYS
) {
5065 QETH_DBF_TEXT(SETUP
, 2, "break3");
5068 QETH_DBF_TEXT_(SETUP
, 2, "4err%d", rc
);
5074 card
->read_or_write_problem
= 0;
5075 rc
= qeth_mpc_initialize(card
);
5077 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
5081 card
->options
.ipa4
.supported_funcs
= 0;
5082 card
->options
.ipa6
.supported_funcs
= 0;
5083 card
->options
.adp
.supported_funcs
= 0;
5084 card
->options
.sbp
.supported_funcs
= 0;
5085 card
->info
.diagass_support
= 0;
5086 rc
= qeth_query_ipassists(card
, QETH_PROT_IPV4
);
5089 if (qeth_is_supported(card
, IPA_SETADAPTERPARMS
)) {
5090 rc
= qeth_query_setadapterparms(card
);
5092 QETH_DBF_TEXT_(SETUP
, 2, "6err%d", rc
);
5096 if (qeth_adp_supported(card
, IPA_SETADP_SET_DIAG_ASSIST
)) {
5097 rc
= qeth_query_setdiagass(card
);
5099 QETH_DBF_TEXT_(SETUP
, 2, "7err%d", rc
);
5105 dev_warn(&card
->gdev
->dev
, "The qeth device driver failed to recover "
5106 "an error on the device\n");
5107 QETH_DBF_MESSAGE(2, "%s Initialization in hardsetup failed! rc=%d\n",
5108 dev_name(&card
->gdev
->dev
), rc
);
5111 EXPORT_SYMBOL_GPL(qeth_core_hardsetup_card
);
5113 static inline int qeth_create_skb_frag(struct qeth_qdio_buffer
*qethbuffer
,
5114 struct qdio_buffer_element
*element
,
5115 struct sk_buff
**pskb
, int offset
, int *pfrag
, int data_len
)
5117 struct page
*page
= virt_to_page(element
->addr
);
5118 if (*pskb
== NULL
) {
5119 if (qethbuffer
->rx_skb
) {
5120 /* only if qeth_card.options.cq == QETH_CQ_ENABLED */
5121 *pskb
= qethbuffer
->rx_skb
;
5122 qethbuffer
->rx_skb
= NULL
;
5124 *pskb
= dev_alloc_skb(QETH_RX_PULL_LEN
+ ETH_HLEN
);
5129 skb_reserve(*pskb
, ETH_HLEN
);
5130 if (data_len
<= QETH_RX_PULL_LEN
) {
5131 memcpy(skb_put(*pskb
, data_len
), element
->addr
+ offset
,
5135 memcpy(skb_put(*pskb
, QETH_RX_PULL_LEN
),
5136 element
->addr
+ offset
, QETH_RX_PULL_LEN
);
5137 skb_fill_page_desc(*pskb
, *pfrag
, page
,
5138 offset
+ QETH_RX_PULL_LEN
,
5139 data_len
- QETH_RX_PULL_LEN
);
5140 (*pskb
)->data_len
+= data_len
- QETH_RX_PULL_LEN
;
5141 (*pskb
)->len
+= data_len
- QETH_RX_PULL_LEN
;
5142 (*pskb
)->truesize
+= data_len
- QETH_RX_PULL_LEN
;
5147 skb_fill_page_desc(*pskb
, *pfrag
, page
, offset
, data_len
);
5148 (*pskb
)->data_len
+= data_len
;
5149 (*pskb
)->len
+= data_len
;
5150 (*pskb
)->truesize
+= data_len
;
5158 static inline int qeth_is_last_sbale(struct qdio_buffer_element
*sbale
)
5160 return (sbale
->eflags
& SBAL_EFLAGS_LAST_ENTRY
);
5163 struct sk_buff
*qeth_core_get_next_skb(struct qeth_card
*card
,
5164 struct qeth_qdio_buffer
*qethbuffer
,
5165 struct qdio_buffer_element
**__element
, int *__offset
,
5166 struct qeth_hdr
**hdr
)
5168 struct qdio_buffer_element
*element
= *__element
;
5169 struct qdio_buffer
*buffer
= qethbuffer
->buffer
;
5170 int offset
= *__offset
;
5171 struct sk_buff
*skb
= NULL
;
5179 /* qeth_hdr must not cross element boundaries */
5180 if (element
->length
< offset
+ sizeof(struct qeth_hdr
)) {
5181 if (qeth_is_last_sbale(element
))
5185 if (element
->length
< sizeof(struct qeth_hdr
))
5188 *hdr
= element
->addr
+ offset
;
5190 offset
+= sizeof(struct qeth_hdr
);
5191 switch ((*hdr
)->hdr
.l2
.id
) {
5192 case QETH_HEADER_TYPE_LAYER2
:
5193 skb_len
= (*hdr
)->hdr
.l2
.pkt_length
;
5195 case QETH_HEADER_TYPE_LAYER3
:
5196 skb_len
= (*hdr
)->hdr
.l3
.length
;
5197 headroom
= ETH_HLEN
;
5199 case QETH_HEADER_TYPE_OSN
:
5200 skb_len
= (*hdr
)->hdr
.osn
.pdu_length
;
5201 headroom
= sizeof(struct qeth_hdr
);
5210 if (((skb_len
>= card
->options
.rx_sg_cb
) &&
5211 (!(card
->info
.type
== QETH_CARD_TYPE_OSN
)) &&
5212 (!atomic_read(&card
->force_alloc_skb
))) ||
5213 (card
->options
.cq
== QETH_CQ_ENABLED
)) {
5216 skb
= dev_alloc_skb(skb_len
+ headroom
);
5220 skb_reserve(skb
, headroom
);
5223 data_ptr
= element
->addr
+ offset
;
5225 data_len
= min(skb_len
, (int)(element
->length
- offset
));
5228 if (qeth_create_skb_frag(qethbuffer
, element
,
5229 &skb
, offset
, &frag
, data_len
))
5232 memcpy(skb_put(skb
, data_len
), data_ptr
,
5236 skb_len
-= data_len
;
5238 if (qeth_is_last_sbale(element
)) {
5239 QETH_CARD_TEXT(card
, 4, "unexeob");
5240 QETH_CARD_HEX(card
, 2, buffer
, sizeof(void *));
5241 dev_kfree_skb_any(skb
);
5242 card
->stats
.rx_errors
++;
5247 data_ptr
= element
->addr
;
5252 *__element
= element
;
5254 if (use_rx_sg
&& card
->options
.performance_stats
) {
5255 card
->perf_stats
.sg_skbs_rx
++;
5256 card
->perf_stats
.sg_frags_rx
+= skb_shinfo(skb
)->nr_frags
;
5260 if (net_ratelimit()) {
5261 QETH_CARD_TEXT(card
, 2, "noskbmem");
5263 card
->stats
.rx_dropped
++;
5266 EXPORT_SYMBOL_GPL(qeth_core_get_next_skb
);
5268 static int qeth_setassparms_cb(struct qeth_card
*card
,
5269 struct qeth_reply
*reply
, unsigned long data
)
5271 struct qeth_ipa_cmd
*cmd
;
5273 QETH_CARD_TEXT(card
, 4, "defadpcb");
5275 cmd
= (struct qeth_ipa_cmd
*) data
;
5276 if (cmd
->hdr
.return_code
== 0) {
5277 cmd
->hdr
.return_code
= cmd
->data
.setassparms
.hdr
.return_code
;
5278 if (cmd
->hdr
.prot_version
== QETH_PROT_IPV4
)
5279 card
->options
.ipa4
.enabled_funcs
= cmd
->hdr
.ipa_enabled
;
5280 if (cmd
->hdr
.prot_version
== QETH_PROT_IPV6
)
5281 card
->options
.ipa6
.enabled_funcs
= cmd
->hdr
.ipa_enabled
;
5283 if (cmd
->data
.setassparms
.hdr
.assist_no
== IPA_INBOUND_CHECKSUM
&&
5284 cmd
->data
.setassparms
.hdr
.command_code
== IPA_CMD_ASS_START
) {
5285 card
->info
.csum_mask
= cmd
->data
.setassparms
.data
.flags_32bit
;
5286 QETH_CARD_TEXT_(card
, 3, "csum:%d", card
->info
.csum_mask
);
5288 if (cmd
->data
.setassparms
.hdr
.assist_no
== IPA_OUTBOUND_CHECKSUM
&&
5289 cmd
->data
.setassparms
.hdr
.command_code
== IPA_CMD_ASS_START
) {
5290 card
->info
.tx_csum_mask
=
5291 cmd
->data
.setassparms
.data
.flags_32bit
;
5292 QETH_CARD_TEXT_(card
, 3, "tcsu:%d", card
->info
.tx_csum_mask
);
5298 struct qeth_cmd_buffer
*qeth_get_setassparms_cmd(struct qeth_card
*card
,
5299 enum qeth_ipa_funcs ipa_func
,
5300 __u16 cmd_code
, __u16 len
,
5301 enum qeth_prot_versions prot
)
5303 struct qeth_cmd_buffer
*iob
;
5304 struct qeth_ipa_cmd
*cmd
;
5306 QETH_CARD_TEXT(card
, 4, "getasscm");
5307 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SETASSPARMS
, prot
);
5310 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
5311 cmd
->data
.setassparms
.hdr
.assist_no
= ipa_func
;
5312 cmd
->data
.setassparms
.hdr
.length
= 8 + len
;
5313 cmd
->data
.setassparms
.hdr
.command_code
= cmd_code
;
5314 cmd
->data
.setassparms
.hdr
.return_code
= 0;
5315 cmd
->data
.setassparms
.hdr
.seq_no
= 0;
5320 EXPORT_SYMBOL_GPL(qeth_get_setassparms_cmd
);
5322 int qeth_send_setassparms(struct qeth_card
*card
,
5323 struct qeth_cmd_buffer
*iob
, __u16 len
, long data
,
5324 int (*reply_cb
)(struct qeth_card
*,
5325 struct qeth_reply
*, unsigned long),
5329 struct qeth_ipa_cmd
*cmd
;
5331 QETH_CARD_TEXT(card
, 4, "sendassp");
5333 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
5334 if (len
<= sizeof(__u32
))
5335 cmd
->data
.setassparms
.data
.flags_32bit
= (__u32
) data
;
5336 else /* (len > sizeof(__u32)) */
5337 memcpy(&cmd
->data
.setassparms
.data
, (void *) data
, len
);
5339 rc
= qeth_send_ipa_cmd(card
, iob
, reply_cb
, reply_param
);
5342 EXPORT_SYMBOL_GPL(qeth_send_setassparms
);
5344 int qeth_send_simple_setassparms(struct qeth_card
*card
,
5345 enum qeth_ipa_funcs ipa_func
,
5346 __u16 cmd_code
, long data
)
5350 struct qeth_cmd_buffer
*iob
;
5352 QETH_CARD_TEXT(card
, 4, "simassp4");
5354 length
= sizeof(__u32
);
5355 iob
= qeth_get_setassparms_cmd(card
, ipa_func
, cmd_code
,
5356 length
, QETH_PROT_IPV4
);
5359 rc
= qeth_send_setassparms(card
, iob
, length
, data
,
5360 qeth_setassparms_cb
, NULL
);
5363 EXPORT_SYMBOL_GPL(qeth_send_simple_setassparms
);
5365 static void qeth_unregister_dbf_views(void)
5368 for (x
= 0; x
< QETH_DBF_INFOS
; x
++) {
5369 debug_unregister(qeth_dbf
[x
].id
);
5370 qeth_dbf
[x
].id
= NULL
;
5374 void qeth_dbf_longtext(debug_info_t
*id
, int level
, char *fmt
, ...)
5376 char dbf_txt_buf
[32];
5379 if (!debug_level_enabled(id
, level
))
5381 va_start(args
, fmt
);
5382 vsnprintf(dbf_txt_buf
, sizeof(dbf_txt_buf
), fmt
, args
);
5384 debug_text_event(id
, level
, dbf_txt_buf
);
5386 EXPORT_SYMBOL_GPL(qeth_dbf_longtext
);
5388 static int qeth_register_dbf_views(void)
5393 for (x
= 0; x
< QETH_DBF_INFOS
; x
++) {
5394 /* register the areas */
5395 qeth_dbf
[x
].id
= debug_register(qeth_dbf
[x
].name
,
5399 if (qeth_dbf
[x
].id
== NULL
) {
5400 qeth_unregister_dbf_views();
5404 /* register a view */
5405 ret
= debug_register_view(qeth_dbf
[x
].id
, qeth_dbf
[x
].view
);
5407 qeth_unregister_dbf_views();
5411 /* set a passing level */
5412 debug_set_level(qeth_dbf
[x
].id
, qeth_dbf
[x
].level
);
5418 int qeth_core_load_discipline(struct qeth_card
*card
,
5419 enum qeth_discipline_id discipline
)
5422 mutex_lock(&qeth_mod_mutex
);
5423 switch (discipline
) {
5424 case QETH_DISCIPLINE_LAYER3
:
5425 card
->discipline
= try_then_request_module(
5426 symbol_get(qeth_l3_discipline
), "qeth_l3");
5428 case QETH_DISCIPLINE_LAYER2
:
5429 card
->discipline
= try_then_request_module(
5430 symbol_get(qeth_l2_discipline
), "qeth_l2");
5433 if (!card
->discipline
) {
5434 dev_err(&card
->gdev
->dev
, "There is no kernel module to "
5435 "support discipline %d\n", discipline
);
5438 mutex_unlock(&qeth_mod_mutex
);
5442 void qeth_core_free_discipline(struct qeth_card
*card
)
5444 if (card
->options
.layer2
)
5445 symbol_put(qeth_l2_discipline
);
5447 symbol_put(qeth_l3_discipline
);
5448 card
->discipline
= NULL
;
5451 static const struct device_type qeth_generic_devtype
= {
5452 .name
= "qeth_generic",
5453 .groups
= qeth_generic_attr_groups
,
5455 static const struct device_type qeth_osn_devtype
= {
5457 .groups
= qeth_osn_attr_groups
,
5460 #define DBF_NAME_LEN 20
5462 struct qeth_dbf_entry
{
5463 char dbf_name
[DBF_NAME_LEN
];
5464 debug_info_t
*dbf_info
;
5465 struct list_head dbf_list
;
5468 static LIST_HEAD(qeth_dbf_list
);
5469 static DEFINE_MUTEX(qeth_dbf_list_mutex
);
5471 static debug_info_t
*qeth_get_dbf_entry(char *name
)
5473 struct qeth_dbf_entry
*entry
;
5474 debug_info_t
*rc
= NULL
;
5476 mutex_lock(&qeth_dbf_list_mutex
);
5477 list_for_each_entry(entry
, &qeth_dbf_list
, dbf_list
) {
5478 if (strcmp(entry
->dbf_name
, name
) == 0) {
5479 rc
= entry
->dbf_info
;
5483 mutex_unlock(&qeth_dbf_list_mutex
);
5487 static int qeth_add_dbf_entry(struct qeth_card
*card
, char *name
)
5489 struct qeth_dbf_entry
*new_entry
;
5491 card
->debug
= debug_register(name
, 2, 1, 8);
5493 QETH_DBF_TEXT_(SETUP
, 2, "%s", "qcdbf");
5496 if (debug_register_view(card
->debug
, &debug_hex_ascii_view
))
5498 new_entry
= kzalloc(sizeof(struct qeth_dbf_entry
), GFP_KERNEL
);
5501 strncpy(new_entry
->dbf_name
, name
, DBF_NAME_LEN
);
5502 new_entry
->dbf_info
= card
->debug
;
5503 mutex_lock(&qeth_dbf_list_mutex
);
5504 list_add(&new_entry
->dbf_list
, &qeth_dbf_list
);
5505 mutex_unlock(&qeth_dbf_list_mutex
);
5510 debug_unregister(card
->debug
);
5515 static void qeth_clear_dbf_list(void)
5517 struct qeth_dbf_entry
*entry
, *tmp
;
5519 mutex_lock(&qeth_dbf_list_mutex
);
5520 list_for_each_entry_safe(entry
, tmp
, &qeth_dbf_list
, dbf_list
) {
5521 list_del(&entry
->dbf_list
);
5522 debug_unregister(entry
->dbf_info
);
5525 mutex_unlock(&qeth_dbf_list_mutex
);
5528 static int qeth_core_probe_device(struct ccwgroup_device
*gdev
)
5530 struct qeth_card
*card
;
5533 unsigned long flags
;
5534 char dbf_name
[DBF_NAME_LEN
];
5536 QETH_DBF_TEXT(SETUP
, 2, "probedev");
5539 if (!get_device(dev
))
5542 QETH_DBF_TEXT_(SETUP
, 2, "%s", dev_name(&gdev
->dev
));
5544 card
= qeth_alloc_card();
5546 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", -ENOMEM
);
5551 snprintf(dbf_name
, sizeof(dbf_name
), "qeth_card_%s",
5552 dev_name(&gdev
->dev
));
5553 card
->debug
= qeth_get_dbf_entry(dbf_name
);
5555 rc
= qeth_add_dbf_entry(card
, dbf_name
);
5560 card
->read
.ccwdev
= gdev
->cdev
[0];
5561 card
->write
.ccwdev
= gdev
->cdev
[1];
5562 card
->data
.ccwdev
= gdev
->cdev
[2];
5563 dev_set_drvdata(&gdev
->dev
, card
);
5565 gdev
->cdev
[0]->handler
= qeth_irq
;
5566 gdev
->cdev
[1]->handler
= qeth_irq
;
5567 gdev
->cdev
[2]->handler
= qeth_irq
;
5569 rc
= qeth_determine_card_type(card
);
5571 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
5574 rc
= qeth_setup_card(card
);
5576 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
5580 if (card
->info
.type
== QETH_CARD_TYPE_OSN
)
5581 gdev
->dev
.type
= &qeth_osn_devtype
;
5583 gdev
->dev
.type
= &qeth_generic_devtype
;
5585 switch (card
->info
.type
) {
5586 case QETH_CARD_TYPE_OSN
:
5587 case QETH_CARD_TYPE_OSM
:
5588 rc
= qeth_core_load_discipline(card
, QETH_DISCIPLINE_LAYER2
);
5591 rc
= card
->discipline
->setup(card
->gdev
);
5594 case QETH_CARD_TYPE_OSD
:
5595 case QETH_CARD_TYPE_OSX
:
5600 write_lock_irqsave(&qeth_core_card_list
.rwlock
, flags
);
5601 list_add_tail(&card
->list
, &qeth_core_card_list
.list
);
5602 write_unlock_irqrestore(&qeth_core_card_list
.rwlock
, flags
);
5604 qeth_determine_capabilities(card
);
5608 qeth_core_free_discipline(card
);
5610 qeth_core_free_card(card
);
5616 static void qeth_core_remove_device(struct ccwgroup_device
*gdev
)
5618 unsigned long flags
;
5619 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5621 QETH_DBF_TEXT(SETUP
, 2, "removedv");
5623 if (card
->discipline
) {
5624 card
->discipline
->remove(gdev
);
5625 qeth_core_free_discipline(card
);
5628 write_lock_irqsave(&qeth_core_card_list
.rwlock
, flags
);
5629 list_del(&card
->list
);
5630 write_unlock_irqrestore(&qeth_core_card_list
.rwlock
, flags
);
5631 qeth_core_free_card(card
);
5632 dev_set_drvdata(&gdev
->dev
, NULL
);
5633 put_device(&gdev
->dev
);
5637 static int qeth_core_set_online(struct ccwgroup_device
*gdev
)
5639 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5643 if (!card
->discipline
) {
5644 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
5645 def_discipline
= QETH_DISCIPLINE_LAYER3
;
5647 def_discipline
= QETH_DISCIPLINE_LAYER2
;
5648 rc
= qeth_core_load_discipline(card
, def_discipline
);
5651 rc
= card
->discipline
->setup(card
->gdev
);
5655 rc
= card
->discipline
->set_online(gdev
);
5660 static int qeth_core_set_offline(struct ccwgroup_device
*gdev
)
5662 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5663 return card
->discipline
->set_offline(gdev
);
5666 static void qeth_core_shutdown(struct ccwgroup_device
*gdev
)
5668 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5669 if (card
->discipline
&& card
->discipline
->shutdown
)
5670 card
->discipline
->shutdown(gdev
);
5673 static int qeth_core_prepare(struct ccwgroup_device
*gdev
)
5675 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5676 if (card
->discipline
&& card
->discipline
->prepare
)
5677 return card
->discipline
->prepare(gdev
);
5681 static void qeth_core_complete(struct ccwgroup_device
*gdev
)
5683 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5684 if (card
->discipline
&& card
->discipline
->complete
)
5685 card
->discipline
->complete(gdev
);
5688 static int qeth_core_freeze(struct ccwgroup_device
*gdev
)
5690 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5691 if (card
->discipline
&& card
->discipline
->freeze
)
5692 return card
->discipline
->freeze(gdev
);
5696 static int qeth_core_thaw(struct ccwgroup_device
*gdev
)
5698 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5699 if (card
->discipline
&& card
->discipline
->thaw
)
5700 return card
->discipline
->thaw(gdev
);
5704 static int qeth_core_restore(struct ccwgroup_device
*gdev
)
5706 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5707 if (card
->discipline
&& card
->discipline
->restore
)
5708 return card
->discipline
->restore(gdev
);
5712 static struct ccwgroup_driver qeth_core_ccwgroup_driver
= {
5714 .owner
= THIS_MODULE
,
5717 .setup
= qeth_core_probe_device
,
5718 .remove
= qeth_core_remove_device
,
5719 .set_online
= qeth_core_set_online
,
5720 .set_offline
= qeth_core_set_offline
,
5721 .shutdown
= qeth_core_shutdown
,
5722 .prepare
= qeth_core_prepare
,
5723 .complete
= qeth_core_complete
,
5724 .freeze
= qeth_core_freeze
,
5725 .thaw
= qeth_core_thaw
,
5726 .restore
= qeth_core_restore
,
5729 static ssize_t
qeth_core_driver_group_store(struct device_driver
*ddrv
,
5730 const char *buf
, size_t count
)
5734 err
= ccwgroup_create_dev(qeth_core_root_dev
,
5735 &qeth_core_ccwgroup_driver
, 3, buf
);
5737 return err
? err
: count
;
5739 static DRIVER_ATTR(group
, 0200, NULL
, qeth_core_driver_group_store
);
5741 static struct attribute
*qeth_drv_attrs
[] = {
5742 &driver_attr_group
.attr
,
5745 static struct attribute_group qeth_drv_attr_group
= {
5746 .attrs
= qeth_drv_attrs
,
5748 static const struct attribute_group
*qeth_drv_attr_groups
[] = {
5749 &qeth_drv_attr_group
,
5754 const char str
[ETH_GSTRING_LEN
];
5755 } qeth_ethtool_stats_keys
[] = {
5760 {"tx skbs no packing"},
5761 {"tx buffers no packing"},
5762 {"tx skbs packing"},
5763 {"tx buffers packing"},
5766 /* 10 */{"rx sg skbs"},
5768 {"rx sg page allocs"},
5769 {"tx large kbytes"},
5771 {"tx pk state ch n->p"},
5772 {"tx pk state ch p->n"},
5773 {"tx pk watermark low"},
5774 {"tx pk watermark high"},
5775 {"queue 0 buffer usage"},
5776 /* 20 */{"queue 1 buffer usage"},
5777 {"queue 2 buffer usage"},
5778 {"queue 3 buffer usage"},
5781 {"rx do_QDIO time"},
5782 {"rx do_QDIO count"},
5783 {"tx handler time"},
5784 {"tx handler count"},
5786 /* 30 */{"tx count"},
5787 {"tx do_QDIO time"},
5788 {"tx do_QDIO count"},
5791 {"cq handler count"},
5795 int qeth_core_get_sset_count(struct net_device
*dev
, int stringset
)
5797 switch (stringset
) {
5799 return (sizeof(qeth_ethtool_stats_keys
) / ETH_GSTRING_LEN
);
5804 EXPORT_SYMBOL_GPL(qeth_core_get_sset_count
);
5806 void qeth_core_get_ethtool_stats(struct net_device
*dev
,
5807 struct ethtool_stats
*stats
, u64
*data
)
5809 struct qeth_card
*card
= dev
->ml_priv
;
5810 data
[0] = card
->stats
.rx_packets
-
5811 card
->perf_stats
.initial_rx_packets
;
5812 data
[1] = card
->perf_stats
.bufs_rec
;
5813 data
[2] = card
->stats
.tx_packets
-
5814 card
->perf_stats
.initial_tx_packets
;
5815 data
[3] = card
->perf_stats
.bufs_sent
;
5816 data
[4] = card
->stats
.tx_packets
- card
->perf_stats
.initial_tx_packets
5817 - card
->perf_stats
.skbs_sent_pack
;
5818 data
[5] = card
->perf_stats
.bufs_sent
- card
->perf_stats
.bufs_sent_pack
;
5819 data
[6] = card
->perf_stats
.skbs_sent_pack
;
5820 data
[7] = card
->perf_stats
.bufs_sent_pack
;
5821 data
[8] = card
->perf_stats
.sg_skbs_sent
;
5822 data
[9] = card
->perf_stats
.sg_frags_sent
;
5823 data
[10] = card
->perf_stats
.sg_skbs_rx
;
5824 data
[11] = card
->perf_stats
.sg_frags_rx
;
5825 data
[12] = card
->perf_stats
.sg_alloc_page_rx
;
5826 data
[13] = (card
->perf_stats
.large_send_bytes
>> 10);
5827 data
[14] = card
->perf_stats
.large_send_cnt
;
5828 data
[15] = card
->perf_stats
.sc_dp_p
;
5829 data
[16] = card
->perf_stats
.sc_p_dp
;
5830 data
[17] = QETH_LOW_WATERMARK_PACK
;
5831 data
[18] = QETH_HIGH_WATERMARK_PACK
;
5832 data
[19] = atomic_read(&card
->qdio
.out_qs
[0]->used_buffers
);
5833 data
[20] = (card
->qdio
.no_out_queues
> 1) ?
5834 atomic_read(&card
->qdio
.out_qs
[1]->used_buffers
) : 0;
5835 data
[21] = (card
->qdio
.no_out_queues
> 2) ?
5836 atomic_read(&card
->qdio
.out_qs
[2]->used_buffers
) : 0;
5837 data
[22] = (card
->qdio
.no_out_queues
> 3) ?
5838 atomic_read(&card
->qdio
.out_qs
[3]->used_buffers
) : 0;
5839 data
[23] = card
->perf_stats
.inbound_time
;
5840 data
[24] = card
->perf_stats
.inbound_cnt
;
5841 data
[25] = card
->perf_stats
.inbound_do_qdio_time
;
5842 data
[26] = card
->perf_stats
.inbound_do_qdio_cnt
;
5843 data
[27] = card
->perf_stats
.outbound_handler_time
;
5844 data
[28] = card
->perf_stats
.outbound_handler_cnt
;
5845 data
[29] = card
->perf_stats
.outbound_time
;
5846 data
[30] = card
->perf_stats
.outbound_cnt
;
5847 data
[31] = card
->perf_stats
.outbound_do_qdio_time
;
5848 data
[32] = card
->perf_stats
.outbound_do_qdio_cnt
;
5849 data
[33] = card
->perf_stats
.tx_csum
;
5850 data
[34] = card
->perf_stats
.tx_lin
;
5851 data
[35] = card
->perf_stats
.cq_cnt
;
5852 data
[36] = card
->perf_stats
.cq_time
;
5854 EXPORT_SYMBOL_GPL(qeth_core_get_ethtool_stats
);
5856 void qeth_core_get_strings(struct net_device
*dev
, u32 stringset
, u8
*data
)
5858 switch (stringset
) {
5860 memcpy(data
, &qeth_ethtool_stats_keys
,
5861 sizeof(qeth_ethtool_stats_keys
));
5868 EXPORT_SYMBOL_GPL(qeth_core_get_strings
);
5870 void qeth_core_get_drvinfo(struct net_device
*dev
,
5871 struct ethtool_drvinfo
*info
)
5873 struct qeth_card
*card
= dev
->ml_priv
;
5875 strlcpy(info
->driver
, card
->options
.layer2
? "qeth_l2" : "qeth_l3",
5876 sizeof(info
->driver
));
5877 strlcpy(info
->version
, "1.0", sizeof(info
->version
));
5878 strlcpy(info
->fw_version
, card
->info
.mcl_level
,
5879 sizeof(info
->fw_version
));
5880 snprintf(info
->bus_info
, sizeof(info
->bus_info
), "%s/%s/%s",
5881 CARD_RDEV_ID(card
), CARD_WDEV_ID(card
), CARD_DDEV_ID(card
));
5883 EXPORT_SYMBOL_GPL(qeth_core_get_drvinfo
);
5885 /* Helper function to fill 'advertizing' and 'supported' which are the same. */
5886 /* Autoneg and full-duplex are supported and advertized uncondionally. */
5887 /* Always advertize and support all speeds up to specified, and only one */
5888 /* specified port type. */
5889 static void qeth_set_ecmd_adv_sup(struct ethtool_cmd
*ecmd
,
5890 int maxspeed
, int porttype
)
5892 int port_sup
, port_adv
, spd_sup
, spd_adv
;
5896 port_sup
= SUPPORTED_TP
;
5897 port_adv
= ADVERTISED_TP
;
5900 port_sup
= SUPPORTED_FIBRE
;
5901 port_adv
= ADVERTISED_FIBRE
;
5904 port_sup
= SUPPORTED_TP
;
5905 port_adv
= ADVERTISED_TP
;
5909 /* "Fallthrough" case'es ordered from high to low result in setting */
5910 /* flags cumulatively, starting from the specified speed and down to */
5911 /* the lowest possible. */
5916 spd_sup
|= SUPPORTED_10000baseT_Full
;
5917 spd_adv
|= ADVERTISED_10000baseT_Full
;
5919 spd_sup
|= SUPPORTED_1000baseT_Half
| SUPPORTED_1000baseT_Full
;
5920 spd_adv
|= ADVERTISED_1000baseT_Half
|
5921 ADVERTISED_1000baseT_Full
;
5923 spd_sup
|= SUPPORTED_100baseT_Half
| SUPPORTED_100baseT_Full
;
5924 spd_adv
|= ADVERTISED_100baseT_Half
| ADVERTISED_100baseT_Full
;
5926 spd_sup
|= SUPPORTED_10baseT_Half
| SUPPORTED_10baseT_Full
;
5927 spd_adv
|= ADVERTISED_10baseT_Half
| ADVERTISED_10baseT_Full
;
5930 spd_sup
= SUPPORTED_10baseT_Half
| SUPPORTED_10baseT_Full
;
5931 spd_adv
= ADVERTISED_10baseT_Half
| ADVERTISED_10baseT_Full
;
5934 ecmd
->advertising
= ADVERTISED_Autoneg
| port_adv
| spd_adv
;
5935 ecmd
->supported
= SUPPORTED_Autoneg
| port_sup
| spd_sup
;
5938 int qeth_core_ethtool_get_settings(struct net_device
*netdev
,
5939 struct ethtool_cmd
*ecmd
)
5941 struct qeth_card
*card
= netdev
->ml_priv
;
5942 enum qeth_link_types link_type
;
5943 struct carrier_info carrier_info
;
5947 if ((card
->info
.type
== QETH_CARD_TYPE_IQD
) || (card
->info
.guestlan
))
5948 link_type
= QETH_LINK_TYPE_10GBIT_ETH
;
5950 link_type
= card
->info
.link_type
;
5952 ecmd
->transceiver
= XCVR_INTERNAL
;
5953 ecmd
->duplex
= DUPLEX_FULL
;
5954 ecmd
->autoneg
= AUTONEG_ENABLE
;
5956 switch (link_type
) {
5957 case QETH_LINK_TYPE_FAST_ETH
:
5958 case QETH_LINK_TYPE_LANE_ETH100
:
5959 qeth_set_ecmd_adv_sup(ecmd
, SPEED_100
, PORT_TP
);
5961 ecmd
->port
= PORT_TP
;
5964 case QETH_LINK_TYPE_GBIT_ETH
:
5965 case QETH_LINK_TYPE_LANE_ETH1000
:
5966 qeth_set_ecmd_adv_sup(ecmd
, SPEED_1000
, PORT_FIBRE
);
5968 ecmd
->port
= PORT_FIBRE
;
5971 case QETH_LINK_TYPE_10GBIT_ETH
:
5972 qeth_set_ecmd_adv_sup(ecmd
, SPEED_10000
, PORT_FIBRE
);
5973 speed
= SPEED_10000
;
5974 ecmd
->port
= PORT_FIBRE
;
5978 qeth_set_ecmd_adv_sup(ecmd
, SPEED_10
, PORT_TP
);
5980 ecmd
->port
= PORT_TP
;
5982 ethtool_cmd_speed_set(ecmd
, speed
);
5984 /* Check if we can obtain more accurate information. */
5985 /* If QUERY_CARD_INFO command is not supported or fails, */
5986 /* just return the heuristics that was filled above. */
5987 if (!qeth_card_hw_is_reachable(card
))
5989 rc
= qeth_query_card_info(card
, &carrier_info
);
5990 if (rc
== -EOPNOTSUPP
) /* for old hardware, return heuristic */
5992 if (rc
) /* report error from the hardware operation */
5994 /* on success, fill in the information got from the hardware */
5997 "card info: card_type=0x%02x, port_mode=0x%04x, port_speed=0x%08x\n",
5998 carrier_info
.card_type
,
5999 carrier_info
.port_mode
,
6000 carrier_info
.port_speed
);
6002 /* Update attributes for which we've obtained more authoritative */
6003 /* information, leave the rest the way they where filled above. */
6004 switch (carrier_info
.card_type
) {
6005 case CARD_INFO_TYPE_1G_COPPER_A
:
6006 case CARD_INFO_TYPE_1G_COPPER_B
:
6007 qeth_set_ecmd_adv_sup(ecmd
, SPEED_1000
, PORT_TP
);
6008 ecmd
->port
= PORT_TP
;
6010 case CARD_INFO_TYPE_1G_FIBRE_A
:
6011 case CARD_INFO_TYPE_1G_FIBRE_B
:
6012 qeth_set_ecmd_adv_sup(ecmd
, SPEED_1000
, PORT_FIBRE
);
6013 ecmd
->port
= PORT_FIBRE
;
6015 case CARD_INFO_TYPE_10G_FIBRE_A
:
6016 case CARD_INFO_TYPE_10G_FIBRE_B
:
6017 qeth_set_ecmd_adv_sup(ecmd
, SPEED_10000
, PORT_FIBRE
);
6018 ecmd
->port
= PORT_FIBRE
;
6022 switch (carrier_info
.port_mode
) {
6023 case CARD_INFO_PORTM_FULLDUPLEX
:
6024 ecmd
->duplex
= DUPLEX_FULL
;
6026 case CARD_INFO_PORTM_HALFDUPLEX
:
6027 ecmd
->duplex
= DUPLEX_HALF
;
6031 switch (carrier_info
.port_speed
) {
6032 case CARD_INFO_PORTS_10M
:
6035 case CARD_INFO_PORTS_100M
:
6038 case CARD_INFO_PORTS_1G
:
6041 case CARD_INFO_PORTS_10G
:
6042 speed
= SPEED_10000
;
6045 ethtool_cmd_speed_set(ecmd
, speed
);
6049 EXPORT_SYMBOL_GPL(qeth_core_ethtool_get_settings
);
6051 static int qeth_send_checksum_command(struct qeth_card
*card
)
6055 rc
= qeth_send_simple_setassparms(card
, IPA_INBOUND_CHECKSUM
,
6056 IPA_CMD_ASS_START
, 0);
6058 dev_warn(&card
->gdev
->dev
, "Starting HW checksumming for %s "
6059 "failed, using SW checksumming\n",
6060 QETH_CARD_IFNAME(card
));
6063 rc
= qeth_send_simple_setassparms(card
, IPA_INBOUND_CHECKSUM
,
6065 card
->info
.csum_mask
);
6067 dev_warn(&card
->gdev
->dev
, "Enabling HW checksumming for %s "
6068 "failed, using SW checksumming\n",
6069 QETH_CARD_IFNAME(card
));
6075 int qeth_set_rx_csum(struct qeth_card
*card
, int on
)
6080 rc
= qeth_send_checksum_command(card
);
6083 dev_info(&card
->gdev
->dev
,
6084 "HW Checksumming (inbound) enabled\n");
6086 rc
= qeth_send_simple_setassparms(card
,
6087 IPA_INBOUND_CHECKSUM
, IPA_CMD_ASS_STOP
, 0);
6093 EXPORT_SYMBOL_GPL(qeth_set_rx_csum
);
6095 int qeth_start_ipa_tx_checksum(struct qeth_card
*card
)
6099 if (!qeth_is_supported(card
, IPA_OUTBOUND_CHECKSUM
))
6101 rc
= qeth_send_simple_setassparms(card
, IPA_OUTBOUND_CHECKSUM
,
6102 IPA_CMD_ASS_START
, 0);
6105 rc
= qeth_send_simple_setassparms(card
, IPA_OUTBOUND_CHECKSUM
,
6107 card
->info
.tx_csum_mask
);
6111 dev_info(&card
->gdev
->dev
, "HW TX Checksumming enabled\n");
6114 dev_warn(&card
->gdev
->dev
, "Enabling HW TX checksumming for %s "
6115 "failed, using SW TX checksumming\n", QETH_CARD_IFNAME(card
));
6118 EXPORT_SYMBOL_GPL(qeth_start_ipa_tx_checksum
);
6120 static int __init
qeth_core_init(void)
6124 pr_info("loading core functions\n");
6125 INIT_LIST_HEAD(&qeth_core_card_list
.list
);
6126 INIT_LIST_HEAD(&qeth_dbf_list
);
6127 rwlock_init(&qeth_core_card_list
.rwlock
);
6128 mutex_init(&qeth_mod_mutex
);
6130 qeth_wq
= create_singlethread_workqueue("qeth_wq");
6132 rc
= qeth_register_dbf_views();
6135 qeth_core_root_dev
= root_device_register("qeth");
6136 rc
= PTR_ERR_OR_ZERO(qeth_core_root_dev
);
6139 qeth_core_header_cache
= kmem_cache_create("qeth_hdr",
6140 sizeof(struct qeth_hdr
) + ETH_HLEN
, 64, 0, NULL
);
6141 if (!qeth_core_header_cache
) {
6145 qeth_qdio_outbuf_cache
= kmem_cache_create("qeth_buf",
6146 sizeof(struct qeth_qdio_out_buffer
), 0, 0, NULL
);
6147 if (!qeth_qdio_outbuf_cache
) {
6151 rc
= ccw_driver_register(&qeth_ccw_driver
);
6154 qeth_core_ccwgroup_driver
.driver
.groups
= qeth_drv_attr_groups
;
6155 rc
= ccwgroup_driver_register(&qeth_core_ccwgroup_driver
);
6162 ccw_driver_unregister(&qeth_ccw_driver
);
6164 kmem_cache_destroy(qeth_qdio_outbuf_cache
);
6166 kmem_cache_destroy(qeth_core_header_cache
);
6168 root_device_unregister(qeth_core_root_dev
);
6170 qeth_unregister_dbf_views();
6172 pr_err("Initializing the qeth device driver failed\n");
6176 static void __exit
qeth_core_exit(void)
6178 qeth_clear_dbf_list();
6179 destroy_workqueue(qeth_wq
);
6180 ccwgroup_driver_unregister(&qeth_core_ccwgroup_driver
);
6181 ccw_driver_unregister(&qeth_ccw_driver
);
6182 kmem_cache_destroy(qeth_qdio_outbuf_cache
);
6183 kmem_cache_destroy(qeth_core_header_cache
);
6184 root_device_unregister(qeth_core_root_dev
);
6185 qeth_unregister_dbf_views();
6186 pr_info("core functions removed\n");
6189 module_init(qeth_core_init
);
6190 module_exit(qeth_core_exit
);
6191 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
6192 MODULE_DESCRIPTION("qeth core functions");
6193 MODULE_LICENSE("GPL");