2 * drivers/s390/net/qeth_core_main.c
4 * Copyright IBM Corp. 2007, 2009
5 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
6 * Frank Pavlic <fpavlic@de.ibm.com>,
7 * Thomas Spatzier <tspat@de.ibm.com>,
8 * Frank Blaschka <frank.blaschka@de.ibm.com>
11 #define KMSG_COMPONENT "qeth"
12 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/string.h>
17 #include <linux/errno.h>
18 #include <linux/kernel.h>
20 #include <linux/tcp.h>
21 #include <linux/mii.h>
22 #include <linux/kthread.h>
24 #include <asm/ebcdic.h>
27 #include "qeth_core.h"
29 struct qeth_dbf_info qeth_dbf
[QETH_DBF_INFOS
] = {
30 /* define dbf - Name, Pages, Areas, Maxlen, Level, View, Handle */
32 [QETH_DBF_SETUP
] = {"qeth_setup",
33 8, 1, 8, 5, &debug_hex_ascii_view
, NULL
},
34 [QETH_DBF_QERR
] = {"qeth_qerr",
35 2, 1, 8, 2, &debug_hex_ascii_view
, NULL
},
36 [QETH_DBF_TRACE
] = {"qeth_trace",
37 4, 1, 8, 3, &debug_hex_ascii_view
, NULL
},
38 [QETH_DBF_MSG
] = {"qeth_msg",
39 8, 1, 128, 3, &debug_sprintf_view
, NULL
},
40 [QETH_DBF_SENSE
] = {"qeth_sense",
41 2, 1, 64, 2, &debug_hex_ascii_view
, NULL
},
42 [QETH_DBF_MISC
] = {"qeth_misc",
43 2, 1, 256, 2, &debug_hex_ascii_view
, NULL
},
44 [QETH_DBF_CTRL
] = {"qeth_control",
45 8, 1, QETH_DBF_CTRL_LEN
, 5, &debug_hex_ascii_view
, NULL
},
47 EXPORT_SYMBOL_GPL(qeth_dbf
);
49 struct qeth_card_list_struct qeth_core_card_list
;
50 EXPORT_SYMBOL_GPL(qeth_core_card_list
);
51 struct kmem_cache
*qeth_core_header_cache
;
52 EXPORT_SYMBOL_GPL(qeth_core_header_cache
);
54 static struct device
*qeth_core_root_dev
;
55 static unsigned int known_devices
[][10] = QETH_MODELLIST_ARRAY
;
56 static struct lock_class_key qdio_out_skb_queue_key
;
58 static void qeth_send_control_data_cb(struct qeth_channel
*,
59 struct qeth_cmd_buffer
*);
60 static int qeth_issue_next_read(struct qeth_card
*);
61 static struct qeth_cmd_buffer
*qeth_get_buffer(struct qeth_channel
*);
62 static void qeth_setup_ccw(struct qeth_channel
*, unsigned char *, __u32
);
63 static void qeth_free_buffer_pool(struct qeth_card
*);
64 static int qeth_qdio_establish(struct qeth_card
*);
67 static inline void __qeth_fill_buffer_frag(struct sk_buff
*skb
,
68 struct qdio_buffer
*buffer
, int is_tso
,
69 int *next_element_to_fill
)
71 struct skb_frag_struct
*frag
;
74 int element
, cnt
, dlen
;
76 fragno
= skb_shinfo(skb
)->nr_frags
;
77 element
= *next_element_to_fill
;
81 buffer
->element
[element
].flags
=
82 SBAL_FLAGS_MIDDLE_FRAG
;
84 buffer
->element
[element
].flags
=
85 SBAL_FLAGS_FIRST_FRAG
;
86 dlen
= skb
->len
- skb
->data_len
;
88 buffer
->element
[element
].addr
= skb
->data
;
89 buffer
->element
[element
].length
= dlen
;
92 for (cnt
= 0; cnt
< fragno
; cnt
++) {
93 frag
= &skb_shinfo(skb
)->frags
[cnt
];
94 addr
= (page_to_pfn(frag
->page
) << PAGE_SHIFT
) +
96 buffer
->element
[element
].addr
= (char *)addr
;
97 buffer
->element
[element
].length
= frag
->size
;
98 if (cnt
< (fragno
- 1))
99 buffer
->element
[element
].flags
=
100 SBAL_FLAGS_MIDDLE_FRAG
;
102 buffer
->element
[element
].flags
=
103 SBAL_FLAGS_LAST_FRAG
;
106 *next_element_to_fill
= element
;
109 static inline const char *qeth_get_cardname(struct qeth_card
*card
)
111 if (card
->info
.guestlan
) {
112 switch (card
->info
.type
) {
113 case QETH_CARD_TYPE_OSAE
:
114 return " Guest LAN QDIO";
115 case QETH_CARD_TYPE_IQD
:
116 return " Guest LAN Hiper";
121 switch (card
->info
.type
) {
122 case QETH_CARD_TYPE_OSAE
:
123 return " OSD Express";
124 case QETH_CARD_TYPE_IQD
:
125 return " HiperSockets";
126 case QETH_CARD_TYPE_OSN
:
135 /* max length to be returned: 14 */
136 const char *qeth_get_cardname_short(struct qeth_card
*card
)
138 if (card
->info
.guestlan
) {
139 switch (card
->info
.type
) {
140 case QETH_CARD_TYPE_OSAE
:
141 return "GuestLAN QDIO";
142 case QETH_CARD_TYPE_IQD
:
143 return "GuestLAN Hiper";
148 switch (card
->info
.type
) {
149 case QETH_CARD_TYPE_OSAE
:
150 switch (card
->info
.link_type
) {
151 case QETH_LINK_TYPE_FAST_ETH
:
153 case QETH_LINK_TYPE_HSTR
:
155 case QETH_LINK_TYPE_GBIT_ETH
:
157 case QETH_LINK_TYPE_10GBIT_ETH
:
159 case QETH_LINK_TYPE_LANE_ETH100
:
160 return "OSD_FE_LANE";
161 case QETH_LINK_TYPE_LANE_TR
:
162 return "OSD_TR_LANE";
163 case QETH_LINK_TYPE_LANE_ETH1000
:
164 return "OSD_GbE_LANE";
165 case QETH_LINK_TYPE_LANE
:
166 return "OSD_ATM_LANE";
168 return "OSD_Express";
170 case QETH_CARD_TYPE_IQD
:
171 return "HiperSockets";
172 case QETH_CARD_TYPE_OSN
:
181 void qeth_set_allowed_threads(struct qeth_card
*card
, unsigned long threads
,
182 int clear_start_mask
)
186 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
187 card
->thread_allowed_mask
= threads
;
188 if (clear_start_mask
)
189 card
->thread_start_mask
&= threads
;
190 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
191 wake_up(&card
->wait_q
);
193 EXPORT_SYMBOL_GPL(qeth_set_allowed_threads
);
195 int qeth_threads_running(struct qeth_card
*card
, unsigned long threads
)
200 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
201 rc
= (card
->thread_running_mask
& threads
);
202 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
205 EXPORT_SYMBOL_GPL(qeth_threads_running
);
207 int qeth_wait_for_threads(struct qeth_card
*card
, unsigned long threads
)
209 return wait_event_interruptible(card
->wait_q
,
210 qeth_threads_running(card
, threads
) == 0);
212 EXPORT_SYMBOL_GPL(qeth_wait_for_threads
);
214 void qeth_clear_working_pool_list(struct qeth_card
*card
)
216 struct qeth_buffer_pool_entry
*pool_entry
, *tmp
;
218 QETH_DBF_TEXT(TRACE
, 5, "clwrklst");
219 list_for_each_entry_safe(pool_entry
, tmp
,
220 &card
->qdio
.in_buf_pool
.entry_list
, list
){
221 list_del(&pool_entry
->list
);
224 EXPORT_SYMBOL_GPL(qeth_clear_working_pool_list
);
226 static int qeth_alloc_buffer_pool(struct qeth_card
*card
)
228 struct qeth_buffer_pool_entry
*pool_entry
;
232 QETH_DBF_TEXT(TRACE
, 5, "alocpool");
233 for (i
= 0; i
< card
->qdio
.init_pool
.buf_count
; ++i
) {
234 pool_entry
= kmalloc(sizeof(*pool_entry
), GFP_KERNEL
);
236 qeth_free_buffer_pool(card
);
239 for (j
= 0; j
< QETH_MAX_BUFFER_ELEMENTS(card
); ++j
) {
240 ptr
= (void *) __get_free_page(GFP_KERNEL
);
243 free_page((unsigned long)
244 pool_entry
->elements
[--j
]);
246 qeth_free_buffer_pool(card
);
249 pool_entry
->elements
[j
] = ptr
;
251 list_add(&pool_entry
->init_list
,
252 &card
->qdio
.init_pool
.entry_list
);
257 int qeth_realloc_buffer_pool(struct qeth_card
*card
, int bufcnt
)
259 QETH_DBF_TEXT(TRACE
, 2, "realcbp");
261 if ((card
->state
!= CARD_STATE_DOWN
) &&
262 (card
->state
!= CARD_STATE_RECOVER
))
265 /* TODO: steel/add buffers from/to a running card's buffer pool (?) */
266 qeth_clear_working_pool_list(card
);
267 qeth_free_buffer_pool(card
);
268 card
->qdio
.in_buf_pool
.buf_count
= bufcnt
;
269 card
->qdio
.init_pool
.buf_count
= bufcnt
;
270 return qeth_alloc_buffer_pool(card
);
272 EXPORT_SYMBOL_GPL(qeth_realloc_buffer_pool
);
274 static int qeth_issue_next_read(struct qeth_card
*card
)
277 struct qeth_cmd_buffer
*iob
;
279 QETH_DBF_TEXT(TRACE
, 5, "issnxrd");
280 if (card
->read
.state
!= CH_STATE_UP
)
282 iob
= qeth_get_buffer(&card
->read
);
284 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
285 "failed to recover an error on the device\n");
286 QETH_DBF_MESSAGE(2, "%s issue_next_read failed: no iob "
287 "available\n", dev_name(&card
->gdev
->dev
));
290 qeth_setup_ccw(&card
->read
, iob
->data
, QETH_BUFSIZE
);
291 QETH_DBF_TEXT(TRACE
, 6, "noirqpnd");
292 rc
= ccw_device_start(card
->read
.ccwdev
, &card
->read
.ccw
,
295 QETH_DBF_MESSAGE(2, "%s error in starting next read ccw! "
296 "rc=%i\n", dev_name(&card
->gdev
->dev
), rc
);
297 atomic_set(&card
->read
.irq_pending
, 0);
298 qeth_schedule_recovery(card
);
299 wake_up(&card
->wait_q
);
304 static struct qeth_reply
*qeth_alloc_reply(struct qeth_card
*card
)
306 struct qeth_reply
*reply
;
308 reply
= kzalloc(sizeof(struct qeth_reply
), GFP_ATOMIC
);
310 atomic_set(&reply
->refcnt
, 1);
311 atomic_set(&reply
->received
, 0);
317 static void qeth_get_reply(struct qeth_reply
*reply
)
319 WARN_ON(atomic_read(&reply
->refcnt
) <= 0);
320 atomic_inc(&reply
->refcnt
);
323 static void qeth_put_reply(struct qeth_reply
*reply
)
325 WARN_ON(atomic_read(&reply
->refcnt
) <= 0);
326 if (atomic_dec_and_test(&reply
->refcnt
))
330 static void qeth_issue_ipa_msg(struct qeth_ipa_cmd
*cmd
, int rc
,
331 struct qeth_card
*card
)
334 int com
= cmd
->hdr
.command
;
335 ipa_name
= qeth_get_ipa_cmd_name(com
);
337 QETH_DBF_MESSAGE(2, "IPA: %s(x%X) for %s returned x%X \"%s\"\n",
338 ipa_name
, com
, QETH_CARD_IFNAME(card
),
339 rc
, qeth_get_ipa_msg(rc
));
341 QETH_DBF_MESSAGE(5, "IPA: %s(x%X) for %s succeeded\n",
342 ipa_name
, com
, QETH_CARD_IFNAME(card
));
345 static struct qeth_ipa_cmd
*qeth_check_ipa_data(struct qeth_card
*card
,
346 struct qeth_cmd_buffer
*iob
)
348 struct qeth_ipa_cmd
*cmd
= NULL
;
350 QETH_DBF_TEXT(TRACE
, 5, "chkipad");
351 if (IS_IPA(iob
->data
)) {
352 cmd
= (struct qeth_ipa_cmd
*) PDU_ENCAPSULATION(iob
->data
);
353 if (IS_IPA_REPLY(cmd
)) {
354 if (cmd
->hdr
.command
!= IPA_CMD_SETCCID
&&
355 cmd
->hdr
.command
!= IPA_CMD_DELCCID
&&
356 cmd
->hdr
.command
!= IPA_CMD_MODCCID
&&
357 cmd
->hdr
.command
!= IPA_CMD_SET_DIAG_ASS
)
358 qeth_issue_ipa_msg(cmd
,
359 cmd
->hdr
.return_code
, card
);
362 switch (cmd
->hdr
.command
) {
363 case IPA_CMD_STOPLAN
:
364 dev_warn(&card
->gdev
->dev
,
365 "The link for interface %s on CHPID"
367 QETH_CARD_IFNAME(card
),
369 card
->lan_online
= 0;
370 if (card
->dev
&& netif_carrier_ok(card
->dev
))
371 netif_carrier_off(card
->dev
);
373 case IPA_CMD_STARTLAN
:
374 dev_info(&card
->gdev
->dev
,
375 "The link for %s on CHPID 0x%X has"
377 QETH_CARD_IFNAME(card
),
379 netif_carrier_on(card
->dev
);
380 card
->lan_online
= 1;
381 qeth_schedule_recovery(card
);
383 case IPA_CMD_MODCCID
:
385 case IPA_CMD_REGISTER_LOCAL_ADDR
:
386 QETH_DBF_TEXT(TRACE
, 3, "irla");
388 case IPA_CMD_UNREGISTER_LOCAL_ADDR
:
389 QETH_DBF_TEXT(TRACE
, 3, "urla");
392 QETH_DBF_MESSAGE(2, "Received data is IPA "
393 "but not a reply!\n");
401 void qeth_clear_ipacmd_list(struct qeth_card
*card
)
403 struct qeth_reply
*reply
, *r
;
406 QETH_DBF_TEXT(TRACE
, 4, "clipalst");
408 spin_lock_irqsave(&card
->lock
, flags
);
409 list_for_each_entry_safe(reply
, r
, &card
->cmd_waiter_list
, list
) {
410 qeth_get_reply(reply
);
412 atomic_inc(&reply
->received
);
413 list_del_init(&reply
->list
);
414 wake_up(&reply
->wait_q
);
415 qeth_put_reply(reply
);
417 spin_unlock_irqrestore(&card
->lock
, flags
);
419 EXPORT_SYMBOL_GPL(qeth_clear_ipacmd_list
);
421 static int qeth_check_idx_response(unsigned char *buffer
)
426 QETH_DBF_HEX(CTRL
, 2, buffer
, QETH_DBF_CTRL_LEN
);
427 if ((buffer
[2] & 0xc0) == 0xc0) {
428 QETH_DBF_MESSAGE(2, "received an IDX TERMINATE "
429 "with cause code 0x%02x%s\n",
431 ((buffer
[4] == 0x22) ?
432 " -- try another portname" : ""));
433 QETH_DBF_TEXT(TRACE
, 2, "ckidxres");
434 QETH_DBF_TEXT(TRACE
, 2, " idxterm");
435 QETH_DBF_TEXT_(TRACE
, 2, " rc%d", -EIO
);
441 static void qeth_setup_ccw(struct qeth_channel
*channel
, unsigned char *iob
,
444 struct qeth_card
*card
;
446 QETH_DBF_TEXT(TRACE
, 4, "setupccw");
447 card
= CARD_FROM_CDEV(channel
->ccwdev
);
448 if (channel
== &card
->read
)
449 memcpy(&channel
->ccw
, READ_CCW
, sizeof(struct ccw1
));
451 memcpy(&channel
->ccw
, WRITE_CCW
, sizeof(struct ccw1
));
452 channel
->ccw
.count
= len
;
453 channel
->ccw
.cda
= (__u32
) __pa(iob
);
456 static struct qeth_cmd_buffer
*__qeth_get_buffer(struct qeth_channel
*channel
)
460 QETH_DBF_TEXT(TRACE
, 6, "getbuff");
461 index
= channel
->io_buf_no
;
463 if (channel
->iob
[index
].state
== BUF_STATE_FREE
) {
464 channel
->iob
[index
].state
= BUF_STATE_LOCKED
;
465 channel
->io_buf_no
= (channel
->io_buf_no
+ 1) %
467 memset(channel
->iob
[index
].data
, 0, QETH_BUFSIZE
);
468 return channel
->iob
+ index
;
470 index
= (index
+ 1) % QETH_CMD_BUFFER_NO
;
471 } while (index
!= channel
->io_buf_no
);
476 void qeth_release_buffer(struct qeth_channel
*channel
,
477 struct qeth_cmd_buffer
*iob
)
481 QETH_DBF_TEXT(TRACE
, 6, "relbuff");
482 spin_lock_irqsave(&channel
->iob_lock
, flags
);
483 memset(iob
->data
, 0, QETH_BUFSIZE
);
484 iob
->state
= BUF_STATE_FREE
;
485 iob
->callback
= qeth_send_control_data_cb
;
487 spin_unlock_irqrestore(&channel
->iob_lock
, flags
);
489 EXPORT_SYMBOL_GPL(qeth_release_buffer
);
491 static struct qeth_cmd_buffer
*qeth_get_buffer(struct qeth_channel
*channel
)
493 struct qeth_cmd_buffer
*buffer
= NULL
;
496 spin_lock_irqsave(&channel
->iob_lock
, flags
);
497 buffer
= __qeth_get_buffer(channel
);
498 spin_unlock_irqrestore(&channel
->iob_lock
, flags
);
502 struct qeth_cmd_buffer
*qeth_wait_for_buffer(struct qeth_channel
*channel
)
504 struct qeth_cmd_buffer
*buffer
;
505 wait_event(channel
->wait_q
,
506 ((buffer
= qeth_get_buffer(channel
)) != NULL
));
509 EXPORT_SYMBOL_GPL(qeth_wait_for_buffer
);
511 void qeth_clear_cmd_buffers(struct qeth_channel
*channel
)
515 for (cnt
= 0; cnt
< QETH_CMD_BUFFER_NO
; cnt
++)
516 qeth_release_buffer(channel
, &channel
->iob
[cnt
]);
518 channel
->io_buf_no
= 0;
520 EXPORT_SYMBOL_GPL(qeth_clear_cmd_buffers
);
522 static void qeth_send_control_data_cb(struct qeth_channel
*channel
,
523 struct qeth_cmd_buffer
*iob
)
525 struct qeth_card
*card
;
526 struct qeth_reply
*reply
, *r
;
527 struct qeth_ipa_cmd
*cmd
;
531 QETH_DBF_TEXT(TRACE
, 4, "sndctlcb");
533 card
= CARD_FROM_CDEV(channel
->ccwdev
);
534 if (qeth_check_idx_response(iob
->data
)) {
535 qeth_clear_ipacmd_list(card
);
536 if (((iob
->data
[2] & 0xc0) == 0xc0) && iob
->data
[4] == 0xf6)
537 dev_err(&card
->gdev
->dev
,
538 "The qeth device is not configured "
539 "for the OSI layer required by z/VM\n");
541 qeth_schedule_recovery(card
);
545 cmd
= qeth_check_ipa_data(card
, iob
);
546 if ((cmd
== NULL
) && (card
->state
!= CARD_STATE_DOWN
))
548 /*in case of OSN : check if cmd is set */
549 if (card
->info
.type
== QETH_CARD_TYPE_OSN
&&
551 cmd
->hdr
.command
!= IPA_CMD_STARTLAN
&&
552 card
->osn_info
.assist_cb
!= NULL
) {
553 card
->osn_info
.assist_cb(card
->dev
, cmd
);
557 spin_lock_irqsave(&card
->lock
, flags
);
558 list_for_each_entry_safe(reply
, r
, &card
->cmd_waiter_list
, list
) {
559 if ((reply
->seqno
== QETH_IDX_COMMAND_SEQNO
) ||
560 ((cmd
) && (reply
->seqno
== cmd
->hdr
.seqno
))) {
561 qeth_get_reply(reply
);
562 list_del_init(&reply
->list
);
563 spin_unlock_irqrestore(&card
->lock
, flags
);
565 if (reply
->callback
!= NULL
) {
567 reply
->offset
= (__u16
)((char *)cmd
-
569 keep_reply
= reply
->callback(card
,
573 keep_reply
= reply
->callback(card
,
578 reply
->rc
= (u16
) cmd
->hdr
.return_code
;
582 spin_lock_irqsave(&card
->lock
, flags
);
583 list_add_tail(&reply
->list
,
584 &card
->cmd_waiter_list
);
585 spin_unlock_irqrestore(&card
->lock
, flags
);
587 atomic_inc(&reply
->received
);
588 wake_up(&reply
->wait_q
);
590 qeth_put_reply(reply
);
594 spin_unlock_irqrestore(&card
->lock
, flags
);
596 memcpy(&card
->seqno
.pdu_hdr_ack
,
597 QETH_PDU_HEADER_SEQ_NO(iob
->data
),
599 qeth_release_buffer(channel
, iob
);
602 static int qeth_setup_channel(struct qeth_channel
*channel
)
606 QETH_DBF_TEXT(SETUP
, 2, "setupch");
607 for (cnt
= 0; cnt
< QETH_CMD_BUFFER_NO
; cnt
++) {
608 channel
->iob
[cnt
].data
= (char *)
609 kmalloc(QETH_BUFSIZE
, GFP_DMA
|GFP_KERNEL
);
610 if (channel
->iob
[cnt
].data
== NULL
)
612 channel
->iob
[cnt
].state
= BUF_STATE_FREE
;
613 channel
->iob
[cnt
].channel
= channel
;
614 channel
->iob
[cnt
].callback
= qeth_send_control_data_cb
;
615 channel
->iob
[cnt
].rc
= 0;
617 if (cnt
< QETH_CMD_BUFFER_NO
) {
619 kfree(channel
->iob
[cnt
].data
);
623 channel
->io_buf_no
= 0;
624 atomic_set(&channel
->irq_pending
, 0);
625 spin_lock_init(&channel
->iob_lock
);
627 init_waitqueue_head(&channel
->wait_q
);
631 static int qeth_set_thread_start_bit(struct qeth_card
*card
,
632 unsigned long thread
)
636 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
637 if (!(card
->thread_allowed_mask
& thread
) ||
638 (card
->thread_start_mask
& thread
)) {
639 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
642 card
->thread_start_mask
|= thread
;
643 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
647 void qeth_clear_thread_start_bit(struct qeth_card
*card
, unsigned long thread
)
651 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
652 card
->thread_start_mask
&= ~thread
;
653 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
654 wake_up(&card
->wait_q
);
656 EXPORT_SYMBOL_GPL(qeth_clear_thread_start_bit
);
658 void qeth_clear_thread_running_bit(struct qeth_card
*card
, unsigned long thread
)
662 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
663 card
->thread_running_mask
&= ~thread
;
664 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
665 wake_up(&card
->wait_q
);
667 EXPORT_SYMBOL_GPL(qeth_clear_thread_running_bit
);
669 static int __qeth_do_run_thread(struct qeth_card
*card
, unsigned long thread
)
674 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
675 if (card
->thread_start_mask
& thread
) {
676 if ((card
->thread_allowed_mask
& thread
) &&
677 !(card
->thread_running_mask
& thread
)) {
679 card
->thread_start_mask
&= ~thread
;
680 card
->thread_running_mask
|= thread
;
684 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
688 int qeth_do_run_thread(struct qeth_card
*card
, unsigned long thread
)
692 wait_event(card
->wait_q
,
693 (rc
= __qeth_do_run_thread(card
, thread
)) >= 0);
696 EXPORT_SYMBOL_GPL(qeth_do_run_thread
);
698 void qeth_schedule_recovery(struct qeth_card
*card
)
700 QETH_DBF_TEXT(TRACE
, 2, "startrec");
701 if (qeth_set_thread_start_bit(card
, QETH_RECOVER_THREAD
) == 0)
702 schedule_work(&card
->kernel_thread_starter
);
704 EXPORT_SYMBOL_GPL(qeth_schedule_recovery
);
706 static int qeth_get_problem(struct ccw_device
*cdev
, struct irb
*irb
)
711 sense
= (char *) irb
->ecw
;
712 cstat
= irb
->scsw
.cmd
.cstat
;
713 dstat
= irb
->scsw
.cmd
.dstat
;
715 if (cstat
& (SCHN_STAT_CHN_CTRL_CHK
| SCHN_STAT_INTF_CTRL_CHK
|
716 SCHN_STAT_CHN_DATA_CHK
| SCHN_STAT_CHAIN_CHECK
|
717 SCHN_STAT_PROT_CHECK
| SCHN_STAT_PROG_CHECK
)) {
718 QETH_DBF_TEXT(TRACE
, 2, "CGENCHK");
719 dev_warn(&cdev
->dev
, "The qeth device driver "
720 "failed to recover an error on the device\n");
721 QETH_DBF_MESSAGE(2, "%s check on device dstat=x%x, cstat=x%x ",
722 dev_name(&cdev
->dev
), dstat
, cstat
);
723 print_hex_dump(KERN_WARNING
, "qeth: irb ", DUMP_PREFIX_OFFSET
,
728 if (dstat
& DEV_STAT_UNIT_CHECK
) {
729 if (sense
[SENSE_RESETTING_EVENT_BYTE
] &
730 SENSE_RESETTING_EVENT_FLAG
) {
731 QETH_DBF_TEXT(TRACE
, 2, "REVIND");
734 if (sense
[SENSE_COMMAND_REJECT_BYTE
] &
735 SENSE_COMMAND_REJECT_FLAG
) {
736 QETH_DBF_TEXT(TRACE
, 2, "CMDREJi");
739 if ((sense
[2] == 0xaf) && (sense
[3] == 0xfe)) {
740 QETH_DBF_TEXT(TRACE
, 2, "AFFE");
743 if ((!sense
[0]) && (!sense
[1]) && (!sense
[2]) && (!sense
[3])) {
744 QETH_DBF_TEXT(TRACE
, 2, "ZEROSEN");
747 QETH_DBF_TEXT(TRACE
, 2, "DGENCHK");
753 static long __qeth_check_irb_error(struct ccw_device
*cdev
,
754 unsigned long intparm
, struct irb
*irb
)
759 switch (PTR_ERR(irb
)) {
761 QETH_DBF_MESSAGE(2, "%s i/o-error on device\n",
762 dev_name(&cdev
->dev
));
763 QETH_DBF_TEXT(TRACE
, 2, "ckirberr");
764 QETH_DBF_TEXT_(TRACE
, 2, " rc%d", -EIO
);
767 dev_warn(&cdev
->dev
, "A hardware operation timed out"
769 QETH_DBF_TEXT(TRACE
, 2, "ckirberr");
770 QETH_DBF_TEXT_(TRACE
, 2, " rc%d", -ETIMEDOUT
);
771 if (intparm
== QETH_RCD_PARM
) {
772 struct qeth_card
*card
= CARD_FROM_CDEV(cdev
);
774 if (card
&& (card
->data
.ccwdev
== cdev
)) {
775 card
->data
.state
= CH_STATE_DOWN
;
776 wake_up(&card
->wait_q
);
781 QETH_DBF_MESSAGE(2, "%s unknown error %ld on device\n",
782 dev_name(&cdev
->dev
), PTR_ERR(irb
));
783 QETH_DBF_TEXT(TRACE
, 2, "ckirberr");
784 QETH_DBF_TEXT(TRACE
, 2, " rc???");
789 static void qeth_irq(struct ccw_device
*cdev
, unsigned long intparm
,
794 struct qeth_cmd_buffer
*buffer
;
795 struct qeth_channel
*channel
;
796 struct qeth_card
*card
;
797 struct qeth_cmd_buffer
*iob
;
800 QETH_DBF_TEXT(TRACE
, 5, "irq");
802 if (__qeth_check_irb_error(cdev
, intparm
, irb
))
804 cstat
= irb
->scsw
.cmd
.cstat
;
805 dstat
= irb
->scsw
.cmd
.dstat
;
807 card
= CARD_FROM_CDEV(cdev
);
811 if (card
->read
.ccwdev
== cdev
) {
812 channel
= &card
->read
;
813 QETH_DBF_TEXT(TRACE
, 5, "read");
814 } else if (card
->write
.ccwdev
== cdev
) {
815 channel
= &card
->write
;
816 QETH_DBF_TEXT(TRACE
, 5, "write");
818 channel
= &card
->data
;
819 QETH_DBF_TEXT(TRACE
, 5, "data");
821 atomic_set(&channel
->irq_pending
, 0);
823 if (irb
->scsw
.cmd
.fctl
& (SCSW_FCTL_CLEAR_FUNC
))
824 channel
->state
= CH_STATE_STOPPED
;
826 if (irb
->scsw
.cmd
.fctl
& (SCSW_FCTL_HALT_FUNC
))
827 channel
->state
= CH_STATE_HALTED
;
829 /*let's wake up immediately on data channel*/
830 if ((channel
== &card
->data
) && (intparm
!= 0) &&
831 (intparm
!= QETH_RCD_PARM
))
834 if (intparm
== QETH_CLEAR_CHANNEL_PARM
) {
835 QETH_DBF_TEXT(TRACE
, 6, "clrchpar");
836 /* we don't have to handle this further */
839 if (intparm
== QETH_HALT_CHANNEL_PARM
) {
840 QETH_DBF_TEXT(TRACE
, 6, "hltchpar");
841 /* we don't have to handle this further */
844 if ((dstat
& DEV_STAT_UNIT_EXCEP
) ||
845 (dstat
& DEV_STAT_UNIT_CHECK
) ||
847 if (irb
->esw
.esw0
.erw
.cons
) {
848 dev_warn(&channel
->ccwdev
->dev
,
849 "The qeth device driver failed to recover "
850 "an error on the device\n");
851 QETH_DBF_MESSAGE(2, "%s sense data available. cstat "
853 dev_name(&channel
->ccwdev
->dev
), cstat
, dstat
);
854 print_hex_dump(KERN_WARNING
, "qeth: irb ",
855 DUMP_PREFIX_OFFSET
, 16, 1, irb
, 32, 1);
856 print_hex_dump(KERN_WARNING
, "qeth: sense data ",
857 DUMP_PREFIX_OFFSET
, 16, 1, irb
->ecw
, 32, 1);
859 if (intparm
== QETH_RCD_PARM
) {
860 channel
->state
= CH_STATE_DOWN
;
863 rc
= qeth_get_problem(cdev
, irb
);
865 qeth_clear_ipacmd_list(card
);
866 qeth_schedule_recovery(card
);
871 if (intparm
== QETH_RCD_PARM
) {
872 channel
->state
= CH_STATE_RCD_DONE
;
876 buffer
= (struct qeth_cmd_buffer
*) __va((addr_t
)intparm
);
877 buffer
->state
= BUF_STATE_PROCESSED
;
879 if (channel
== &card
->data
)
881 if (channel
== &card
->read
&&
882 channel
->state
== CH_STATE_UP
)
883 qeth_issue_next_read(card
);
886 index
= channel
->buf_no
;
887 while (iob
[index
].state
== BUF_STATE_PROCESSED
) {
888 if (iob
[index
].callback
!= NULL
)
889 iob
[index
].callback(channel
, iob
+ index
);
891 index
= (index
+ 1) % QETH_CMD_BUFFER_NO
;
893 channel
->buf_no
= index
;
895 wake_up(&card
->wait_q
);
899 static void __qeth_clear_output_buffer(struct qeth_qdio_out_q
*queue
,
900 struct qeth_qdio_out_buffer
*buf
, unsigned int qeth_skip_skb
)
905 /* is PCI flag set on buffer? */
906 if (buf
->buffer
->element
[0].flags
& 0x40)
907 atomic_dec(&queue
->set_pci_flags_count
);
909 if (!qeth_skip_skb
) {
910 skb
= skb_dequeue(&buf
->skb_list
);
912 atomic_dec(&skb
->users
);
913 dev_kfree_skb_any(skb
);
914 skb
= skb_dequeue(&buf
->skb_list
);
917 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(queue
->card
); ++i
) {
918 if (buf
->buffer
->element
[i
].addr
&& buf
->is_header
[i
])
919 kmem_cache_free(qeth_core_header_cache
,
920 buf
->buffer
->element
[i
].addr
);
921 buf
->is_header
[i
] = 0;
922 buf
->buffer
->element
[i
].length
= 0;
923 buf
->buffer
->element
[i
].addr
= NULL
;
924 buf
->buffer
->element
[i
].flags
= 0;
926 buf
->buffer
->element
[15].flags
= 0;
927 buf
->next_element_to_fill
= 0;
928 atomic_set(&buf
->state
, QETH_QDIO_BUF_EMPTY
);
931 static void qeth_clear_output_buffer(struct qeth_qdio_out_q
*queue
,
932 struct qeth_qdio_out_buffer
*buf
)
934 __qeth_clear_output_buffer(queue
, buf
, 0);
937 void qeth_clear_qdio_buffers(struct qeth_card
*card
)
941 QETH_DBF_TEXT(TRACE
, 2, "clearqdbf");
942 /* clear outbound buffers to free skbs */
943 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
)
944 if (card
->qdio
.out_qs
[i
]) {
945 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
)
946 qeth_clear_output_buffer(card
->qdio
.out_qs
[i
],
947 &card
->qdio
.out_qs
[i
]->bufs
[j
]);
950 EXPORT_SYMBOL_GPL(qeth_clear_qdio_buffers
);
952 static void qeth_free_buffer_pool(struct qeth_card
*card
)
954 struct qeth_buffer_pool_entry
*pool_entry
, *tmp
;
956 QETH_DBF_TEXT(TRACE
, 5, "freepool");
957 list_for_each_entry_safe(pool_entry
, tmp
,
958 &card
->qdio
.init_pool
.entry_list
, init_list
){
959 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(card
); ++i
)
960 free_page((unsigned long)pool_entry
->elements
[i
]);
961 list_del(&pool_entry
->init_list
);
966 static void qeth_free_qdio_buffers(struct qeth_card
*card
)
970 QETH_DBF_TEXT(TRACE
, 2, "freeqdbf");
971 if (atomic_xchg(&card
->qdio
.state
, QETH_QDIO_UNINITIALIZED
) ==
972 QETH_QDIO_UNINITIALIZED
)
974 kfree(card
->qdio
.in_q
);
975 card
->qdio
.in_q
= NULL
;
976 /* inbound buffer pool */
977 qeth_free_buffer_pool(card
);
978 /* free outbound qdio_qs */
979 if (card
->qdio
.out_qs
) {
980 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
981 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
)
982 qeth_clear_output_buffer(card
->qdio
.out_qs
[i
],
983 &card
->qdio
.out_qs
[i
]->bufs
[j
]);
984 kfree(card
->qdio
.out_qs
[i
]);
986 kfree(card
->qdio
.out_qs
);
987 card
->qdio
.out_qs
= NULL
;
991 static void qeth_clean_channel(struct qeth_channel
*channel
)
995 QETH_DBF_TEXT(SETUP
, 2, "freech");
996 for (cnt
= 0; cnt
< QETH_CMD_BUFFER_NO
; cnt
++)
997 kfree(channel
->iob
[cnt
].data
);
1000 static int qeth_is_1920_device(struct qeth_card
*card
)
1002 int single_queue
= 0;
1003 struct ccw_device
*ccwdev
;
1004 struct channelPath_dsc
{
1015 QETH_DBF_TEXT(SETUP
, 2, "chk_1920");
1017 ccwdev
= card
->data
.ccwdev
;
1018 chp_dsc
= (struct channelPath_dsc
*)ccw_device_get_chp_desc(ccwdev
, 0);
1019 if (chp_dsc
!= NULL
) {
1020 /* CHPP field bit 6 == 1 -> single queue */
1021 single_queue
= ((chp_dsc
->chpp
& 0x02) == 0x02);
1024 QETH_DBF_TEXT_(SETUP
, 2, "rc:%x", single_queue
);
1025 return single_queue
;
1028 static void qeth_init_qdio_info(struct qeth_card
*card
)
1030 QETH_DBF_TEXT(SETUP
, 4, "intqdinf");
1031 atomic_set(&card
->qdio
.state
, QETH_QDIO_UNINITIALIZED
);
1033 card
->qdio
.in_buf_size
= QETH_IN_BUF_SIZE_DEFAULT
;
1034 card
->qdio
.init_pool
.buf_count
= QETH_IN_BUF_COUNT_DEFAULT
;
1035 card
->qdio
.in_buf_pool
.buf_count
= card
->qdio
.init_pool
.buf_count
;
1036 INIT_LIST_HEAD(&card
->qdio
.in_buf_pool
.entry_list
);
1037 INIT_LIST_HEAD(&card
->qdio
.init_pool
.entry_list
);
1040 static void qeth_set_intial_options(struct qeth_card
*card
)
1042 card
->options
.route4
.type
= NO_ROUTER
;
1043 card
->options
.route6
.type
= NO_ROUTER
;
1044 card
->options
.checksum_type
= QETH_CHECKSUM_DEFAULT
;
1045 card
->options
.broadcast_mode
= QETH_TR_BROADCAST_ALLRINGS
;
1046 card
->options
.macaddr_mode
= QETH_TR_MACADDR_NONCANONICAL
;
1047 card
->options
.fake_broadcast
= 0;
1048 card
->options
.add_hhlen
= DEFAULT_ADD_HHLEN
;
1049 card
->options
.performance_stats
= 0;
1050 card
->options
.rx_sg_cb
= QETH_RX_SG_CB
;
1051 card
->options
.isolation
= ISOLATION_MODE_NONE
;
1054 static int qeth_do_start_thread(struct qeth_card
*card
, unsigned long thread
)
1056 unsigned long flags
;
1059 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
1060 QETH_DBF_TEXT_(TRACE
, 4, " %02x%02x%02x",
1061 (u8
) card
->thread_start_mask
,
1062 (u8
) card
->thread_allowed_mask
,
1063 (u8
) card
->thread_running_mask
);
1064 rc
= (card
->thread_start_mask
& thread
);
1065 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
1069 static void qeth_start_kernel_thread(struct work_struct
*work
)
1071 struct qeth_card
*card
= container_of(work
, struct qeth_card
,
1072 kernel_thread_starter
);
1073 QETH_DBF_TEXT(TRACE
, 2, "strthrd");
1075 if (card
->read
.state
!= CH_STATE_UP
&&
1076 card
->write
.state
!= CH_STATE_UP
)
1078 if (qeth_do_start_thread(card
, QETH_RECOVER_THREAD
))
1079 kthread_run(card
->discipline
.recover
, (void *) card
,
1083 static int qeth_setup_card(struct qeth_card
*card
)
1086 QETH_DBF_TEXT(SETUP
, 2, "setupcrd");
1087 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
1089 card
->read
.state
= CH_STATE_DOWN
;
1090 card
->write
.state
= CH_STATE_DOWN
;
1091 card
->data
.state
= CH_STATE_DOWN
;
1092 card
->state
= CARD_STATE_DOWN
;
1093 card
->lan_online
= 0;
1094 card
->use_hard_stop
= 0;
1096 spin_lock_init(&card
->vlanlock
);
1097 spin_lock_init(&card
->mclock
);
1098 card
->vlangrp
= NULL
;
1099 spin_lock_init(&card
->lock
);
1100 spin_lock_init(&card
->ip_lock
);
1101 spin_lock_init(&card
->thread_mask_lock
);
1102 card
->thread_start_mask
= 0;
1103 card
->thread_allowed_mask
= 0;
1104 card
->thread_running_mask
= 0;
1105 INIT_WORK(&card
->kernel_thread_starter
, qeth_start_kernel_thread
);
1106 INIT_LIST_HEAD(&card
->ip_list
);
1107 INIT_LIST_HEAD(card
->ip_tbd_list
);
1108 INIT_LIST_HEAD(&card
->cmd_waiter_list
);
1109 init_waitqueue_head(&card
->wait_q
);
1110 /* intial options */
1111 qeth_set_intial_options(card
);
1112 /* IP address takeover */
1113 INIT_LIST_HEAD(&card
->ipato
.entries
);
1114 card
->ipato
.enabled
= 0;
1115 card
->ipato
.invert4
= 0;
1116 card
->ipato
.invert6
= 0;
1117 /* init QDIO stuff */
1118 qeth_init_qdio_info(card
);
1122 static void qeth_core_sl_print(struct seq_file
*m
, struct service_level
*slr
)
1124 struct qeth_card
*card
= container_of(slr
, struct qeth_card
,
1125 qeth_service_level
);
1126 if (card
->info
.mcl_level
[0])
1127 seq_printf(m
, "qeth: %s firmware level %s\n",
1128 CARD_BUS_ID(card
), card
->info
.mcl_level
);
1131 static struct qeth_card
*qeth_alloc_card(void)
1133 struct qeth_card
*card
;
1135 QETH_DBF_TEXT(SETUP
, 2, "alloccrd");
1136 card
= kzalloc(sizeof(struct qeth_card
), GFP_DMA
|GFP_KERNEL
);
1139 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
1140 card
->ip_tbd_list
= kmalloc(sizeof(struct list_head
), GFP_KERNEL
);
1141 if (!card
->ip_tbd_list
) {
1142 QETH_DBF_TEXT(SETUP
, 0, "iptbdnom");
1145 if (qeth_setup_channel(&card
->read
))
1147 if (qeth_setup_channel(&card
->write
))
1149 card
->options
.layer2
= -1;
1150 card
->qeth_service_level
.seq_print
= qeth_core_sl_print
;
1151 register_service_level(&card
->qeth_service_level
);
1155 qeth_clean_channel(&card
->read
);
1157 kfree(card
->ip_tbd_list
);
1164 static int qeth_determine_card_type(struct qeth_card
*card
)
1168 QETH_DBF_TEXT(SETUP
, 2, "detcdtyp");
1170 card
->qdio
.do_prio_queueing
= QETH_PRIOQ_DEFAULT
;
1171 card
->qdio
.default_out_queue
= QETH_DEFAULT_QUEUE
;
1172 while (known_devices
[i
][4]) {
1173 if ((CARD_RDEV(card
)->id
.dev_type
== known_devices
[i
][2]) &&
1174 (CARD_RDEV(card
)->id
.dev_model
== known_devices
[i
][3])) {
1175 card
->info
.type
= known_devices
[i
][4];
1176 card
->qdio
.no_out_queues
= known_devices
[i
][8];
1177 card
->info
.is_multicast_different
= known_devices
[i
][9];
1178 if (qeth_is_1920_device(card
)) {
1179 dev_info(&card
->gdev
->dev
,
1180 "Priority Queueing not supported\n");
1181 card
->qdio
.no_out_queues
= 1;
1182 card
->qdio
.default_out_queue
= 0;
1188 card
->info
.type
= QETH_CARD_TYPE_UNKNOWN
;
1189 dev_err(&card
->gdev
->dev
, "The adapter hardware is of an "
1194 static int qeth_clear_channel(struct qeth_channel
*channel
)
1196 unsigned long flags
;
1197 struct qeth_card
*card
;
1200 QETH_DBF_TEXT(TRACE
, 3, "clearch");
1201 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1202 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1203 rc
= ccw_device_clear(channel
->ccwdev
, QETH_CLEAR_CHANNEL_PARM
);
1204 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1208 rc
= wait_event_interruptible_timeout(card
->wait_q
,
1209 channel
->state
== CH_STATE_STOPPED
, QETH_TIMEOUT
);
1210 if (rc
== -ERESTARTSYS
)
1212 if (channel
->state
!= CH_STATE_STOPPED
)
1214 channel
->state
= CH_STATE_DOWN
;
1218 static int qeth_halt_channel(struct qeth_channel
*channel
)
1220 unsigned long flags
;
1221 struct qeth_card
*card
;
1224 QETH_DBF_TEXT(TRACE
, 3, "haltch");
1225 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1226 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1227 rc
= ccw_device_halt(channel
->ccwdev
, QETH_HALT_CHANNEL_PARM
);
1228 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1232 rc
= wait_event_interruptible_timeout(card
->wait_q
,
1233 channel
->state
== CH_STATE_HALTED
, QETH_TIMEOUT
);
1234 if (rc
== -ERESTARTSYS
)
1236 if (channel
->state
!= CH_STATE_HALTED
)
1241 static int qeth_halt_channels(struct qeth_card
*card
)
1243 int rc1
= 0, rc2
= 0, rc3
= 0;
1245 QETH_DBF_TEXT(TRACE
, 3, "haltchs");
1246 rc1
= qeth_halt_channel(&card
->read
);
1247 rc2
= qeth_halt_channel(&card
->write
);
1248 rc3
= qeth_halt_channel(&card
->data
);
1256 static int qeth_clear_channels(struct qeth_card
*card
)
1258 int rc1
= 0, rc2
= 0, rc3
= 0;
1260 QETH_DBF_TEXT(TRACE
, 3, "clearchs");
1261 rc1
= qeth_clear_channel(&card
->read
);
1262 rc2
= qeth_clear_channel(&card
->write
);
1263 rc3
= qeth_clear_channel(&card
->data
);
1271 static int qeth_clear_halt_card(struct qeth_card
*card
, int halt
)
1275 QETH_DBF_TEXT(TRACE
, 3, "clhacrd");
1276 QETH_DBF_HEX(TRACE
, 3, &card
, sizeof(void *));
1279 rc
= qeth_halt_channels(card
);
1282 return qeth_clear_channels(card
);
1285 int qeth_qdio_clear_card(struct qeth_card
*card
, int use_halt
)
1289 QETH_DBF_TEXT(TRACE
, 3, "qdioclr");
1290 switch (atomic_cmpxchg(&card
->qdio
.state
, QETH_QDIO_ESTABLISHED
,
1291 QETH_QDIO_CLEANING
)) {
1292 case QETH_QDIO_ESTABLISHED
:
1293 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
1294 rc
= qdio_cleanup(CARD_DDEV(card
),
1295 QDIO_FLAG_CLEANUP_USING_HALT
);
1297 rc
= qdio_cleanup(CARD_DDEV(card
),
1298 QDIO_FLAG_CLEANUP_USING_CLEAR
);
1300 QETH_DBF_TEXT_(TRACE
, 3, "1err%d", rc
);
1301 atomic_set(&card
->qdio
.state
, QETH_QDIO_ALLOCATED
);
1303 case QETH_QDIO_CLEANING
:
1308 rc
= qeth_clear_halt_card(card
, use_halt
);
1310 QETH_DBF_TEXT_(TRACE
, 3, "2err%d", rc
);
1311 card
->state
= CARD_STATE_DOWN
;
1314 EXPORT_SYMBOL_GPL(qeth_qdio_clear_card
);
1316 static int qeth_read_conf_data(struct qeth_card
*card
, void **buffer
,
1322 struct qeth_channel
*channel
= &card
->data
;
1323 unsigned long flags
;
1326 * scan for RCD command in extended SenseID data
1328 ciw
= ccw_device_get_ciw(channel
->ccwdev
, CIW_TYPE_RCD
);
1329 if (!ciw
|| ciw
->cmd
== 0)
1331 rcd_buf
= kzalloc(ciw
->count
, GFP_KERNEL
| GFP_DMA
);
1335 channel
->ccw
.cmd_code
= ciw
->cmd
;
1336 channel
->ccw
.cda
= (__u32
) __pa(rcd_buf
);
1337 channel
->ccw
.count
= ciw
->count
;
1338 channel
->ccw
.flags
= CCW_FLAG_SLI
;
1339 channel
->state
= CH_STATE_RCD
;
1340 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1341 ret
= ccw_device_start_timeout(channel
->ccwdev
, &channel
->ccw
,
1342 QETH_RCD_PARM
, LPM_ANYPATH
, 0,
1344 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1346 wait_event(card
->wait_q
,
1347 (channel
->state
== CH_STATE_RCD_DONE
||
1348 channel
->state
== CH_STATE_DOWN
));
1349 if (channel
->state
== CH_STATE_DOWN
)
1352 channel
->state
= CH_STATE_DOWN
;
1358 *length
= ciw
->count
;
1364 static void qeth_configure_unitaddr(struct qeth_card
*card
, char *prcd
)
1366 QETH_DBF_TEXT(SETUP
, 2, "cfgunit");
1367 card
->info
.chpid
= prcd
[30];
1368 card
->info
.unit_addr2
= prcd
[31];
1369 card
->info
.cula
= prcd
[63];
1370 card
->info
.guestlan
= ((prcd
[0x10] == _ascebc
['V']) &&
1371 (prcd
[0x11] == _ascebc
['M']));
1374 static void qeth_configure_blkt_default(struct qeth_card
*card
, char *prcd
)
1376 QETH_DBF_TEXT(SETUP
, 2, "cfgblkt");
1378 if (prcd
[74] == 0xF0 && prcd
[75] == 0xF0 && prcd
[76] == 0xF5) {
1379 card
->info
.blkt
.time_total
= 250;
1380 card
->info
.blkt
.inter_packet
= 5;
1381 card
->info
.blkt
.inter_packet_jumbo
= 15;
1383 card
->info
.blkt
.time_total
= 0;
1384 card
->info
.blkt
.inter_packet
= 0;
1385 card
->info
.blkt
.inter_packet_jumbo
= 0;
1389 static void qeth_init_tokens(struct qeth_card
*card
)
1391 card
->token
.issuer_rm_w
= 0x00010103UL
;
1392 card
->token
.cm_filter_w
= 0x00010108UL
;
1393 card
->token
.cm_connection_w
= 0x0001010aUL
;
1394 card
->token
.ulp_filter_w
= 0x0001010bUL
;
1395 card
->token
.ulp_connection_w
= 0x0001010dUL
;
1398 static void qeth_init_func_level(struct qeth_card
*card
)
1400 if (card
->ipato
.enabled
) {
1401 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
1402 card
->info
.func_level
=
1403 QETH_IDX_FUNC_LEVEL_IQD_ENA_IPAT
;
1405 card
->info
.func_level
=
1406 QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT
;
1408 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
1409 /*FIXME:why do we have same values for dis and ena for
1411 card
->info
.func_level
=
1412 QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT
;
1414 card
->info
.func_level
=
1415 QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT
;
1419 static int qeth_idx_activate_get_answer(struct qeth_channel
*channel
,
1420 void (*idx_reply_cb
)(struct qeth_channel
*,
1421 struct qeth_cmd_buffer
*))
1423 struct qeth_cmd_buffer
*iob
;
1424 unsigned long flags
;
1426 struct qeth_card
*card
;
1428 QETH_DBF_TEXT(SETUP
, 2, "idxanswr");
1429 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1430 iob
= qeth_get_buffer(channel
);
1431 iob
->callback
= idx_reply_cb
;
1432 memcpy(&channel
->ccw
, READ_CCW
, sizeof(struct ccw1
));
1433 channel
->ccw
.count
= QETH_BUFSIZE
;
1434 channel
->ccw
.cda
= (__u32
) __pa(iob
->data
);
1436 wait_event(card
->wait_q
,
1437 atomic_cmpxchg(&channel
->irq_pending
, 0, 1) == 0);
1438 QETH_DBF_TEXT(SETUP
, 6, "noirqpnd");
1439 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1440 rc
= ccw_device_start(channel
->ccwdev
,
1441 &channel
->ccw
, (addr_t
) iob
, 0, 0);
1442 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1445 QETH_DBF_MESSAGE(2, "Error2 in activating channel rc=%d\n", rc
);
1446 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
1447 atomic_set(&channel
->irq_pending
, 0);
1448 wake_up(&card
->wait_q
);
1451 rc
= wait_event_interruptible_timeout(card
->wait_q
,
1452 channel
->state
== CH_STATE_UP
, QETH_TIMEOUT
);
1453 if (rc
== -ERESTARTSYS
)
1455 if (channel
->state
!= CH_STATE_UP
) {
1457 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
1458 qeth_clear_cmd_buffers(channel
);
1464 static int qeth_idx_activate_channel(struct qeth_channel
*channel
,
1465 void (*idx_reply_cb
)(struct qeth_channel
*,
1466 struct qeth_cmd_buffer
*))
1468 struct qeth_card
*card
;
1469 struct qeth_cmd_buffer
*iob
;
1470 unsigned long flags
;
1474 struct ccw_dev_id temp_devid
;
1476 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1478 QETH_DBF_TEXT(SETUP
, 2, "idxactch");
1480 iob
= qeth_get_buffer(channel
);
1481 iob
->callback
= idx_reply_cb
;
1482 memcpy(&channel
->ccw
, WRITE_CCW
, sizeof(struct ccw1
));
1483 channel
->ccw
.count
= IDX_ACTIVATE_SIZE
;
1484 channel
->ccw
.cda
= (__u32
) __pa(iob
->data
);
1485 if (channel
== &card
->write
) {
1486 memcpy(iob
->data
, IDX_ACTIVATE_WRITE
, IDX_ACTIVATE_SIZE
);
1487 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob
->data
),
1488 &card
->seqno
.trans_hdr
, QETH_SEQ_NO_LENGTH
);
1489 card
->seqno
.trans_hdr
++;
1491 memcpy(iob
->data
, IDX_ACTIVATE_READ
, IDX_ACTIVATE_SIZE
);
1492 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob
->data
),
1493 &card
->seqno
.trans_hdr
, QETH_SEQ_NO_LENGTH
);
1495 tmp
= ((__u8
)card
->info
.portno
) | 0x80;
1496 memcpy(QETH_IDX_ACT_PNO(iob
->data
), &tmp
, 1);
1497 memcpy(QETH_IDX_ACT_ISSUER_RM_TOKEN(iob
->data
),
1498 &card
->token
.issuer_rm_w
, QETH_MPC_TOKEN_LENGTH
);
1499 memcpy(QETH_IDX_ACT_FUNC_LEVEL(iob
->data
),
1500 &card
->info
.func_level
, sizeof(__u16
));
1501 ccw_device_get_id(CARD_DDEV(card
), &temp_devid
);
1502 memcpy(QETH_IDX_ACT_QDIO_DEV_CUA(iob
->data
), &temp_devid
.devno
, 2);
1503 temp
= (card
->info
.cula
<< 8) + card
->info
.unit_addr2
;
1504 memcpy(QETH_IDX_ACT_QDIO_DEV_REALADDR(iob
->data
), &temp
, 2);
1506 wait_event(card
->wait_q
,
1507 atomic_cmpxchg(&channel
->irq_pending
, 0, 1) == 0);
1508 QETH_DBF_TEXT(SETUP
, 6, "noirqpnd");
1509 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1510 rc
= ccw_device_start(channel
->ccwdev
,
1511 &channel
->ccw
, (addr_t
) iob
, 0, 0);
1512 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1515 QETH_DBF_MESSAGE(2, "Error1 in activating channel. rc=%d\n",
1517 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
1518 atomic_set(&channel
->irq_pending
, 0);
1519 wake_up(&card
->wait_q
);
1522 rc
= wait_event_interruptible_timeout(card
->wait_q
,
1523 channel
->state
== CH_STATE_ACTIVATING
, QETH_TIMEOUT
);
1524 if (rc
== -ERESTARTSYS
)
1526 if (channel
->state
!= CH_STATE_ACTIVATING
) {
1527 dev_warn(&channel
->ccwdev
->dev
, "The qeth device driver"
1528 " failed to recover an error on the device\n");
1529 QETH_DBF_MESSAGE(2, "%s IDX activate timed out\n",
1530 dev_name(&channel
->ccwdev
->dev
));
1531 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", -ETIME
);
1532 qeth_clear_cmd_buffers(channel
);
1535 return qeth_idx_activate_get_answer(channel
, idx_reply_cb
);
1538 static int qeth_peer_func_level(int level
)
1540 if ((level
& 0xff) == 8)
1541 return (level
& 0xff) + 0x400;
1542 if (((level
>> 8) & 3) == 1)
1543 return (level
& 0xff) + 0x200;
1547 static void qeth_idx_write_cb(struct qeth_channel
*channel
,
1548 struct qeth_cmd_buffer
*iob
)
1550 struct qeth_card
*card
;
1553 QETH_DBF_TEXT(SETUP
, 2, "idxwrcb");
1555 if (channel
->state
== CH_STATE_DOWN
) {
1556 channel
->state
= CH_STATE_ACTIVATING
;
1559 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1561 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob
->data
))) {
1562 if (QETH_IDX_ACT_CAUSE_CODE(iob
->data
) == 0x19)
1563 dev_err(&card
->write
.ccwdev
->dev
,
1564 "The adapter is used exclusively by another "
1567 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on write channel:"
1568 " negative reply\n",
1569 dev_name(&card
->write
.ccwdev
->dev
));
1572 memcpy(&temp
, QETH_IDX_ACT_FUNC_LEVEL(iob
->data
), 2);
1573 if ((temp
& ~0x0100) != qeth_peer_func_level(card
->info
.func_level
)) {
1574 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on write channel: "
1575 "function level mismatch (sent: 0x%x, received: "
1576 "0x%x)\n", dev_name(&card
->write
.ccwdev
->dev
),
1577 card
->info
.func_level
, temp
);
1580 channel
->state
= CH_STATE_UP
;
1582 qeth_release_buffer(channel
, iob
);
1585 static void qeth_idx_read_cb(struct qeth_channel
*channel
,
1586 struct qeth_cmd_buffer
*iob
)
1588 struct qeth_card
*card
;
1591 QETH_DBF_TEXT(SETUP
, 2, "idxrdcb");
1592 if (channel
->state
== CH_STATE_DOWN
) {
1593 channel
->state
= CH_STATE_ACTIVATING
;
1597 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1598 if (qeth_check_idx_response(iob
->data
))
1601 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob
->data
))) {
1602 if (QETH_IDX_ACT_CAUSE_CODE(iob
->data
) == 0x19)
1603 dev_err(&card
->write
.ccwdev
->dev
,
1604 "The adapter is used exclusively by another "
1607 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on read channel:"
1608 " negative reply\n",
1609 dev_name(&card
->read
.ccwdev
->dev
));
1614 * temporary fix for microcode bug
1615 * to revert it,replace OR by AND
1617 if ((!QETH_IDX_NO_PORTNAME_REQUIRED(iob
->data
)) ||
1618 (card
->info
.type
== QETH_CARD_TYPE_OSAE
))
1619 card
->info
.portname_required
= 1;
1621 memcpy(&temp
, QETH_IDX_ACT_FUNC_LEVEL(iob
->data
), 2);
1622 if (temp
!= qeth_peer_func_level(card
->info
.func_level
)) {
1623 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on read channel: function "
1624 "level mismatch (sent: 0x%x, received: 0x%x)\n",
1625 dev_name(&card
->read
.ccwdev
->dev
),
1626 card
->info
.func_level
, temp
);
1629 memcpy(&card
->token
.issuer_rm_r
,
1630 QETH_IDX_ACT_ISSUER_RM_TOKEN(iob
->data
),
1631 QETH_MPC_TOKEN_LENGTH
);
1632 memcpy(&card
->info
.mcl_level
[0],
1633 QETH_IDX_REPLY_LEVEL(iob
->data
), QETH_MCL_LENGTH
);
1634 channel
->state
= CH_STATE_UP
;
1636 qeth_release_buffer(channel
, iob
);
1639 void qeth_prepare_control_data(struct qeth_card
*card
, int len
,
1640 struct qeth_cmd_buffer
*iob
)
1642 qeth_setup_ccw(&card
->write
, iob
->data
, len
);
1643 iob
->callback
= qeth_release_buffer
;
1645 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob
->data
),
1646 &card
->seqno
.trans_hdr
, QETH_SEQ_NO_LENGTH
);
1647 card
->seqno
.trans_hdr
++;
1648 memcpy(QETH_PDU_HEADER_SEQ_NO(iob
->data
),
1649 &card
->seqno
.pdu_hdr
, QETH_SEQ_NO_LENGTH
);
1650 card
->seqno
.pdu_hdr
++;
1651 memcpy(QETH_PDU_HEADER_ACK_SEQ_NO(iob
->data
),
1652 &card
->seqno
.pdu_hdr_ack
, QETH_SEQ_NO_LENGTH
);
1653 QETH_DBF_HEX(CTRL
, 2, iob
->data
, QETH_DBF_CTRL_LEN
);
1655 EXPORT_SYMBOL_GPL(qeth_prepare_control_data
);
1657 int qeth_send_control_data(struct qeth_card
*card
, int len
,
1658 struct qeth_cmd_buffer
*iob
,
1659 int (*reply_cb
)(struct qeth_card
*, struct qeth_reply
*,
1664 unsigned long flags
;
1665 struct qeth_reply
*reply
= NULL
;
1666 unsigned long timeout
, event_timeout
;
1667 struct qeth_ipa_cmd
*cmd
;
1669 QETH_DBF_TEXT(TRACE
, 2, "sendctl");
1671 reply
= qeth_alloc_reply(card
);
1675 reply
->callback
= reply_cb
;
1676 reply
->param
= reply_param
;
1677 if (card
->state
== CARD_STATE_DOWN
)
1678 reply
->seqno
= QETH_IDX_COMMAND_SEQNO
;
1680 reply
->seqno
= card
->seqno
.ipa
++;
1681 init_waitqueue_head(&reply
->wait_q
);
1682 spin_lock_irqsave(&card
->lock
, flags
);
1683 list_add_tail(&reply
->list
, &card
->cmd_waiter_list
);
1684 spin_unlock_irqrestore(&card
->lock
, flags
);
1685 QETH_DBF_HEX(CTRL
, 2, iob
->data
, QETH_DBF_CTRL_LEN
);
1687 while (atomic_cmpxchg(&card
->write
.irq_pending
, 0, 1)) ;
1688 qeth_prepare_control_data(card
, len
, iob
);
1690 if (IS_IPA(iob
->data
))
1691 event_timeout
= QETH_IPA_TIMEOUT
;
1693 event_timeout
= QETH_TIMEOUT
;
1694 timeout
= jiffies
+ event_timeout
;
1696 QETH_DBF_TEXT(TRACE
, 6, "noirqpnd");
1697 spin_lock_irqsave(get_ccwdev_lock(card
->write
.ccwdev
), flags
);
1698 rc
= ccw_device_start(card
->write
.ccwdev
, &card
->write
.ccw
,
1699 (addr_t
) iob
, 0, 0);
1700 spin_unlock_irqrestore(get_ccwdev_lock(card
->write
.ccwdev
), flags
);
1702 QETH_DBF_MESSAGE(2, "%s qeth_send_control_data: "
1703 "ccw_device_start rc = %i\n",
1704 dev_name(&card
->write
.ccwdev
->dev
), rc
);
1705 QETH_DBF_TEXT_(TRACE
, 2, " err%d", rc
);
1706 spin_lock_irqsave(&card
->lock
, flags
);
1707 list_del_init(&reply
->list
);
1708 qeth_put_reply(reply
);
1709 spin_unlock_irqrestore(&card
->lock
, flags
);
1710 qeth_release_buffer(iob
->channel
, iob
);
1711 atomic_set(&card
->write
.irq_pending
, 0);
1712 wake_up(&card
->wait_q
);
1716 /* we have only one long running ipassist, since we can ensure
1717 process context of this command we can sleep */
1718 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1719 if ((cmd
->hdr
.command
== IPA_CMD_SETIP
) &&
1720 (cmd
->hdr
.prot_version
== QETH_PROT_IPV4
)) {
1721 if (!wait_event_timeout(reply
->wait_q
,
1722 atomic_read(&reply
->received
), event_timeout
))
1725 while (!atomic_read(&reply
->received
)) {
1726 if (time_after(jiffies
, timeout
))
1733 qeth_put_reply(reply
);
1737 spin_lock_irqsave(&reply
->card
->lock
, flags
);
1738 list_del_init(&reply
->list
);
1739 spin_unlock_irqrestore(&reply
->card
->lock
, flags
);
1741 atomic_inc(&reply
->received
);
1742 wake_up(&reply
->wait_q
);
1744 qeth_put_reply(reply
);
1747 EXPORT_SYMBOL_GPL(qeth_send_control_data
);
1749 static int qeth_cm_enable_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
1752 struct qeth_cmd_buffer
*iob
;
1754 QETH_DBF_TEXT(SETUP
, 2, "cmenblcb");
1756 iob
= (struct qeth_cmd_buffer
*) data
;
1757 memcpy(&card
->token
.cm_filter_r
,
1758 QETH_CM_ENABLE_RESP_FILTER_TOKEN(iob
->data
),
1759 QETH_MPC_TOKEN_LENGTH
);
1760 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
1764 static int qeth_cm_enable(struct qeth_card
*card
)
1767 struct qeth_cmd_buffer
*iob
;
1769 QETH_DBF_TEXT(SETUP
, 2, "cmenable");
1771 iob
= qeth_wait_for_buffer(&card
->write
);
1772 memcpy(iob
->data
, CM_ENABLE
, CM_ENABLE_SIZE
);
1773 memcpy(QETH_CM_ENABLE_ISSUER_RM_TOKEN(iob
->data
),
1774 &card
->token
.issuer_rm_r
, QETH_MPC_TOKEN_LENGTH
);
1775 memcpy(QETH_CM_ENABLE_FILTER_TOKEN(iob
->data
),
1776 &card
->token
.cm_filter_w
, QETH_MPC_TOKEN_LENGTH
);
1778 rc
= qeth_send_control_data(card
, CM_ENABLE_SIZE
, iob
,
1779 qeth_cm_enable_cb
, NULL
);
1783 static int qeth_cm_setup_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
1787 struct qeth_cmd_buffer
*iob
;
1789 QETH_DBF_TEXT(SETUP
, 2, "cmsetpcb");
1791 iob
= (struct qeth_cmd_buffer
*) data
;
1792 memcpy(&card
->token
.cm_connection_r
,
1793 QETH_CM_SETUP_RESP_DEST_ADDR(iob
->data
),
1794 QETH_MPC_TOKEN_LENGTH
);
1795 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
1799 static int qeth_cm_setup(struct qeth_card
*card
)
1802 struct qeth_cmd_buffer
*iob
;
1804 QETH_DBF_TEXT(SETUP
, 2, "cmsetup");
1806 iob
= qeth_wait_for_buffer(&card
->write
);
1807 memcpy(iob
->data
, CM_SETUP
, CM_SETUP_SIZE
);
1808 memcpy(QETH_CM_SETUP_DEST_ADDR(iob
->data
),
1809 &card
->token
.issuer_rm_r
, QETH_MPC_TOKEN_LENGTH
);
1810 memcpy(QETH_CM_SETUP_CONNECTION_TOKEN(iob
->data
),
1811 &card
->token
.cm_connection_w
, QETH_MPC_TOKEN_LENGTH
);
1812 memcpy(QETH_CM_SETUP_FILTER_TOKEN(iob
->data
),
1813 &card
->token
.cm_filter_r
, QETH_MPC_TOKEN_LENGTH
);
1814 rc
= qeth_send_control_data(card
, CM_SETUP_SIZE
, iob
,
1815 qeth_cm_setup_cb
, NULL
);
1820 static inline int qeth_get_initial_mtu_for_card(struct qeth_card
*card
)
1822 switch (card
->info
.type
) {
1823 case QETH_CARD_TYPE_UNKNOWN
:
1825 case QETH_CARD_TYPE_IQD
:
1826 return card
->info
.max_mtu
;
1827 case QETH_CARD_TYPE_OSAE
:
1828 switch (card
->info
.link_type
) {
1829 case QETH_LINK_TYPE_HSTR
:
1830 case QETH_LINK_TYPE_LANE_TR
:
1840 static inline int qeth_get_max_mtu_for_card(int cardtype
)
1844 case QETH_CARD_TYPE_UNKNOWN
:
1845 case QETH_CARD_TYPE_OSAE
:
1846 case QETH_CARD_TYPE_OSN
:
1848 case QETH_CARD_TYPE_IQD
:
1855 static inline int qeth_get_mtu_out_of_mpc(int cardtype
)
1858 case QETH_CARD_TYPE_IQD
:
1865 static inline int qeth_get_mtu_outof_framesize(int framesize
)
1867 switch (framesize
) {
1881 static inline int qeth_mtu_is_valid(struct qeth_card
*card
, int mtu
)
1883 switch (card
->info
.type
) {
1884 case QETH_CARD_TYPE_OSAE
:
1885 return ((mtu
>= 576) && (mtu
<= 61440));
1886 case QETH_CARD_TYPE_IQD
:
1887 return ((mtu
>= 576) &&
1888 (mtu
<= card
->info
.max_mtu
+ 4096 - 32));
1889 case QETH_CARD_TYPE_OSN
:
1890 case QETH_CARD_TYPE_UNKNOWN
:
1896 static int qeth_ulp_enable_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
1900 __u16 mtu
, framesize
;
1903 struct qeth_cmd_buffer
*iob
;
1905 QETH_DBF_TEXT(SETUP
, 2, "ulpenacb");
1907 iob
= (struct qeth_cmd_buffer
*) data
;
1908 memcpy(&card
->token
.ulp_filter_r
,
1909 QETH_ULP_ENABLE_RESP_FILTER_TOKEN(iob
->data
),
1910 QETH_MPC_TOKEN_LENGTH
);
1911 if (qeth_get_mtu_out_of_mpc(card
->info
.type
)) {
1912 memcpy(&framesize
, QETH_ULP_ENABLE_RESP_MAX_MTU(iob
->data
), 2);
1913 mtu
= qeth_get_mtu_outof_framesize(framesize
);
1916 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
1919 card
->info
.max_mtu
= mtu
;
1920 card
->info
.initial_mtu
= mtu
;
1921 card
->qdio
.in_buf_size
= mtu
+ 2 * PAGE_SIZE
;
1923 card
->info
.initial_mtu
= qeth_get_initial_mtu_for_card(card
);
1924 card
->info
.max_mtu
= qeth_get_max_mtu_for_card(card
->info
.type
);
1925 card
->qdio
.in_buf_size
= QETH_IN_BUF_SIZE_DEFAULT
;
1928 memcpy(&len
, QETH_ULP_ENABLE_RESP_DIFINFO_LEN(iob
->data
), 2);
1929 if (len
>= QETH_MPC_DIFINFO_LEN_INDICATES_LINK_TYPE
) {
1931 QETH_ULP_ENABLE_RESP_LINK_TYPE(iob
->data
), 1);
1932 card
->info
.link_type
= link_type
;
1934 card
->info
.link_type
= 0;
1935 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
1939 static int qeth_ulp_enable(struct qeth_card
*card
)
1943 struct qeth_cmd_buffer
*iob
;
1945 /*FIXME: trace view callbacks*/
1946 QETH_DBF_TEXT(SETUP
, 2, "ulpenabl");
1948 iob
= qeth_wait_for_buffer(&card
->write
);
1949 memcpy(iob
->data
, ULP_ENABLE
, ULP_ENABLE_SIZE
);
1951 *(QETH_ULP_ENABLE_LINKNUM(iob
->data
)) =
1952 (__u8
) card
->info
.portno
;
1953 if (card
->options
.layer2
)
1954 if (card
->info
.type
== QETH_CARD_TYPE_OSN
)
1955 prot_type
= QETH_PROT_OSN2
;
1957 prot_type
= QETH_PROT_LAYER2
;
1959 prot_type
= QETH_PROT_TCPIP
;
1961 memcpy(QETH_ULP_ENABLE_PROT_TYPE(iob
->data
), &prot_type
, 1);
1962 memcpy(QETH_ULP_ENABLE_DEST_ADDR(iob
->data
),
1963 &card
->token
.cm_connection_r
, QETH_MPC_TOKEN_LENGTH
);
1964 memcpy(QETH_ULP_ENABLE_FILTER_TOKEN(iob
->data
),
1965 &card
->token
.ulp_filter_w
, QETH_MPC_TOKEN_LENGTH
);
1966 memcpy(QETH_ULP_ENABLE_PORTNAME_AND_LL(iob
->data
),
1967 card
->info
.portname
, 9);
1968 rc
= qeth_send_control_data(card
, ULP_ENABLE_SIZE
, iob
,
1969 qeth_ulp_enable_cb
, NULL
);
1974 static int qeth_ulp_setup_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
1977 struct qeth_cmd_buffer
*iob
;
1979 QETH_DBF_TEXT(SETUP
, 2, "ulpstpcb");
1981 iob
= (struct qeth_cmd_buffer
*) data
;
1982 memcpy(&card
->token
.ulp_connection_r
,
1983 QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob
->data
),
1984 QETH_MPC_TOKEN_LENGTH
);
1985 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
1989 static int qeth_ulp_setup(struct qeth_card
*card
)
1993 struct qeth_cmd_buffer
*iob
;
1994 struct ccw_dev_id dev_id
;
1996 QETH_DBF_TEXT(SETUP
, 2, "ulpsetup");
1998 iob
= qeth_wait_for_buffer(&card
->write
);
1999 memcpy(iob
->data
, ULP_SETUP
, ULP_SETUP_SIZE
);
2001 memcpy(QETH_ULP_SETUP_DEST_ADDR(iob
->data
),
2002 &card
->token
.cm_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2003 memcpy(QETH_ULP_SETUP_CONNECTION_TOKEN(iob
->data
),
2004 &card
->token
.ulp_connection_w
, QETH_MPC_TOKEN_LENGTH
);
2005 memcpy(QETH_ULP_SETUP_FILTER_TOKEN(iob
->data
),
2006 &card
->token
.ulp_filter_r
, QETH_MPC_TOKEN_LENGTH
);
2008 ccw_device_get_id(CARD_DDEV(card
), &dev_id
);
2009 memcpy(QETH_ULP_SETUP_CUA(iob
->data
), &dev_id
.devno
, 2);
2010 temp
= (card
->info
.cula
<< 8) + card
->info
.unit_addr2
;
2011 memcpy(QETH_ULP_SETUP_REAL_DEVADDR(iob
->data
), &temp
, 2);
2012 rc
= qeth_send_control_data(card
, ULP_SETUP_SIZE
, iob
,
2013 qeth_ulp_setup_cb
, NULL
);
2017 static int qeth_alloc_qdio_buffers(struct qeth_card
*card
)
2021 QETH_DBF_TEXT(SETUP
, 2, "allcqdbf");
2023 if (atomic_cmpxchg(&card
->qdio
.state
, QETH_QDIO_UNINITIALIZED
,
2024 QETH_QDIO_ALLOCATED
) != QETH_QDIO_UNINITIALIZED
)
2027 card
->qdio
.in_q
= kmalloc(sizeof(struct qeth_qdio_q
),
2029 if (!card
->qdio
.in_q
)
2031 QETH_DBF_TEXT(SETUP
, 2, "inq");
2032 QETH_DBF_HEX(SETUP
, 2, &card
->qdio
.in_q
, sizeof(void *));
2033 memset(card
->qdio
.in_q
, 0, sizeof(struct qeth_qdio_q
));
2034 /* give inbound qeth_qdio_buffers their qdio_buffers */
2035 for (i
= 0; i
< QDIO_MAX_BUFFERS_PER_Q
; ++i
)
2036 card
->qdio
.in_q
->bufs
[i
].buffer
=
2037 &card
->qdio
.in_q
->qdio_bufs
[i
];
2038 /* inbound buffer pool */
2039 if (qeth_alloc_buffer_pool(card
))
2043 kmalloc(card
->qdio
.no_out_queues
*
2044 sizeof(struct qeth_qdio_out_q
*), GFP_KERNEL
);
2045 if (!card
->qdio
.out_qs
)
2047 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
2048 card
->qdio
.out_qs
[i
] = kmalloc(sizeof(struct qeth_qdio_out_q
),
2050 if (!card
->qdio
.out_qs
[i
])
2052 QETH_DBF_TEXT_(SETUP
, 2, "outq %i", i
);
2053 QETH_DBF_HEX(SETUP
, 2, &card
->qdio
.out_qs
[i
], sizeof(void *));
2054 memset(card
->qdio
.out_qs
[i
], 0, sizeof(struct qeth_qdio_out_q
));
2055 card
->qdio
.out_qs
[i
]->queue_no
= i
;
2056 /* give outbound qeth_qdio_buffers their qdio_buffers */
2057 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
) {
2058 card
->qdio
.out_qs
[i
]->bufs
[j
].buffer
=
2059 &card
->qdio
.out_qs
[i
]->qdio_bufs
[j
];
2060 skb_queue_head_init(&card
->qdio
.out_qs
[i
]->bufs
[j
].
2063 &card
->qdio
.out_qs
[i
]->bufs
[j
].skb_list
.lock
,
2064 &qdio_out_skb_queue_key
);
2065 INIT_LIST_HEAD(&card
->qdio
.out_qs
[i
]->bufs
[j
].ctx_list
);
2072 kfree(card
->qdio
.out_qs
[--i
]);
2073 kfree(card
->qdio
.out_qs
);
2074 card
->qdio
.out_qs
= NULL
;
2076 qeth_free_buffer_pool(card
);
2078 kfree(card
->qdio
.in_q
);
2079 card
->qdio
.in_q
= NULL
;
2081 atomic_set(&card
->qdio
.state
, QETH_QDIO_UNINITIALIZED
);
2085 static void qeth_create_qib_param_field(struct qeth_card
*card
,
2089 param_field
[0] = _ascebc
['P'];
2090 param_field
[1] = _ascebc
['C'];
2091 param_field
[2] = _ascebc
['I'];
2092 param_field
[3] = _ascebc
['T'];
2093 *((unsigned int *) (¶m_field
[4])) = QETH_PCI_THRESHOLD_A(card
);
2094 *((unsigned int *) (¶m_field
[8])) = QETH_PCI_THRESHOLD_B(card
);
2095 *((unsigned int *) (¶m_field
[12])) = QETH_PCI_TIMER_VALUE(card
);
2098 static void qeth_create_qib_param_field_blkt(struct qeth_card
*card
,
2101 param_field
[16] = _ascebc
['B'];
2102 param_field
[17] = _ascebc
['L'];
2103 param_field
[18] = _ascebc
['K'];
2104 param_field
[19] = _ascebc
['T'];
2105 *((unsigned int *) (¶m_field
[20])) = card
->info
.blkt
.time_total
;
2106 *((unsigned int *) (¶m_field
[24])) = card
->info
.blkt
.inter_packet
;
2107 *((unsigned int *) (¶m_field
[28])) =
2108 card
->info
.blkt
.inter_packet_jumbo
;
2111 static int qeth_qdio_activate(struct qeth_card
*card
)
2113 QETH_DBF_TEXT(SETUP
, 3, "qdioact");
2114 return qdio_activate(CARD_DDEV(card
));
2117 static int qeth_dm_act(struct qeth_card
*card
)
2120 struct qeth_cmd_buffer
*iob
;
2122 QETH_DBF_TEXT(SETUP
, 2, "dmact");
2124 iob
= qeth_wait_for_buffer(&card
->write
);
2125 memcpy(iob
->data
, DM_ACT
, DM_ACT_SIZE
);
2127 memcpy(QETH_DM_ACT_DEST_ADDR(iob
->data
),
2128 &card
->token
.cm_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2129 memcpy(QETH_DM_ACT_CONNECTION_TOKEN(iob
->data
),
2130 &card
->token
.ulp_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2131 rc
= qeth_send_control_data(card
, DM_ACT_SIZE
, iob
, NULL
, NULL
);
2135 static int qeth_mpc_initialize(struct qeth_card
*card
)
2139 QETH_DBF_TEXT(SETUP
, 2, "mpcinit");
2141 rc
= qeth_issue_next_read(card
);
2143 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
2146 rc
= qeth_cm_enable(card
);
2148 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
2151 rc
= qeth_cm_setup(card
);
2153 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
2156 rc
= qeth_ulp_enable(card
);
2158 QETH_DBF_TEXT_(SETUP
, 2, "4err%d", rc
);
2161 rc
= qeth_ulp_setup(card
);
2163 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
2166 rc
= qeth_alloc_qdio_buffers(card
);
2168 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
2171 rc
= qeth_qdio_establish(card
);
2173 QETH_DBF_TEXT_(SETUP
, 2, "6err%d", rc
);
2174 qeth_free_qdio_buffers(card
);
2177 rc
= qeth_qdio_activate(card
);
2179 QETH_DBF_TEXT_(SETUP
, 2, "7err%d", rc
);
2182 rc
= qeth_dm_act(card
);
2184 QETH_DBF_TEXT_(SETUP
, 2, "8err%d", rc
);
2190 qeth_qdio_clear_card(card
, card
->info
.type
!= QETH_CARD_TYPE_IQD
);
2194 static void qeth_print_status_with_portname(struct qeth_card
*card
)
2199 sprintf(dbf_text
, "%s", card
->info
.portname
+ 1);
2200 for (i
= 0; i
< 8; i
++)
2202 (char) _ebcasc
[(__u8
) dbf_text
[i
]];
2204 dev_info(&card
->gdev
->dev
, "Device is a%s card%s%s%s\n"
2205 "with link type %s (portname: %s)\n",
2206 qeth_get_cardname(card
),
2207 (card
->info
.mcl_level
[0]) ? " (level: " : "",
2208 (card
->info
.mcl_level
[0]) ? card
->info
.mcl_level
: "",
2209 (card
->info
.mcl_level
[0]) ? ")" : "",
2210 qeth_get_cardname_short(card
),
2215 static void qeth_print_status_no_portname(struct qeth_card
*card
)
2217 if (card
->info
.portname
[0])
2218 dev_info(&card
->gdev
->dev
, "Device is a%s "
2219 "card%s%s%s\nwith link type %s "
2220 "(no portname needed by interface).\n",
2221 qeth_get_cardname(card
),
2222 (card
->info
.mcl_level
[0]) ? " (level: " : "",
2223 (card
->info
.mcl_level
[0]) ? card
->info
.mcl_level
: "",
2224 (card
->info
.mcl_level
[0]) ? ")" : "",
2225 qeth_get_cardname_short(card
));
2227 dev_info(&card
->gdev
->dev
, "Device is a%s "
2228 "card%s%s%s\nwith link type %s.\n",
2229 qeth_get_cardname(card
),
2230 (card
->info
.mcl_level
[0]) ? " (level: " : "",
2231 (card
->info
.mcl_level
[0]) ? card
->info
.mcl_level
: "",
2232 (card
->info
.mcl_level
[0]) ? ")" : "",
2233 qeth_get_cardname_short(card
));
2236 void qeth_print_status_message(struct qeth_card
*card
)
2238 switch (card
->info
.type
) {
2239 case QETH_CARD_TYPE_OSAE
:
2240 /* VM will use a non-zero first character
2241 * to indicate a HiperSockets like reporting
2242 * of the level OSA sets the first character to zero
2244 if (!card
->info
.mcl_level
[0]) {
2245 sprintf(card
->info
.mcl_level
, "%02x%02x",
2246 card
->info
.mcl_level
[2],
2247 card
->info
.mcl_level
[3]);
2249 card
->info
.mcl_level
[QETH_MCL_LENGTH
] = 0;
2253 case QETH_CARD_TYPE_IQD
:
2254 if ((card
->info
.guestlan
) ||
2255 (card
->info
.mcl_level
[0] & 0x80)) {
2256 card
->info
.mcl_level
[0] = (char) _ebcasc
[(__u8
)
2257 card
->info
.mcl_level
[0]];
2258 card
->info
.mcl_level
[1] = (char) _ebcasc
[(__u8
)
2259 card
->info
.mcl_level
[1]];
2260 card
->info
.mcl_level
[2] = (char) _ebcasc
[(__u8
)
2261 card
->info
.mcl_level
[2]];
2262 card
->info
.mcl_level
[3] = (char) _ebcasc
[(__u8
)
2263 card
->info
.mcl_level
[3]];
2264 card
->info
.mcl_level
[QETH_MCL_LENGTH
] = 0;
2268 memset(&card
->info
.mcl_level
[0], 0, QETH_MCL_LENGTH
+ 1);
2270 if (card
->info
.portname_required
)
2271 qeth_print_status_with_portname(card
);
2273 qeth_print_status_no_portname(card
);
2275 EXPORT_SYMBOL_GPL(qeth_print_status_message
);
2277 static void qeth_initialize_working_pool_list(struct qeth_card
*card
)
2279 struct qeth_buffer_pool_entry
*entry
;
2281 QETH_DBF_TEXT(TRACE
, 5, "inwrklst");
2283 list_for_each_entry(entry
,
2284 &card
->qdio
.init_pool
.entry_list
, init_list
) {
2285 qeth_put_buffer_pool_entry(card
, entry
);
2289 static inline struct qeth_buffer_pool_entry
*qeth_find_free_buffer_pool_entry(
2290 struct qeth_card
*card
)
2292 struct list_head
*plh
;
2293 struct qeth_buffer_pool_entry
*entry
;
2297 if (list_empty(&card
->qdio
.in_buf_pool
.entry_list
))
2300 list_for_each(plh
, &card
->qdio
.in_buf_pool
.entry_list
) {
2301 entry
= list_entry(plh
, struct qeth_buffer_pool_entry
, list
);
2303 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(card
); ++i
) {
2304 if (page_count(virt_to_page(entry
->elements
[i
])) > 1) {
2310 list_del_init(&entry
->list
);
2315 /* no free buffer in pool so take first one and swap pages */
2316 entry
= list_entry(card
->qdio
.in_buf_pool
.entry_list
.next
,
2317 struct qeth_buffer_pool_entry
, list
);
2318 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(card
); ++i
) {
2319 if (page_count(virt_to_page(entry
->elements
[i
])) > 1) {
2320 page
= alloc_page(GFP_ATOMIC
);
2324 free_page((unsigned long)entry
->elements
[i
]);
2325 entry
->elements
[i
] = page_address(page
);
2326 if (card
->options
.performance_stats
)
2327 card
->perf_stats
.sg_alloc_page_rx
++;
2331 list_del_init(&entry
->list
);
2335 static int qeth_init_input_buffer(struct qeth_card
*card
,
2336 struct qeth_qdio_buffer
*buf
)
2338 struct qeth_buffer_pool_entry
*pool_entry
;
2341 pool_entry
= qeth_find_free_buffer_pool_entry(card
);
2346 * since the buffer is accessed only from the input_tasklet
2347 * there shouldn't be a need to synchronize; also, since we use
2348 * the QETH_IN_BUF_REQUEUE_THRESHOLD we should never run out off
2352 buf
->pool_entry
= pool_entry
;
2353 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(card
); ++i
) {
2354 buf
->buffer
->element
[i
].length
= PAGE_SIZE
;
2355 buf
->buffer
->element
[i
].addr
= pool_entry
->elements
[i
];
2356 if (i
== QETH_MAX_BUFFER_ELEMENTS(card
) - 1)
2357 buf
->buffer
->element
[i
].flags
= SBAL_FLAGS_LAST_ENTRY
;
2359 buf
->buffer
->element
[i
].flags
= 0;
2364 int qeth_init_qdio_queues(struct qeth_card
*card
)
2369 QETH_DBF_TEXT(SETUP
, 2, "initqdqs");
2372 memset(card
->qdio
.in_q
->qdio_bufs
, 0,
2373 QDIO_MAX_BUFFERS_PER_Q
* sizeof(struct qdio_buffer
));
2374 qeth_initialize_working_pool_list(card
);
2375 /*give only as many buffers to hardware as we have buffer pool entries*/
2376 for (i
= 0; i
< card
->qdio
.in_buf_pool
.buf_count
- 1; ++i
)
2377 qeth_init_input_buffer(card
, &card
->qdio
.in_q
->bufs
[i
]);
2378 card
->qdio
.in_q
->next_buf_to_init
=
2379 card
->qdio
.in_buf_pool
.buf_count
- 1;
2380 rc
= do_QDIO(CARD_DDEV(card
), QDIO_FLAG_SYNC_INPUT
, 0, 0,
2381 card
->qdio
.in_buf_pool
.buf_count
- 1);
2383 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
2386 /* outbound queue */
2387 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
2388 memset(card
->qdio
.out_qs
[i
]->qdio_bufs
, 0,
2389 QDIO_MAX_BUFFERS_PER_Q
* sizeof(struct qdio_buffer
));
2390 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
) {
2391 qeth_clear_output_buffer(card
->qdio
.out_qs
[i
],
2392 &card
->qdio
.out_qs
[i
]->bufs
[j
]);
2394 card
->qdio
.out_qs
[i
]->card
= card
;
2395 card
->qdio
.out_qs
[i
]->next_buf_to_fill
= 0;
2396 card
->qdio
.out_qs
[i
]->do_pack
= 0;
2397 atomic_set(&card
->qdio
.out_qs
[i
]->used_buffers
, 0);
2398 atomic_set(&card
->qdio
.out_qs
[i
]->set_pci_flags_count
, 0);
2399 atomic_set(&card
->qdio
.out_qs
[i
]->state
,
2400 QETH_OUT_Q_UNLOCKED
);
2404 EXPORT_SYMBOL_GPL(qeth_init_qdio_queues
);
2406 static inline __u8
qeth_get_ipa_adp_type(enum qeth_link_types link_type
)
2408 switch (link_type
) {
2409 case QETH_LINK_TYPE_HSTR
:
2416 static void qeth_fill_ipacmd_header(struct qeth_card
*card
,
2417 struct qeth_ipa_cmd
*cmd
, __u8 command
,
2418 enum qeth_prot_versions prot
)
2420 memset(cmd
, 0, sizeof(struct qeth_ipa_cmd
));
2421 cmd
->hdr
.command
= command
;
2422 cmd
->hdr
.initiator
= IPA_CMD_INITIATOR_HOST
;
2423 cmd
->hdr
.seqno
= card
->seqno
.ipa
;
2424 cmd
->hdr
.adapter_type
= qeth_get_ipa_adp_type(card
->info
.link_type
);
2425 cmd
->hdr
.rel_adapter_no
= (__u8
) card
->info
.portno
;
2426 if (card
->options
.layer2
)
2427 cmd
->hdr
.prim_version_no
= 2;
2429 cmd
->hdr
.prim_version_no
= 1;
2430 cmd
->hdr
.param_count
= 1;
2431 cmd
->hdr
.prot_version
= prot
;
2432 cmd
->hdr
.ipa_supported
= 0;
2433 cmd
->hdr
.ipa_enabled
= 0;
2436 struct qeth_cmd_buffer
*qeth_get_ipacmd_buffer(struct qeth_card
*card
,
2437 enum qeth_ipa_cmds ipacmd
, enum qeth_prot_versions prot
)
2439 struct qeth_cmd_buffer
*iob
;
2440 struct qeth_ipa_cmd
*cmd
;
2442 iob
= qeth_wait_for_buffer(&card
->write
);
2443 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
2444 qeth_fill_ipacmd_header(card
, cmd
, ipacmd
, prot
);
2448 EXPORT_SYMBOL_GPL(qeth_get_ipacmd_buffer
);
2450 void qeth_prepare_ipa_cmd(struct qeth_card
*card
, struct qeth_cmd_buffer
*iob
,
2453 memcpy(iob
->data
, IPA_PDU_HEADER
, IPA_PDU_HEADER_SIZE
);
2454 memcpy(QETH_IPA_CMD_PROT_TYPE(iob
->data
), &prot_type
, 1);
2455 memcpy(QETH_IPA_CMD_DEST_ADDR(iob
->data
),
2456 &card
->token
.ulp_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2458 EXPORT_SYMBOL_GPL(qeth_prepare_ipa_cmd
);
2460 int qeth_send_ipa_cmd(struct qeth_card
*card
, struct qeth_cmd_buffer
*iob
,
2461 int (*reply_cb
)(struct qeth_card
*, struct qeth_reply
*,
2468 QETH_DBF_TEXT(TRACE
, 4, "sendipa");
2470 if (card
->options
.layer2
)
2471 if (card
->info
.type
== QETH_CARD_TYPE_OSN
)
2472 prot_type
= QETH_PROT_OSN2
;
2474 prot_type
= QETH_PROT_LAYER2
;
2476 prot_type
= QETH_PROT_TCPIP
;
2477 qeth_prepare_ipa_cmd(card
, iob
, prot_type
);
2478 rc
= qeth_send_control_data(card
, IPA_CMD_LENGTH
,
2479 iob
, reply_cb
, reply_param
);
2482 EXPORT_SYMBOL_GPL(qeth_send_ipa_cmd
);
2484 static int qeth_send_startstoplan(struct qeth_card
*card
,
2485 enum qeth_ipa_cmds ipacmd
, enum qeth_prot_versions prot
)
2488 struct qeth_cmd_buffer
*iob
;
2490 iob
= qeth_get_ipacmd_buffer(card
, ipacmd
, prot
);
2491 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
2496 int qeth_send_startlan(struct qeth_card
*card
)
2500 QETH_DBF_TEXT(SETUP
, 2, "strtlan");
2502 rc
= qeth_send_startstoplan(card
, IPA_CMD_STARTLAN
, 0);
2505 EXPORT_SYMBOL_GPL(qeth_send_startlan
);
2507 int qeth_send_stoplan(struct qeth_card
*card
)
2512 * TODO: according to the IPA format document page 14,
2513 * TCP/IP (we!) never issue a STOPLAN
2516 QETH_DBF_TEXT(SETUP
, 2, "stoplan");
2518 rc
= qeth_send_startstoplan(card
, IPA_CMD_STOPLAN
, 0);
2521 EXPORT_SYMBOL_GPL(qeth_send_stoplan
);
2523 int qeth_default_setadapterparms_cb(struct qeth_card
*card
,
2524 struct qeth_reply
*reply
, unsigned long data
)
2526 struct qeth_ipa_cmd
*cmd
;
2528 QETH_DBF_TEXT(TRACE
, 4, "defadpcb");
2530 cmd
= (struct qeth_ipa_cmd
*) data
;
2531 if (cmd
->hdr
.return_code
== 0)
2532 cmd
->hdr
.return_code
=
2533 cmd
->data
.setadapterparms
.hdr
.return_code
;
2536 EXPORT_SYMBOL_GPL(qeth_default_setadapterparms_cb
);
2538 static int qeth_query_setadapterparms_cb(struct qeth_card
*card
,
2539 struct qeth_reply
*reply
, unsigned long data
)
2541 struct qeth_ipa_cmd
*cmd
;
2543 QETH_DBF_TEXT(TRACE
, 3, "quyadpcb");
2545 cmd
= (struct qeth_ipa_cmd
*) data
;
2546 if (cmd
->data
.setadapterparms
.data
.query_cmds_supp
.lan_type
& 0x7f)
2547 card
->info
.link_type
=
2548 cmd
->data
.setadapterparms
.data
.query_cmds_supp
.lan_type
;
2549 card
->options
.adp
.supported_funcs
=
2550 cmd
->data
.setadapterparms
.data
.query_cmds_supp
.supported_cmds
;
2551 return qeth_default_setadapterparms_cb(card
, reply
, (unsigned long)cmd
);
2554 struct qeth_cmd_buffer
*qeth_get_adapter_cmd(struct qeth_card
*card
,
2555 __u32 command
, __u32 cmdlen
)
2557 struct qeth_cmd_buffer
*iob
;
2558 struct qeth_ipa_cmd
*cmd
;
2560 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SETADAPTERPARMS
,
2562 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
2563 cmd
->data
.setadapterparms
.hdr
.cmdlength
= cmdlen
;
2564 cmd
->data
.setadapterparms
.hdr
.command_code
= command
;
2565 cmd
->data
.setadapterparms
.hdr
.used_total
= 1;
2566 cmd
->data
.setadapterparms
.hdr
.seq_no
= 1;
2570 EXPORT_SYMBOL_GPL(qeth_get_adapter_cmd
);
2572 int qeth_query_setadapterparms(struct qeth_card
*card
)
2575 struct qeth_cmd_buffer
*iob
;
2577 QETH_DBF_TEXT(TRACE
, 3, "queryadp");
2578 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_QUERY_COMMANDS_SUPPORTED
,
2579 sizeof(struct qeth_ipacmd_setadpparms
));
2580 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_query_setadapterparms_cb
, NULL
);
2583 EXPORT_SYMBOL_GPL(qeth_query_setadapterparms
);
2585 int qeth_check_qdio_errors(struct qeth_card
*card
, struct qdio_buffer
*buf
,
2586 unsigned int qdio_error
, const char *dbftext
)
2589 QETH_DBF_TEXT(TRACE
, 2, dbftext
);
2590 QETH_DBF_TEXT(QERR
, 2, dbftext
);
2591 QETH_DBF_TEXT_(QERR
, 2, " F15=%02X",
2592 buf
->element
[15].flags
& 0xff);
2593 QETH_DBF_TEXT_(QERR
, 2, " F14=%02X",
2594 buf
->element
[14].flags
& 0xff);
2595 QETH_DBF_TEXT_(QERR
, 2, " qerr=%X", qdio_error
);
2596 if ((buf
->element
[15].flags
& 0xff) == 0x12) {
2597 card
->stats
.rx_dropped
++;
2604 EXPORT_SYMBOL_GPL(qeth_check_qdio_errors
);
2606 void qeth_queue_input_buffer(struct qeth_card
*card
, int index
)
2608 struct qeth_qdio_q
*queue
= card
->qdio
.in_q
;
2614 count
= (index
< queue
->next_buf_to_init
)?
2615 card
->qdio
.in_buf_pool
.buf_count
-
2616 (queue
->next_buf_to_init
- index
) :
2617 card
->qdio
.in_buf_pool
.buf_count
-
2618 (queue
->next_buf_to_init
+ QDIO_MAX_BUFFERS_PER_Q
- index
);
2619 /* only requeue at a certain threshold to avoid SIGAs */
2620 if (count
>= QETH_IN_BUF_REQUEUE_THRESHOLD(card
)) {
2621 for (i
= queue
->next_buf_to_init
;
2622 i
< queue
->next_buf_to_init
+ count
; ++i
) {
2623 if (qeth_init_input_buffer(card
,
2624 &queue
->bufs
[i
% QDIO_MAX_BUFFERS_PER_Q
])) {
2631 if (newcount
< count
) {
2632 /* we are in memory shortage so we switch back to
2633 traditional skb allocation and drop packages */
2634 atomic_set(&card
->force_alloc_skb
, 3);
2637 atomic_add_unless(&card
->force_alloc_skb
, -1, 0);
2641 * according to old code it should be avoided to requeue all
2642 * 128 buffers in order to benefit from PCI avoidance.
2643 * this function keeps at least one buffer (the buffer at
2644 * 'index') un-requeued -> this buffer is the first buffer that
2645 * will be requeued the next time
2647 if (card
->options
.performance_stats
) {
2648 card
->perf_stats
.inbound_do_qdio_cnt
++;
2649 card
->perf_stats
.inbound_do_qdio_start_time
=
2652 rc
= do_QDIO(CARD_DDEV(card
), QDIO_FLAG_SYNC_INPUT
, 0,
2653 queue
->next_buf_to_init
, count
);
2654 if (card
->options
.performance_stats
)
2655 card
->perf_stats
.inbound_do_qdio_time
+=
2657 card
->perf_stats
.inbound_do_qdio_start_time
;
2659 dev_warn(&card
->gdev
->dev
,
2660 "QDIO reported an error, rc=%i\n", rc
);
2661 QETH_DBF_TEXT(TRACE
, 2, "qinberr");
2662 QETH_DBF_TEXT_(TRACE
, 2, "%s", CARD_BUS_ID(card
));
2664 queue
->next_buf_to_init
= (queue
->next_buf_to_init
+ count
) %
2665 QDIO_MAX_BUFFERS_PER_Q
;
2668 EXPORT_SYMBOL_GPL(qeth_queue_input_buffer
);
2670 static int qeth_handle_send_error(struct qeth_card
*card
,
2671 struct qeth_qdio_out_buffer
*buffer
, unsigned int qdio_err
)
2673 int sbalf15
= buffer
->buffer
->element
[15].flags
& 0xff;
2675 QETH_DBF_TEXT(TRACE
, 6, "hdsnderr");
2676 if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
2683 qeth_check_qdio_errors(card
, buffer
->buffer
, qdio_err
, "qouterr");
2686 return QETH_SEND_ERROR_NONE
;
2688 if ((sbalf15
>= 15) && (sbalf15
<= 31))
2689 return QETH_SEND_ERROR_RETRY
;
2691 QETH_DBF_TEXT(TRACE
, 1, "lnkfail");
2692 QETH_DBF_TEXT_(TRACE
, 1, "%s", CARD_BUS_ID(card
));
2693 QETH_DBF_TEXT_(TRACE
, 1, "%04x %02x",
2694 (u16
)qdio_err
, (u8
)sbalf15
);
2695 return QETH_SEND_ERROR_LINK_FAILURE
;
2699 * Switched to packing state if the number of used buffers on a queue
2700 * reaches a certain limit.
2702 static void qeth_switch_to_packing_if_needed(struct qeth_qdio_out_q
*queue
)
2704 if (!queue
->do_pack
) {
2705 if (atomic_read(&queue
->used_buffers
)
2706 >= QETH_HIGH_WATERMARK_PACK
){
2707 /* switch non-PACKING -> PACKING */
2708 QETH_DBF_TEXT(TRACE
, 6, "np->pack");
2709 if (queue
->card
->options
.performance_stats
)
2710 queue
->card
->perf_stats
.sc_dp_p
++;
2717 * Switches from packing to non-packing mode. If there is a packing
2718 * buffer on the queue this buffer will be prepared to be flushed.
2719 * In that case 1 is returned to inform the caller. If no buffer
2720 * has to be flushed, zero is returned.
2722 static int qeth_switch_to_nonpacking_if_needed(struct qeth_qdio_out_q
*queue
)
2724 struct qeth_qdio_out_buffer
*buffer
;
2725 int flush_count
= 0;
2727 if (queue
->do_pack
) {
2728 if (atomic_read(&queue
->used_buffers
)
2729 <= QETH_LOW_WATERMARK_PACK
) {
2730 /* switch PACKING -> non-PACKING */
2731 QETH_DBF_TEXT(TRACE
, 6, "pack->np");
2732 if (queue
->card
->options
.performance_stats
)
2733 queue
->card
->perf_stats
.sc_p_dp
++;
2735 /* flush packing buffers */
2736 buffer
= &queue
->bufs
[queue
->next_buf_to_fill
];
2737 if ((atomic_read(&buffer
->state
) ==
2738 QETH_QDIO_BUF_EMPTY
) &&
2739 (buffer
->next_element_to_fill
> 0)) {
2740 atomic_set(&buffer
->state
,
2741 QETH_QDIO_BUF_PRIMED
);
2743 queue
->next_buf_to_fill
=
2744 (queue
->next_buf_to_fill
+ 1) %
2745 QDIO_MAX_BUFFERS_PER_Q
;
2753 * Called to flush a packing buffer if no more pci flags are on the queue.
2754 * Checks if there is a packing buffer and prepares it to be flushed.
2755 * In that case returns 1, otherwise zero.
2757 static int qeth_flush_buffers_on_no_pci(struct qeth_qdio_out_q
*queue
)
2759 struct qeth_qdio_out_buffer
*buffer
;
2761 buffer
= &queue
->bufs
[queue
->next_buf_to_fill
];
2762 if ((atomic_read(&buffer
->state
) == QETH_QDIO_BUF_EMPTY
) &&
2763 (buffer
->next_element_to_fill
> 0)) {
2764 /* it's a packing buffer */
2765 atomic_set(&buffer
->state
, QETH_QDIO_BUF_PRIMED
);
2766 queue
->next_buf_to_fill
=
2767 (queue
->next_buf_to_fill
+ 1) % QDIO_MAX_BUFFERS_PER_Q
;
2773 static void qeth_flush_buffers(struct qeth_qdio_out_q
*queue
, int index
,
2776 struct qeth_qdio_out_buffer
*buf
;
2779 unsigned int qdio_flags
;
2781 for (i
= index
; i
< index
+ count
; ++i
) {
2782 buf
= &queue
->bufs
[i
% QDIO_MAX_BUFFERS_PER_Q
];
2783 buf
->buffer
->element
[buf
->next_element_to_fill
- 1].flags
|=
2784 SBAL_FLAGS_LAST_ENTRY
;
2786 if (queue
->card
->info
.type
== QETH_CARD_TYPE_IQD
)
2789 if (!queue
->do_pack
) {
2790 if ((atomic_read(&queue
->used_buffers
) >=
2791 (QETH_HIGH_WATERMARK_PACK
-
2792 QETH_WATERMARK_PACK_FUZZ
)) &&
2793 !atomic_read(&queue
->set_pci_flags_count
)) {
2794 /* it's likely that we'll go to packing
2796 atomic_inc(&queue
->set_pci_flags_count
);
2797 buf
->buffer
->element
[0].flags
|= 0x40;
2800 if (!atomic_read(&queue
->set_pci_flags_count
)) {
2802 * there's no outstanding PCI any more, so we
2803 * have to request a PCI to be sure the the PCI
2804 * will wake at some time in the future then we
2805 * can flush packed buffers that might still be
2806 * hanging around, which can happen if no
2807 * further send was requested by the stack
2809 atomic_inc(&queue
->set_pci_flags_count
);
2810 buf
->buffer
->element
[0].flags
|= 0x40;
2815 queue
->sync_iqdio_error
= 0;
2816 queue
->card
->dev
->trans_start
= jiffies
;
2817 if (queue
->card
->options
.performance_stats
) {
2818 queue
->card
->perf_stats
.outbound_do_qdio_cnt
++;
2819 queue
->card
->perf_stats
.outbound_do_qdio_start_time
=
2822 qdio_flags
= QDIO_FLAG_SYNC_OUTPUT
;
2823 if (atomic_read(&queue
->set_pci_flags_count
))
2824 qdio_flags
|= QDIO_FLAG_PCI_OUT
;
2825 rc
= do_QDIO(CARD_DDEV(queue
->card
), qdio_flags
,
2826 queue
->queue_no
, index
, count
);
2827 if (queue
->card
->options
.performance_stats
)
2828 queue
->card
->perf_stats
.outbound_do_qdio_time
+=
2830 queue
->card
->perf_stats
.outbound_do_qdio_start_time
;
2832 if (!(rc
& QDIO_ERROR_SIGA_BUSY
))
2833 queue
->sync_iqdio_error
= rc
& 3;
2836 queue
->card
->stats
.tx_errors
+= count
;
2837 /* ignore temporary SIGA errors without busy condition */
2838 if (rc
== QDIO_ERROR_SIGA_TARGET
)
2840 QETH_DBF_TEXT(TRACE
, 2, "flushbuf");
2841 QETH_DBF_TEXT_(TRACE
, 2, " err%d", rc
);
2842 QETH_DBF_TEXT_(TRACE
, 2, "%s", CARD_DDEV_ID(queue
->card
));
2844 /* this must not happen under normal circumstances. if it
2845 * happens something is really wrong -> recover */
2846 qeth_schedule_recovery(queue
->card
);
2849 atomic_add(count
, &queue
->used_buffers
);
2850 if (queue
->card
->options
.performance_stats
)
2851 queue
->card
->perf_stats
.bufs_sent
+= count
;
2854 static void qeth_check_outbound_queue(struct qeth_qdio_out_q
*queue
)
2858 int q_was_packing
= 0;
2861 * check if weed have to switch to non-packing mode or if
2862 * we have to get a pci flag out on the queue
2864 if ((atomic_read(&queue
->used_buffers
) <= QETH_LOW_WATERMARK_PACK
) ||
2865 !atomic_read(&queue
->set_pci_flags_count
)) {
2866 if (atomic_xchg(&queue
->state
, QETH_OUT_Q_LOCKED_FLUSH
) ==
2867 QETH_OUT_Q_UNLOCKED
) {
2869 * If we get in here, there was no action in
2870 * do_send_packet. So, we check if there is a
2871 * packing buffer to be flushed here.
2873 netif_stop_queue(queue
->card
->dev
);
2874 index
= queue
->next_buf_to_fill
;
2875 q_was_packing
= queue
->do_pack
;
2876 /* queue->do_pack may change */
2878 flush_cnt
+= qeth_switch_to_nonpacking_if_needed(queue
);
2880 !atomic_read(&queue
->set_pci_flags_count
))
2882 qeth_flush_buffers_on_no_pci(queue
);
2883 if (queue
->card
->options
.performance_stats
&&
2885 queue
->card
->perf_stats
.bufs_sent_pack
+=
2888 qeth_flush_buffers(queue
, index
, flush_cnt
);
2889 atomic_set(&queue
->state
, QETH_OUT_Q_UNLOCKED
);
2894 void qeth_qdio_output_handler(struct ccw_device
*ccwdev
,
2895 unsigned int qdio_error
, int __queue
, int first_element
,
2896 int count
, unsigned long card_ptr
)
2898 struct qeth_card
*card
= (struct qeth_card
*) card_ptr
;
2899 struct qeth_qdio_out_q
*queue
= card
->qdio
.out_qs
[__queue
];
2900 struct qeth_qdio_out_buffer
*buffer
;
2902 unsigned qeth_send_err
;
2904 QETH_DBF_TEXT(TRACE
, 6, "qdouhdl");
2905 if (qdio_error
& QDIO_ERROR_ACTIVATE_CHECK_CONDITION
) {
2906 QETH_DBF_TEXT(TRACE
, 2, "achkcond");
2907 QETH_DBF_TEXT_(TRACE
, 2, "%s", CARD_BUS_ID(card
));
2908 netif_stop_queue(card
->dev
);
2909 qeth_schedule_recovery(card
);
2912 if (card
->options
.performance_stats
) {
2913 card
->perf_stats
.outbound_handler_cnt
++;
2914 card
->perf_stats
.outbound_handler_start_time
=
2917 for (i
= first_element
; i
< (first_element
+ count
); ++i
) {
2918 buffer
= &queue
->bufs
[i
% QDIO_MAX_BUFFERS_PER_Q
];
2919 qeth_send_err
= qeth_handle_send_error(card
, buffer
, qdio_error
);
2920 __qeth_clear_output_buffer(queue
, buffer
,
2921 (qeth_send_err
== QETH_SEND_ERROR_RETRY
) ? 1 : 0);
2923 atomic_sub(count
, &queue
->used_buffers
);
2924 /* check if we need to do something on this outbound queue */
2925 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
)
2926 qeth_check_outbound_queue(queue
);
2928 netif_wake_queue(queue
->card
->dev
);
2929 if (card
->options
.performance_stats
)
2930 card
->perf_stats
.outbound_handler_time
+= qeth_get_micros() -
2931 card
->perf_stats
.outbound_handler_start_time
;
2933 EXPORT_SYMBOL_GPL(qeth_qdio_output_handler
);
2935 int qeth_get_priority_queue(struct qeth_card
*card
, struct sk_buff
*skb
,
2936 int ipv
, int cast_type
)
2938 if (!ipv
&& (card
->info
.type
== QETH_CARD_TYPE_OSAE
))
2939 return card
->qdio
.default_out_queue
;
2940 switch (card
->qdio
.no_out_queues
) {
2942 if (cast_type
&& card
->info
.is_multicast_different
)
2943 return card
->info
.is_multicast_different
&
2944 (card
->qdio
.no_out_queues
- 1);
2945 if (card
->qdio
.do_prio_queueing
&& (ipv
== 4)) {
2946 const u8 tos
= ip_hdr(skb
)->tos
;
2948 if (card
->qdio
.do_prio_queueing
==
2949 QETH_PRIO_Q_ING_TOS
) {
2950 if (tos
& IP_TOS_NOTIMPORTANT
)
2952 if (tos
& IP_TOS_HIGHRELIABILITY
)
2954 if (tos
& IP_TOS_HIGHTHROUGHPUT
)
2956 if (tos
& IP_TOS_LOWDELAY
)
2959 if (card
->qdio
.do_prio_queueing
==
2960 QETH_PRIO_Q_ING_PREC
)
2961 return 3 - (tos
>> 6);
2962 } else if (card
->qdio
.do_prio_queueing
&& (ipv
== 6)) {
2965 return card
->qdio
.default_out_queue
;
2966 case 1: /* fallthrough for single-out-queue 1920-device */
2968 return card
->qdio
.default_out_queue
;
2971 EXPORT_SYMBOL_GPL(qeth_get_priority_queue
);
2973 int qeth_get_elements_no(struct qeth_card
*card
, void *hdr
,
2974 struct sk_buff
*skb
, int elems
)
2976 int elements_needed
= 0;
2978 if (skb_shinfo(skb
)->nr_frags
> 0)
2979 elements_needed
= (skb_shinfo(skb
)->nr_frags
+ 1);
2980 if (elements_needed
== 0)
2981 elements_needed
= 1 + (((((unsigned long) skb
->data
) %
2982 PAGE_SIZE
) + skb
->len
) >> PAGE_SHIFT
);
2983 if ((elements_needed
+ elems
) > QETH_MAX_BUFFER_ELEMENTS(card
)) {
2984 QETH_DBF_MESSAGE(2, "Invalid size of IP packet "
2985 "(Number=%d / Length=%d). Discarded.\n",
2986 (elements_needed
+elems
), skb
->len
);
2989 return elements_needed
;
2991 EXPORT_SYMBOL_GPL(qeth_get_elements_no
);
2993 static inline void __qeth_fill_buffer(struct sk_buff
*skb
,
2994 struct qdio_buffer
*buffer
, int is_tso
, int *next_element_to_fill
,
2997 int length
= skb
->len
;
3003 element
= *next_element_to_fill
;
3005 first_lap
= (is_tso
== 0 ? 1 : 0);
3008 data
= skb
->data
+ offset
;
3013 while (length
> 0) {
3014 /* length_here is the remaining amount of data in this page */
3015 length_here
= PAGE_SIZE
- ((unsigned long) data
% PAGE_SIZE
);
3016 if (length
< length_here
)
3017 length_here
= length
;
3019 buffer
->element
[element
].addr
= data
;
3020 buffer
->element
[element
].length
= length_here
;
3021 length
-= length_here
;
3024 buffer
->element
[element
].flags
= 0;
3026 buffer
->element
[element
].flags
=
3027 SBAL_FLAGS_LAST_FRAG
;
3030 buffer
->element
[element
].flags
=
3031 SBAL_FLAGS_FIRST_FRAG
;
3033 buffer
->element
[element
].flags
=
3034 SBAL_FLAGS_MIDDLE_FRAG
;
3036 data
+= length_here
;
3040 *next_element_to_fill
= element
;
3043 static inline int qeth_fill_buffer(struct qeth_qdio_out_q
*queue
,
3044 struct qeth_qdio_out_buffer
*buf
, struct sk_buff
*skb
,
3045 struct qeth_hdr
*hdr
, int offset
, int hd_len
)
3047 struct qdio_buffer
*buffer
;
3048 int flush_cnt
= 0, hdr_len
, large_send
= 0;
3050 buffer
= buf
->buffer
;
3051 atomic_inc(&skb
->users
);
3052 skb_queue_tail(&buf
->skb_list
, skb
);
3054 /*check first on TSO ....*/
3055 if (hdr
->hdr
.l3
.id
== QETH_HEADER_TYPE_TSO
) {
3056 int element
= buf
->next_element_to_fill
;
3058 hdr_len
= sizeof(struct qeth_hdr_tso
) +
3059 ((struct qeth_hdr_tso
*)hdr
)->ext
.dg_hdr_len
;
3060 /*fill first buffer entry only with header information */
3061 buffer
->element
[element
].addr
= skb
->data
;
3062 buffer
->element
[element
].length
= hdr_len
;
3063 buffer
->element
[element
].flags
= SBAL_FLAGS_FIRST_FRAG
;
3064 buf
->next_element_to_fill
++;
3065 skb
->data
+= hdr_len
;
3066 skb
->len
-= hdr_len
;
3071 int element
= buf
->next_element_to_fill
;
3072 buffer
->element
[element
].addr
= hdr
;
3073 buffer
->element
[element
].length
= sizeof(struct qeth_hdr
) +
3075 buffer
->element
[element
].flags
= SBAL_FLAGS_FIRST_FRAG
;
3076 buf
->is_header
[element
] = 1;
3077 buf
->next_element_to_fill
++;
3080 if (skb_shinfo(skb
)->nr_frags
== 0)
3081 __qeth_fill_buffer(skb
, buffer
, large_send
,
3082 (int *)&buf
->next_element_to_fill
, offset
);
3084 __qeth_fill_buffer_frag(skb
, buffer
, large_send
,
3085 (int *)&buf
->next_element_to_fill
);
3087 if (!queue
->do_pack
) {
3088 QETH_DBF_TEXT(TRACE
, 6, "fillbfnp");
3089 /* set state to PRIMED -> will be flushed */
3090 atomic_set(&buf
->state
, QETH_QDIO_BUF_PRIMED
);
3093 QETH_DBF_TEXT(TRACE
, 6, "fillbfpa");
3094 if (queue
->card
->options
.performance_stats
)
3095 queue
->card
->perf_stats
.skbs_sent_pack
++;
3096 if (buf
->next_element_to_fill
>=
3097 QETH_MAX_BUFFER_ELEMENTS(queue
->card
)) {
3099 * packed buffer if full -> set state PRIMED
3100 * -> will be flushed
3102 atomic_set(&buf
->state
, QETH_QDIO_BUF_PRIMED
);
3109 int qeth_do_send_packet_fast(struct qeth_card
*card
,
3110 struct qeth_qdio_out_q
*queue
, struct sk_buff
*skb
,
3111 struct qeth_hdr
*hdr
, int elements_needed
,
3112 int offset
, int hd_len
)
3114 struct qeth_qdio_out_buffer
*buffer
;
3115 struct sk_buff
*skb1
;
3116 struct qeth_skb_data
*retry_ctrl
;
3120 /* spin until we get the queue ... */
3121 while (atomic_cmpxchg(&queue
->state
, QETH_OUT_Q_UNLOCKED
,
3122 QETH_OUT_Q_LOCKED
) != QETH_OUT_Q_UNLOCKED
);
3123 /* ... now we've got the queue */
3124 index
= queue
->next_buf_to_fill
;
3125 buffer
= &queue
->bufs
[queue
->next_buf_to_fill
];
3127 * check if buffer is empty to make sure that we do not 'overtake'
3128 * ourselves and try to fill a buffer that is already primed
3130 if (atomic_read(&buffer
->state
) != QETH_QDIO_BUF_EMPTY
)
3132 queue
->next_buf_to_fill
= (queue
->next_buf_to_fill
+ 1) %
3133 QDIO_MAX_BUFFERS_PER_Q
;
3134 atomic_set(&queue
->state
, QETH_OUT_Q_UNLOCKED
);
3135 qeth_fill_buffer(queue
, buffer
, skb
, hdr
, offset
, hd_len
);
3136 qeth_flush_buffers(queue
, index
, 1);
3137 if (queue
->sync_iqdio_error
== 2) {
3138 skb1
= skb_dequeue(&buffer
->skb_list
);
3140 atomic_dec(&skb1
->users
);
3141 skb1
= skb_dequeue(&buffer
->skb_list
);
3143 retry_ctrl
= (struct qeth_skb_data
*) &skb
->cb
[16];
3144 if (retry_ctrl
->magic
!= QETH_SKB_MAGIC
) {
3145 retry_ctrl
->magic
= QETH_SKB_MAGIC
;
3146 retry_ctrl
->count
= 0;
3148 if (retry_ctrl
->count
< QETH_SIGA_CC2_RETRIES
) {
3149 retry_ctrl
->count
++;
3150 rc
= dev_queue_xmit(skb
);
3152 dev_kfree_skb_any(skb
);
3153 QETH_DBF_TEXT(QERR
, 2, "qrdrop");
3158 atomic_set(&queue
->state
, QETH_OUT_Q_UNLOCKED
);
3161 EXPORT_SYMBOL_GPL(qeth_do_send_packet_fast
);
3163 int qeth_do_send_packet(struct qeth_card
*card
, struct qeth_qdio_out_q
*queue
,
3164 struct sk_buff
*skb
, struct qeth_hdr
*hdr
,
3165 int elements_needed
)
3167 struct qeth_qdio_out_buffer
*buffer
;
3169 int flush_count
= 0;
3174 /* spin until we get the queue ... */
3175 while (atomic_cmpxchg(&queue
->state
, QETH_OUT_Q_UNLOCKED
,
3176 QETH_OUT_Q_LOCKED
) != QETH_OUT_Q_UNLOCKED
);
3177 start_index
= queue
->next_buf_to_fill
;
3178 buffer
= &queue
->bufs
[queue
->next_buf_to_fill
];
3180 * check if buffer is empty to make sure that we do not 'overtake'
3181 * ourselves and try to fill a buffer that is already primed
3183 if (atomic_read(&buffer
->state
) != QETH_QDIO_BUF_EMPTY
) {
3184 atomic_set(&queue
->state
, QETH_OUT_Q_UNLOCKED
);
3187 /* check if we need to switch packing state of this queue */
3188 qeth_switch_to_packing_if_needed(queue
);
3189 if (queue
->do_pack
) {
3191 /* does packet fit in current buffer? */
3192 if ((QETH_MAX_BUFFER_ELEMENTS(card
) -
3193 buffer
->next_element_to_fill
) < elements_needed
) {
3194 /* ... no -> set state PRIMED */
3195 atomic_set(&buffer
->state
, QETH_QDIO_BUF_PRIMED
);
3197 queue
->next_buf_to_fill
=
3198 (queue
->next_buf_to_fill
+ 1) %
3199 QDIO_MAX_BUFFERS_PER_Q
;
3200 buffer
= &queue
->bufs
[queue
->next_buf_to_fill
];
3201 /* we did a step forward, so check buffer state
3203 if (atomic_read(&buffer
->state
) !=
3204 QETH_QDIO_BUF_EMPTY
) {
3205 qeth_flush_buffers(queue
, start_index
,
3207 atomic_set(&queue
->state
,
3208 QETH_OUT_Q_UNLOCKED
);
3213 tmp
= qeth_fill_buffer(queue
, buffer
, skb
, hdr
, -1, 0);
3214 queue
->next_buf_to_fill
= (queue
->next_buf_to_fill
+ tmp
) %
3215 QDIO_MAX_BUFFERS_PER_Q
;
3218 qeth_flush_buffers(queue
, start_index
, flush_count
);
3219 else if (!atomic_read(&queue
->set_pci_flags_count
))
3220 atomic_xchg(&queue
->state
, QETH_OUT_Q_LOCKED_FLUSH
);
3222 * queue->state will go from LOCKED -> UNLOCKED or from
3223 * LOCKED_FLUSH -> LOCKED if output_handler wanted to 'notify' us
3224 * (switch packing state or flush buffer to get another pci flag out).
3225 * In that case we will enter this loop
3227 while (atomic_dec_return(&queue
->state
)) {
3229 start_index
= queue
->next_buf_to_fill
;
3230 /* check if we can go back to non-packing state */
3231 flush_count
+= qeth_switch_to_nonpacking_if_needed(queue
);
3233 * check if we need to flush a packing buffer to get a pci
3234 * flag out on the queue
3236 if (!flush_count
&& !atomic_read(&queue
->set_pci_flags_count
))
3237 flush_count
+= qeth_flush_buffers_on_no_pci(queue
);
3239 qeth_flush_buffers(queue
, start_index
, flush_count
);
3241 /* at this point the queue is UNLOCKED again */
3242 if (queue
->card
->options
.performance_stats
&& do_pack
)
3243 queue
->card
->perf_stats
.bufs_sent_pack
+= flush_count
;
3247 EXPORT_SYMBOL_GPL(qeth_do_send_packet
);
3249 static int qeth_setadp_promisc_mode_cb(struct qeth_card
*card
,
3250 struct qeth_reply
*reply
, unsigned long data
)
3252 struct qeth_ipa_cmd
*cmd
;
3253 struct qeth_ipacmd_setadpparms
*setparms
;
3255 QETH_DBF_TEXT(TRACE
, 4, "prmadpcb");
3257 cmd
= (struct qeth_ipa_cmd
*) data
;
3258 setparms
= &(cmd
->data
.setadapterparms
);
3260 qeth_default_setadapterparms_cb(card
, reply
, (unsigned long)cmd
);
3261 if (cmd
->hdr
.return_code
) {
3262 QETH_DBF_TEXT_(TRACE
, 4, "prmrc%2.2x", cmd
->hdr
.return_code
);
3263 setparms
->data
.mode
= SET_PROMISC_MODE_OFF
;
3265 card
->info
.promisc_mode
= setparms
->data
.mode
;
3269 void qeth_setadp_promisc_mode(struct qeth_card
*card
)
3271 enum qeth_ipa_promisc_modes mode
;
3272 struct net_device
*dev
= card
->dev
;
3273 struct qeth_cmd_buffer
*iob
;
3274 struct qeth_ipa_cmd
*cmd
;
3276 QETH_DBF_TEXT(TRACE
, 4, "setprom");
3278 if (((dev
->flags
& IFF_PROMISC
) &&
3279 (card
->info
.promisc_mode
== SET_PROMISC_MODE_ON
)) ||
3280 (!(dev
->flags
& IFF_PROMISC
) &&
3281 (card
->info
.promisc_mode
== SET_PROMISC_MODE_OFF
)))
3283 mode
= SET_PROMISC_MODE_OFF
;
3284 if (dev
->flags
& IFF_PROMISC
)
3285 mode
= SET_PROMISC_MODE_ON
;
3286 QETH_DBF_TEXT_(TRACE
, 4, "mode:%x", mode
);
3288 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_SET_PROMISC_MODE
,
3289 sizeof(struct qeth_ipacmd_setadpparms
));
3290 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+ IPA_PDU_HEADER_SIZE
);
3291 cmd
->data
.setadapterparms
.data
.mode
= mode
;
3292 qeth_send_ipa_cmd(card
, iob
, qeth_setadp_promisc_mode_cb
, NULL
);
3294 EXPORT_SYMBOL_GPL(qeth_setadp_promisc_mode
);
3296 int qeth_change_mtu(struct net_device
*dev
, int new_mtu
)
3298 struct qeth_card
*card
;
3301 card
= dev
->ml_priv
;
3303 QETH_DBF_TEXT(TRACE
, 4, "chgmtu");
3304 sprintf(dbf_text
, "%8x", new_mtu
);
3305 QETH_DBF_TEXT(TRACE
, 4, dbf_text
);
3309 if (new_mtu
> 65535)
3311 if ((!qeth_is_supported(card
, IPA_IP_FRAGMENTATION
)) &&
3312 (!qeth_mtu_is_valid(card
, new_mtu
)))
3317 EXPORT_SYMBOL_GPL(qeth_change_mtu
);
3319 struct net_device_stats
*qeth_get_stats(struct net_device
*dev
)
3321 struct qeth_card
*card
;
3323 card
= dev
->ml_priv
;
3325 QETH_DBF_TEXT(TRACE
, 5, "getstat");
3327 return &card
->stats
;
3329 EXPORT_SYMBOL_GPL(qeth_get_stats
);
3331 static int qeth_setadpparms_change_macaddr_cb(struct qeth_card
*card
,
3332 struct qeth_reply
*reply
, unsigned long data
)
3334 struct qeth_ipa_cmd
*cmd
;
3336 QETH_DBF_TEXT(TRACE
, 4, "chgmaccb");
3338 cmd
= (struct qeth_ipa_cmd
*) data
;
3339 if (!card
->options
.layer2
||
3340 !(card
->info
.mac_bits
& QETH_LAYER2_MAC_READ
)) {
3341 memcpy(card
->dev
->dev_addr
,
3342 &cmd
->data
.setadapterparms
.data
.change_addr
.addr
,
3344 card
->info
.mac_bits
|= QETH_LAYER2_MAC_READ
;
3346 qeth_default_setadapterparms_cb(card
, reply
, (unsigned long) cmd
);
3350 int qeth_setadpparms_change_macaddr(struct qeth_card
*card
)
3353 struct qeth_cmd_buffer
*iob
;
3354 struct qeth_ipa_cmd
*cmd
;
3356 QETH_DBF_TEXT(TRACE
, 4, "chgmac");
3358 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_ALTER_MAC_ADDRESS
,
3359 sizeof(struct qeth_ipacmd_setadpparms
));
3360 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
3361 cmd
->data
.setadapterparms
.data
.change_addr
.cmd
= CHANGE_ADDR_READ_MAC
;
3362 cmd
->data
.setadapterparms
.data
.change_addr
.addr_size
= OSA_ADDR_LEN
;
3363 memcpy(&cmd
->data
.setadapterparms
.data
.change_addr
.addr
,
3364 card
->dev
->dev_addr
, OSA_ADDR_LEN
);
3365 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_setadpparms_change_macaddr_cb
,
3369 EXPORT_SYMBOL_GPL(qeth_setadpparms_change_macaddr
);
3371 static int qeth_setadpparms_set_access_ctrl_cb(struct qeth_card
*card
,
3372 struct qeth_reply
*reply
, unsigned long data
)
3374 struct qeth_ipa_cmd
*cmd
;
3375 struct qeth_set_access_ctrl
*access_ctrl_req
;
3378 QETH_DBF_TEXT(TRACE
, 4, "setaccb");
3380 cmd
= (struct qeth_ipa_cmd
*) data
;
3381 access_ctrl_req
= &cmd
->data
.setadapterparms
.data
.set_access_ctrl
;
3382 QETH_DBF_TEXT_(SETUP
, 2, "setaccb");
3383 QETH_DBF_TEXT_(SETUP
, 2, "%s", card
->gdev
->dev
.kobj
.name
);
3384 QETH_DBF_TEXT_(SETUP
, 2, "rc=%d",
3385 cmd
->data
.setadapterparms
.hdr
.return_code
);
3386 switch (cmd
->data
.setadapterparms
.hdr
.return_code
) {
3387 case SET_ACCESS_CTRL_RC_SUCCESS
:
3388 case SET_ACCESS_CTRL_RC_ALREADY_NOT_ISOLATED
:
3389 case SET_ACCESS_CTRL_RC_ALREADY_ISOLATED
:
3391 card
->options
.isolation
= access_ctrl_req
->subcmd_code
;
3392 if (card
->options
.isolation
== ISOLATION_MODE_NONE
) {
3393 dev_info(&card
->gdev
->dev
,
3394 "QDIO data connection isolation is deactivated\n");
3396 dev_info(&card
->gdev
->dev
,
3397 "QDIO data connection isolation is activated\n");
3399 QETH_DBF_MESSAGE(3, "OK:SET_ACCESS_CTRL(%s, %d)==%d\n",
3400 card
->gdev
->dev
.kobj
.name
,
3401 access_ctrl_req
->subcmd_code
,
3402 cmd
->data
.setadapterparms
.hdr
.return_code
);
3406 case SET_ACCESS_CTRL_RC_NOT_SUPPORTED
:
3408 QETH_DBF_MESSAGE(3, "ERR:SET_ACCESS_CTRL(%s,%d)==%d\n",
3409 card
->gdev
->dev
.kobj
.name
,
3410 access_ctrl_req
->subcmd_code
,
3411 cmd
->data
.setadapterparms
.hdr
.return_code
);
3412 dev_err(&card
->gdev
->dev
, "Adapter does not "
3413 "support QDIO data connection isolation\n");
3415 /* ensure isolation mode is "none" */
3416 card
->options
.isolation
= ISOLATION_MODE_NONE
;
3420 case SET_ACCESS_CTRL_RC_NONE_SHARED_ADAPTER
:
3422 QETH_DBF_MESSAGE(3, "ERR:SET_ACCESS_MODE(%s,%d)==%d\n",
3423 card
->gdev
->dev
.kobj
.name
,
3424 access_ctrl_req
->subcmd_code
,
3425 cmd
->data
.setadapterparms
.hdr
.return_code
);
3426 dev_err(&card
->gdev
->dev
,
3427 "Adapter is dedicated. "
3428 "QDIO data connection isolation not supported\n");
3430 /* ensure isolation mode is "none" */
3431 card
->options
.isolation
= ISOLATION_MODE_NONE
;
3435 case SET_ACCESS_CTRL_RC_ACTIVE_CHECKSUM_OFF
:
3437 QETH_DBF_MESSAGE(3, "ERR:SET_ACCESS_MODE(%s,%d)==%d\n",
3438 card
->gdev
->dev
.kobj
.name
,
3439 access_ctrl_req
->subcmd_code
,
3440 cmd
->data
.setadapterparms
.hdr
.return_code
);
3441 dev_err(&card
->gdev
->dev
,
3442 "TSO does not permit QDIO data connection isolation\n");
3444 /* ensure isolation mode is "none" */
3445 card
->options
.isolation
= ISOLATION_MODE_NONE
;
3451 /* this should never happen */
3452 QETH_DBF_MESSAGE(3, "ERR:SET_ACCESS_MODE(%s,%d)==%d"
3454 card
->gdev
->dev
.kobj
.name
,
3455 access_ctrl_req
->subcmd_code
,
3456 cmd
->data
.setadapterparms
.hdr
.return_code
);
3458 /* ensure isolation mode is "none" */
3459 card
->options
.isolation
= ISOLATION_MODE_NONE
;
3464 qeth_default_setadapterparms_cb(card
, reply
, (unsigned long) cmd
);
3468 static int qeth_setadpparms_set_access_ctrl(struct qeth_card
*card
,
3469 enum qeth_ipa_isolation_modes isolation
)
3472 struct qeth_cmd_buffer
*iob
;
3473 struct qeth_ipa_cmd
*cmd
;
3474 struct qeth_set_access_ctrl
*access_ctrl_req
;
3476 QETH_DBF_TEXT(TRACE
, 4, "setacctl");
3478 QETH_DBF_TEXT_(SETUP
, 2, "setacctl");
3479 QETH_DBF_TEXT_(SETUP
, 2, "%s", card
->gdev
->dev
.kobj
.name
);
3481 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_SET_ACCESS_CONTROL
,
3482 sizeof(struct qeth_ipacmd_setadpparms_hdr
) +
3483 sizeof(struct qeth_set_access_ctrl
));
3484 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
3485 access_ctrl_req
= &cmd
->data
.setadapterparms
.data
.set_access_ctrl
;
3486 access_ctrl_req
->subcmd_code
= isolation
;
3488 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_setadpparms_set_access_ctrl_cb
,
3490 QETH_DBF_TEXT_(SETUP
, 2, "rc=%d", rc
);
3494 int qeth_set_access_ctrl_online(struct qeth_card
*card
)
3498 QETH_DBF_TEXT(TRACE
, 4, "setactlo");
3500 if (card
->info
.type
== QETH_CARD_TYPE_OSAE
&&
3501 qeth_adp_supported(card
, IPA_SETADP_SET_ACCESS_CONTROL
)) {
3502 rc
= qeth_setadpparms_set_access_ctrl(card
,
3503 card
->options
.isolation
);
3506 "IPA(SET_ACCESS_CTRL,%s,%d) sent failed",
3507 card
->gdev
->dev
.kobj
.name
,
3510 } else if (card
->options
.isolation
!= ISOLATION_MODE_NONE
) {
3511 card
->options
.isolation
= ISOLATION_MODE_NONE
;
3513 dev_err(&card
->gdev
->dev
, "Adapter does not "
3514 "support QDIO data connection isolation\n");
3519 EXPORT_SYMBOL_GPL(qeth_set_access_ctrl_online
);
3521 void qeth_tx_timeout(struct net_device
*dev
)
3523 struct qeth_card
*card
;
3525 QETH_DBF_TEXT(TRACE
, 4, "txtimeo");
3526 card
= dev
->ml_priv
;
3527 card
->stats
.tx_errors
++;
3528 qeth_schedule_recovery(card
);
3530 EXPORT_SYMBOL_GPL(qeth_tx_timeout
);
3532 int qeth_mdio_read(struct net_device
*dev
, int phy_id
, int regnum
)
3534 struct qeth_card
*card
= dev
->ml_priv
;
3538 case MII_BMCR
: /* Basic mode control register */
3540 if ((card
->info
.link_type
!= QETH_LINK_TYPE_GBIT_ETH
) &&
3541 (card
->info
.link_type
!= QETH_LINK_TYPE_OSN
) &&
3542 (card
->info
.link_type
!= QETH_LINK_TYPE_10GBIT_ETH
))
3543 rc
|= BMCR_SPEED100
;
3545 case MII_BMSR
: /* Basic mode status register */
3546 rc
= BMSR_ERCAP
| BMSR_ANEGCOMPLETE
| BMSR_LSTATUS
|
3547 BMSR_10HALF
| BMSR_10FULL
| BMSR_100HALF
| BMSR_100FULL
|
3550 case MII_PHYSID1
: /* PHYS ID 1 */
3551 rc
= (dev
->dev_addr
[0] << 16) | (dev
->dev_addr
[1] << 8) |
3553 rc
= (rc
>> 5) & 0xFFFF;
3555 case MII_PHYSID2
: /* PHYS ID 2 */
3556 rc
= (dev
->dev_addr
[2] << 10) & 0xFFFF;
3558 case MII_ADVERTISE
: /* Advertisement control reg */
3561 case MII_LPA
: /* Link partner ability reg */
3562 rc
= LPA_10HALF
| LPA_10FULL
| LPA_100HALF
| LPA_100FULL
|
3563 LPA_100BASE4
| LPA_LPACK
;
3565 case MII_EXPANSION
: /* Expansion register */
3567 case MII_DCOUNTER
: /* disconnect counter */
3569 case MII_FCSCOUNTER
: /* false carrier counter */
3571 case MII_NWAYTEST
: /* N-way auto-neg test register */
3573 case MII_RERRCOUNTER
: /* rx error counter */
3574 rc
= card
->stats
.rx_errors
;
3576 case MII_SREVISION
: /* silicon revision */
3578 case MII_RESV1
: /* reserved 1 */
3580 case MII_LBRERROR
: /* loopback, rx, bypass error */
3582 case MII_PHYADDR
: /* physical address */
3584 case MII_RESV2
: /* reserved 2 */
3586 case MII_TPISTATUS
: /* TPI status for 10mbps */
3588 case MII_NCONFIG
: /* network interface config */
3595 EXPORT_SYMBOL_GPL(qeth_mdio_read
);
3597 static int qeth_send_ipa_snmp_cmd(struct qeth_card
*card
,
3598 struct qeth_cmd_buffer
*iob
, int len
,
3599 int (*reply_cb
)(struct qeth_card
*, struct qeth_reply
*,
3605 QETH_DBF_TEXT(TRACE
, 4, "sendsnmp");
3607 memcpy(iob
->data
, IPA_PDU_HEADER
, IPA_PDU_HEADER_SIZE
);
3608 memcpy(QETH_IPA_CMD_DEST_ADDR(iob
->data
),
3609 &card
->token
.ulp_connection_r
, QETH_MPC_TOKEN_LENGTH
);
3610 /* adjust PDU length fields in IPA_PDU_HEADER */
3611 s1
= (u32
) IPA_PDU_HEADER_SIZE
+ len
;
3613 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob
->data
), &s1
, 2);
3614 memcpy(QETH_IPA_PDU_LEN_PDU1(iob
->data
), &s2
, 2);
3615 memcpy(QETH_IPA_PDU_LEN_PDU2(iob
->data
), &s2
, 2);
3616 memcpy(QETH_IPA_PDU_LEN_PDU3(iob
->data
), &s2
, 2);
3617 return qeth_send_control_data(card
, IPA_PDU_HEADER_SIZE
+ len
, iob
,
3618 reply_cb
, reply_param
);
3621 static int qeth_snmp_command_cb(struct qeth_card
*card
,
3622 struct qeth_reply
*reply
, unsigned long sdata
)
3624 struct qeth_ipa_cmd
*cmd
;
3625 struct qeth_arp_query_info
*qinfo
;
3626 struct qeth_snmp_cmd
*snmp
;
3627 unsigned char *data
;
3630 QETH_DBF_TEXT(TRACE
, 3, "snpcmdcb");
3632 cmd
= (struct qeth_ipa_cmd
*) sdata
;
3633 data
= (unsigned char *)((char *)cmd
- reply
->offset
);
3634 qinfo
= (struct qeth_arp_query_info
*) reply
->param
;
3635 snmp
= &cmd
->data
.setadapterparms
.data
.snmp
;
3637 if (cmd
->hdr
.return_code
) {
3638 QETH_DBF_TEXT_(TRACE
, 4, "scer1%i", cmd
->hdr
.return_code
);
3641 if (cmd
->data
.setadapterparms
.hdr
.return_code
) {
3642 cmd
->hdr
.return_code
=
3643 cmd
->data
.setadapterparms
.hdr
.return_code
;
3644 QETH_DBF_TEXT_(TRACE
, 4, "scer2%i", cmd
->hdr
.return_code
);
3647 data_len
= *((__u16
*)QETH_IPA_PDU_LEN_PDU1(data
));
3648 if (cmd
->data
.setadapterparms
.hdr
.seq_no
== 1)
3649 data_len
-= (__u16
)((char *)&snmp
->data
- (char *)cmd
);
3651 data_len
-= (__u16
)((char *)&snmp
->request
- (char *)cmd
);
3653 /* check if there is enough room in userspace */
3654 if ((qinfo
->udata_len
- qinfo
->udata_offset
) < data_len
) {
3655 QETH_DBF_TEXT_(TRACE
, 4, "scer3%i", -ENOMEM
);
3656 cmd
->hdr
.return_code
= -ENOMEM
;
3659 QETH_DBF_TEXT_(TRACE
, 4, "snore%i",
3660 cmd
->data
.setadapterparms
.hdr
.used_total
);
3661 QETH_DBF_TEXT_(TRACE
, 4, "sseqn%i",
3662 cmd
->data
.setadapterparms
.hdr
.seq_no
);
3663 /*copy entries to user buffer*/
3664 if (cmd
->data
.setadapterparms
.hdr
.seq_no
== 1) {
3665 memcpy(qinfo
->udata
+ qinfo
->udata_offset
,
3667 data_len
+ offsetof(struct qeth_snmp_cmd
, data
));
3668 qinfo
->udata_offset
+= offsetof(struct qeth_snmp_cmd
, data
);
3670 memcpy(qinfo
->udata
+ qinfo
->udata_offset
,
3671 (char *)&snmp
->request
, data_len
);
3673 qinfo
->udata_offset
+= data_len
;
3674 /* check if all replies received ... */
3675 QETH_DBF_TEXT_(TRACE
, 4, "srtot%i",
3676 cmd
->data
.setadapterparms
.hdr
.used_total
);
3677 QETH_DBF_TEXT_(TRACE
, 4, "srseq%i",
3678 cmd
->data
.setadapterparms
.hdr
.seq_no
);
3679 if (cmd
->data
.setadapterparms
.hdr
.seq_no
<
3680 cmd
->data
.setadapterparms
.hdr
.used_total
)
3685 int qeth_snmp_command(struct qeth_card
*card
, char __user
*udata
)
3687 struct qeth_cmd_buffer
*iob
;
3688 struct qeth_ipa_cmd
*cmd
;
3689 struct qeth_snmp_ureq
*ureq
;
3691 struct qeth_arp_query_info qinfo
= {0, };
3694 QETH_DBF_TEXT(TRACE
, 3, "snmpcmd");
3696 if (card
->info
.guestlan
)
3699 if ((!qeth_adp_supported(card
, IPA_SETADP_SET_SNMP_CONTROL
)) &&
3700 (!card
->options
.layer2
)) {
3703 /* skip 4 bytes (data_len struct member) to get req_len */
3704 if (copy_from_user(&req_len
, udata
+ sizeof(int), sizeof(int)))
3706 ureq
= kmalloc(req_len
+sizeof(struct qeth_snmp_ureq_hdr
), GFP_KERNEL
);
3708 QETH_DBF_TEXT(TRACE
, 2, "snmpnome");
3711 if (copy_from_user(ureq
, udata
,
3712 req_len
+ sizeof(struct qeth_snmp_ureq_hdr
))) {
3716 qinfo
.udata_len
= ureq
->hdr
.data_len
;
3717 qinfo
.udata
= kzalloc(qinfo
.udata_len
, GFP_KERNEL
);
3722 qinfo
.udata_offset
= sizeof(struct qeth_snmp_ureq_hdr
);
3724 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_SET_SNMP_CONTROL
,
3725 QETH_SNMP_SETADP_CMDLENGTH
+ req_len
);
3726 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
3727 memcpy(&cmd
->data
.setadapterparms
.data
.snmp
, &ureq
->cmd
, req_len
);
3728 rc
= qeth_send_ipa_snmp_cmd(card
, iob
, QETH_SETADP_BASE_LEN
+ req_len
,
3729 qeth_snmp_command_cb
, (void *)&qinfo
);
3731 QETH_DBF_MESSAGE(2, "SNMP command failed on %s: (0x%x)\n",
3732 QETH_CARD_IFNAME(card
), rc
);
3734 if (copy_to_user(udata
, qinfo
.udata
, qinfo
.udata_len
))
3742 EXPORT_SYMBOL_GPL(qeth_snmp_command
);
3744 static inline int qeth_get_qdio_q_format(struct qeth_card
*card
)
3746 switch (card
->info
.type
) {
3747 case QETH_CARD_TYPE_IQD
:
3754 static int qeth_qdio_establish(struct qeth_card
*card
)
3756 struct qdio_initialize init_data
;
3757 char *qib_param_field
;
3758 struct qdio_buffer
**in_sbal_ptrs
;
3759 struct qdio_buffer
**out_sbal_ptrs
;
3763 QETH_DBF_TEXT(SETUP
, 2, "qdioest");
3765 qib_param_field
= kzalloc(QDIO_MAX_BUFFERS_PER_Q
* sizeof(char),
3767 if (!qib_param_field
)
3770 qeth_create_qib_param_field(card
, qib_param_field
);
3771 qeth_create_qib_param_field_blkt(card
, qib_param_field
);
3773 in_sbal_ptrs
= kmalloc(QDIO_MAX_BUFFERS_PER_Q
* sizeof(void *),
3775 if (!in_sbal_ptrs
) {
3776 kfree(qib_param_field
);
3779 for (i
= 0; i
< QDIO_MAX_BUFFERS_PER_Q
; ++i
)
3780 in_sbal_ptrs
[i
] = (struct qdio_buffer
*)
3781 virt_to_phys(card
->qdio
.in_q
->bufs
[i
].buffer
);
3784 kmalloc(card
->qdio
.no_out_queues
* QDIO_MAX_BUFFERS_PER_Q
*
3785 sizeof(void *), GFP_KERNEL
);
3786 if (!out_sbal_ptrs
) {
3787 kfree(in_sbal_ptrs
);
3788 kfree(qib_param_field
);
3791 for (i
= 0, k
= 0; i
< card
->qdio
.no_out_queues
; ++i
)
3792 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
, ++k
) {
3793 out_sbal_ptrs
[k
] = (struct qdio_buffer
*)virt_to_phys(
3794 card
->qdio
.out_qs
[i
]->bufs
[j
].buffer
);
3797 memset(&init_data
, 0, sizeof(struct qdio_initialize
));
3798 init_data
.cdev
= CARD_DDEV(card
);
3799 init_data
.q_format
= qeth_get_qdio_q_format(card
);
3800 init_data
.qib_param_field_format
= 0;
3801 init_data
.qib_param_field
= qib_param_field
;
3802 init_data
.no_input_qs
= 1;
3803 init_data
.no_output_qs
= card
->qdio
.no_out_queues
;
3804 init_data
.input_handler
= card
->discipline
.input_handler
;
3805 init_data
.output_handler
= card
->discipline
.output_handler
;
3806 init_data
.int_parm
= (unsigned long) card
;
3807 init_data
.input_sbal_addr_array
= (void **) in_sbal_ptrs
;
3808 init_data
.output_sbal_addr_array
= (void **) out_sbal_ptrs
;
3810 if (atomic_cmpxchg(&card
->qdio
.state
, QETH_QDIO_ALLOCATED
,
3811 QETH_QDIO_ESTABLISHED
) == QETH_QDIO_ALLOCATED
) {
3812 rc
= qdio_initialize(&init_data
);
3814 atomic_set(&card
->qdio
.state
, QETH_QDIO_ALLOCATED
);
3816 kfree(out_sbal_ptrs
);
3817 kfree(in_sbal_ptrs
);
3818 kfree(qib_param_field
);
3822 static void qeth_core_free_card(struct qeth_card
*card
)
3825 QETH_DBF_TEXT(SETUP
, 2, "freecrd");
3826 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
3827 qeth_clean_channel(&card
->read
);
3828 qeth_clean_channel(&card
->write
);
3830 free_netdev(card
->dev
);
3831 kfree(card
->ip_tbd_list
);
3832 qeth_free_qdio_buffers(card
);
3833 unregister_service_level(&card
->qeth_service_level
);
3837 static struct ccw_device_id qeth_ids
[] = {
3838 {CCW_DEVICE(0x1731, 0x01), .driver_info
= QETH_CARD_TYPE_OSAE
},
3839 {CCW_DEVICE(0x1731, 0x05), .driver_info
= QETH_CARD_TYPE_IQD
},
3840 {CCW_DEVICE(0x1731, 0x06), .driver_info
= QETH_CARD_TYPE_OSN
},
3843 MODULE_DEVICE_TABLE(ccw
, qeth_ids
);
3845 static struct ccw_driver qeth_ccw_driver
= {
3848 .probe
= ccwgroup_probe_ccwdev
,
3849 .remove
= ccwgroup_remove_ccwdev
,
3852 static int qeth_core_driver_group(const char *buf
, struct device
*root_dev
,
3853 unsigned long driver_id
)
3855 return ccwgroup_create_from_string(root_dev
, driver_id
,
3856 &qeth_ccw_driver
, 3, buf
);
3859 int qeth_core_hardsetup_card(struct qeth_card
*card
)
3864 QETH_DBF_TEXT(SETUP
, 2, "hrdsetup");
3865 atomic_set(&card
->force_alloc_skb
, 0);
3868 QETH_DBF_MESSAGE(2, "%s Retrying to do IDX activates.\n",
3869 dev_name(&card
->gdev
->dev
));
3870 ccw_device_set_offline(CARD_DDEV(card
));
3871 ccw_device_set_offline(CARD_WDEV(card
));
3872 ccw_device_set_offline(CARD_RDEV(card
));
3873 rc
= ccw_device_set_online(CARD_RDEV(card
));
3876 rc
= ccw_device_set_online(CARD_WDEV(card
));
3879 rc
= ccw_device_set_online(CARD_DDEV(card
));
3882 rc
= qeth_qdio_clear_card(card
, card
->info
.type
!= QETH_CARD_TYPE_IQD
);
3884 if (rc
== -ERESTARTSYS
) {
3885 QETH_DBF_TEXT(SETUP
, 2, "break1");
3888 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
3894 qeth_init_tokens(card
);
3895 qeth_init_func_level(card
);
3896 rc
= qeth_idx_activate_channel(&card
->read
, qeth_idx_read_cb
);
3897 if (rc
== -ERESTARTSYS
) {
3898 QETH_DBF_TEXT(SETUP
, 2, "break2");
3901 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
3907 rc
= qeth_idx_activate_channel(&card
->write
, qeth_idx_write_cb
);
3908 if (rc
== -ERESTARTSYS
) {
3909 QETH_DBF_TEXT(SETUP
, 2, "break3");
3912 QETH_DBF_TEXT_(SETUP
, 2, "4err%d", rc
);
3918 rc
= qeth_mpc_initialize(card
);
3920 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
3925 dev_warn(&card
->gdev
->dev
, "The qeth device driver failed to recover "
3926 "an error on the device\n");
3927 QETH_DBF_MESSAGE(2, "%s Initialization in hardsetup failed! rc=%d\n",
3928 dev_name(&card
->gdev
->dev
), rc
);
3931 EXPORT_SYMBOL_GPL(qeth_core_hardsetup_card
);
3933 static inline int qeth_create_skb_frag(struct qdio_buffer_element
*element
,
3934 struct sk_buff
**pskb
, int offset
, int *pfrag
, int data_len
)
3936 struct page
*page
= virt_to_page(element
->addr
);
3937 if (*pskb
== NULL
) {
3938 /* the upper protocol layers assume that there is data in the
3939 * skb itself. Copy a small amount (64 bytes) to make them
3941 *pskb
= dev_alloc_skb(64 + ETH_HLEN
);
3944 skb_reserve(*pskb
, ETH_HLEN
);
3945 if (data_len
<= 64) {
3946 memcpy(skb_put(*pskb
, data_len
), element
->addr
+ offset
,
3950 memcpy(skb_put(*pskb
, 64), element
->addr
+ offset
, 64);
3951 skb_fill_page_desc(*pskb
, *pfrag
, page
, offset
+ 64,
3953 (*pskb
)->data_len
+= data_len
- 64;
3954 (*pskb
)->len
+= data_len
- 64;
3955 (*pskb
)->truesize
+= data_len
- 64;
3960 skb_fill_page_desc(*pskb
, *pfrag
, page
, offset
, data_len
);
3961 (*pskb
)->data_len
+= data_len
;
3962 (*pskb
)->len
+= data_len
;
3963 (*pskb
)->truesize
+= data_len
;
3969 struct sk_buff
*qeth_core_get_next_skb(struct qeth_card
*card
,
3970 struct qdio_buffer
*buffer
,
3971 struct qdio_buffer_element
**__element
, int *__offset
,
3972 struct qeth_hdr
**hdr
)
3974 struct qdio_buffer_element
*element
= *__element
;
3975 int offset
= *__offset
;
3976 struct sk_buff
*skb
= NULL
;
3984 /* qeth_hdr must not cross element boundaries */
3985 if (element
->length
< offset
+ sizeof(struct qeth_hdr
)) {
3986 if (qeth_is_last_sbale(element
))
3990 if (element
->length
< sizeof(struct qeth_hdr
))
3993 *hdr
= element
->addr
+ offset
;
3995 offset
+= sizeof(struct qeth_hdr
);
3996 switch ((*hdr
)->hdr
.l2
.id
) {
3997 case QETH_HEADER_TYPE_LAYER2
:
3998 skb_len
= (*hdr
)->hdr
.l2
.pkt_length
;
4000 case QETH_HEADER_TYPE_LAYER3
:
4001 skb_len
= (*hdr
)->hdr
.l3
.length
;
4002 if ((card
->info
.link_type
== QETH_LINK_TYPE_LANE_TR
) ||
4003 (card
->info
.link_type
== QETH_LINK_TYPE_HSTR
))
4006 headroom
= ETH_HLEN
;
4008 case QETH_HEADER_TYPE_OSN
:
4009 skb_len
= (*hdr
)->hdr
.osn
.pdu_length
;
4010 headroom
= sizeof(struct qeth_hdr
);
4019 if ((skb_len
>= card
->options
.rx_sg_cb
) &&
4020 (!(card
->info
.type
== QETH_CARD_TYPE_OSN
)) &&
4021 (!atomic_read(&card
->force_alloc_skb
))) {
4024 skb
= dev_alloc_skb(skb_len
+ headroom
);
4028 skb_reserve(skb
, headroom
);
4031 data_ptr
= element
->addr
+ offset
;
4033 data_len
= min(skb_len
, (int)(element
->length
- offset
));
4036 if (qeth_create_skb_frag(element
, &skb
, offset
,
4040 memcpy(skb_put(skb
, data_len
), data_ptr
,
4044 skb_len
-= data_len
;
4046 if (qeth_is_last_sbale(element
)) {
4047 QETH_DBF_TEXT(TRACE
, 4, "unexeob");
4048 QETH_DBF_TEXT_(TRACE
, 4, "%s",
4050 QETH_DBF_TEXT(QERR
, 2, "unexeob");
4051 QETH_DBF_TEXT_(QERR
, 2, "%s",
4053 QETH_DBF_HEX(MISC
, 4, buffer
, sizeof(*buffer
));
4054 dev_kfree_skb_any(skb
);
4055 card
->stats
.rx_errors
++;
4060 data_ptr
= element
->addr
;
4065 *__element
= element
;
4067 if (use_rx_sg
&& card
->options
.performance_stats
) {
4068 card
->perf_stats
.sg_skbs_rx
++;
4069 card
->perf_stats
.sg_frags_rx
+= skb_shinfo(skb
)->nr_frags
;
4073 if (net_ratelimit()) {
4074 QETH_DBF_TEXT(TRACE
, 2, "noskbmem");
4075 QETH_DBF_TEXT_(TRACE
, 2, "%s", CARD_BUS_ID(card
));
4077 card
->stats
.rx_dropped
++;
4080 EXPORT_SYMBOL_GPL(qeth_core_get_next_skb
);
4082 static void qeth_unregister_dbf_views(void)
4085 for (x
= 0; x
< QETH_DBF_INFOS
; x
++) {
4086 debug_unregister(qeth_dbf
[x
].id
);
4087 qeth_dbf
[x
].id
= NULL
;
4091 void qeth_dbf_longtext(enum qeth_dbf_names dbf_nix
, int level
, char *fmt
, ...)
4093 char dbf_txt_buf
[32];
4096 if (level
> (qeth_dbf
[dbf_nix
].id
)->level
)
4098 va_start(args
, fmt
);
4099 vsnprintf(dbf_txt_buf
, sizeof(dbf_txt_buf
), fmt
, args
);
4101 debug_text_event(qeth_dbf
[dbf_nix
].id
, level
, dbf_txt_buf
);
4103 EXPORT_SYMBOL_GPL(qeth_dbf_longtext
);
4105 static int qeth_register_dbf_views(void)
4110 for (x
= 0; x
< QETH_DBF_INFOS
; x
++) {
4111 /* register the areas */
4112 qeth_dbf
[x
].id
= debug_register(qeth_dbf
[x
].name
,
4116 if (qeth_dbf
[x
].id
== NULL
) {
4117 qeth_unregister_dbf_views();
4121 /* register a view */
4122 ret
= debug_register_view(qeth_dbf
[x
].id
, qeth_dbf
[x
].view
);
4124 qeth_unregister_dbf_views();
4128 /* set a passing level */
4129 debug_set_level(qeth_dbf
[x
].id
, qeth_dbf
[x
].level
);
4135 int qeth_core_load_discipline(struct qeth_card
*card
,
4136 enum qeth_discipline_id discipline
)
4139 switch (discipline
) {
4140 case QETH_DISCIPLINE_LAYER3
:
4141 card
->discipline
.ccwgdriver
= try_then_request_module(
4142 symbol_get(qeth_l3_ccwgroup_driver
),
4145 case QETH_DISCIPLINE_LAYER2
:
4146 card
->discipline
.ccwgdriver
= try_then_request_module(
4147 symbol_get(qeth_l2_ccwgroup_driver
),
4151 if (!card
->discipline
.ccwgdriver
) {
4152 dev_err(&card
->gdev
->dev
, "There is no kernel module to "
4153 "support discipline %d\n", discipline
);
4159 void qeth_core_free_discipline(struct qeth_card
*card
)
4161 if (card
->options
.layer2
)
4162 symbol_put(qeth_l2_ccwgroup_driver
);
4164 symbol_put(qeth_l3_ccwgroup_driver
);
4165 card
->discipline
.ccwgdriver
= NULL
;
4168 static void qeth_determine_capabilities(struct qeth_card
*card
)
4174 QETH_DBF_TEXT(SETUP
, 2, "detcapab");
4175 rc
= ccw_device_set_online(CARD_DDEV(card
));
4177 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
4182 rc
= qeth_read_conf_data(card
, (void **) &prcd
, &length
);
4184 QETH_DBF_MESSAGE(2, "%s qeth_read_conf_data returned %i\n",
4185 dev_name(&card
->gdev
->dev
), rc
);
4186 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
4189 qeth_configure_unitaddr(card
, prcd
);
4190 qeth_configure_blkt_default(card
, prcd
);
4193 rc
= qdio_get_ssqd_desc(CARD_DDEV(card
), &card
->ssqd
);
4195 QETH_DBF_TEXT_(SETUP
, 2, "6err%d", rc
);
4198 ccw_device_set_offline(CARD_DDEV(card
));
4203 static int qeth_core_probe_device(struct ccwgroup_device
*gdev
)
4205 struct qeth_card
*card
;
4208 unsigned long flags
;
4210 QETH_DBF_TEXT(SETUP
, 2, "probedev");
4213 if (!get_device(dev
))
4216 QETH_DBF_TEXT_(SETUP
, 2, "%s", dev_name(&gdev
->dev
));
4218 card
= qeth_alloc_card();
4220 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", -ENOMEM
);
4224 card
->read
.ccwdev
= gdev
->cdev
[0];
4225 card
->write
.ccwdev
= gdev
->cdev
[1];
4226 card
->data
.ccwdev
= gdev
->cdev
[2];
4227 dev_set_drvdata(&gdev
->dev
, card
);
4229 gdev
->cdev
[0]->handler
= qeth_irq
;
4230 gdev
->cdev
[1]->handler
= qeth_irq
;
4231 gdev
->cdev
[2]->handler
= qeth_irq
;
4233 rc
= qeth_determine_card_type(card
);
4235 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
4238 rc
= qeth_setup_card(card
);
4240 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
4244 if (card
->info
.type
== QETH_CARD_TYPE_OSN
) {
4245 rc
= qeth_core_create_osn_attributes(dev
);
4248 rc
= qeth_core_load_discipline(card
, QETH_DISCIPLINE_LAYER2
);
4250 qeth_core_remove_osn_attributes(dev
);
4253 rc
= card
->discipline
.ccwgdriver
->probe(card
->gdev
);
4255 qeth_core_free_discipline(card
);
4256 qeth_core_remove_osn_attributes(dev
);
4260 rc
= qeth_core_create_device_attributes(dev
);
4265 write_lock_irqsave(&qeth_core_card_list
.rwlock
, flags
);
4266 list_add_tail(&card
->list
, &qeth_core_card_list
.list
);
4267 write_unlock_irqrestore(&qeth_core_card_list
.rwlock
, flags
);
4269 qeth_determine_capabilities(card
);
4273 qeth_core_free_card(card
);
4279 static void qeth_core_remove_device(struct ccwgroup_device
*gdev
)
4281 unsigned long flags
;
4282 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
4284 QETH_DBF_TEXT(SETUP
, 2, "removedv");
4285 if (card
->discipline
.ccwgdriver
) {
4286 card
->discipline
.ccwgdriver
->remove(gdev
);
4287 qeth_core_free_discipline(card
);
4290 if (card
->info
.type
== QETH_CARD_TYPE_OSN
) {
4291 qeth_core_remove_osn_attributes(&gdev
->dev
);
4293 qeth_core_remove_device_attributes(&gdev
->dev
);
4295 write_lock_irqsave(&qeth_core_card_list
.rwlock
, flags
);
4296 list_del(&card
->list
);
4297 write_unlock_irqrestore(&qeth_core_card_list
.rwlock
, flags
);
4298 qeth_core_free_card(card
);
4299 dev_set_drvdata(&gdev
->dev
, NULL
);
4300 put_device(&gdev
->dev
);
4304 static int qeth_core_set_online(struct ccwgroup_device
*gdev
)
4306 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
4310 if (!card
->discipline
.ccwgdriver
) {
4311 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
4312 def_discipline
= QETH_DISCIPLINE_LAYER3
;
4314 def_discipline
= QETH_DISCIPLINE_LAYER2
;
4315 rc
= qeth_core_load_discipline(card
, def_discipline
);
4318 rc
= card
->discipline
.ccwgdriver
->probe(card
->gdev
);
4322 rc
= card
->discipline
.ccwgdriver
->set_online(gdev
);
4327 static int qeth_core_set_offline(struct ccwgroup_device
*gdev
)
4329 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
4330 return card
->discipline
.ccwgdriver
->set_offline(gdev
);
4333 static void qeth_core_shutdown(struct ccwgroup_device
*gdev
)
4335 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
4336 if (card
->discipline
.ccwgdriver
&&
4337 card
->discipline
.ccwgdriver
->shutdown
)
4338 card
->discipline
.ccwgdriver
->shutdown(gdev
);
4341 static int qeth_core_prepare(struct ccwgroup_device
*gdev
)
4343 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
4344 if (card
->discipline
.ccwgdriver
&&
4345 card
->discipline
.ccwgdriver
->prepare
)
4346 return card
->discipline
.ccwgdriver
->prepare(gdev
);
4350 static void qeth_core_complete(struct ccwgroup_device
*gdev
)
4352 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
4353 if (card
->discipline
.ccwgdriver
&&
4354 card
->discipline
.ccwgdriver
->complete
)
4355 card
->discipline
.ccwgdriver
->complete(gdev
);
4358 static int qeth_core_freeze(struct ccwgroup_device
*gdev
)
4360 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
4361 if (card
->discipline
.ccwgdriver
&&
4362 card
->discipline
.ccwgdriver
->freeze
)
4363 return card
->discipline
.ccwgdriver
->freeze(gdev
);
4367 static int qeth_core_thaw(struct ccwgroup_device
*gdev
)
4369 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
4370 if (card
->discipline
.ccwgdriver
&&
4371 card
->discipline
.ccwgdriver
->thaw
)
4372 return card
->discipline
.ccwgdriver
->thaw(gdev
);
4376 static int qeth_core_restore(struct ccwgroup_device
*gdev
)
4378 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
4379 if (card
->discipline
.ccwgdriver
&&
4380 card
->discipline
.ccwgdriver
->restore
)
4381 return card
->discipline
.ccwgdriver
->restore(gdev
);
4385 static struct ccwgroup_driver qeth_core_ccwgroup_driver
= {
4386 .owner
= THIS_MODULE
,
4388 .driver_id
= 0xD8C5E3C8,
4389 .probe
= qeth_core_probe_device
,
4390 .remove
= qeth_core_remove_device
,
4391 .set_online
= qeth_core_set_online
,
4392 .set_offline
= qeth_core_set_offline
,
4393 .shutdown
= qeth_core_shutdown
,
4394 .prepare
= qeth_core_prepare
,
4395 .complete
= qeth_core_complete
,
4396 .freeze
= qeth_core_freeze
,
4397 .thaw
= qeth_core_thaw
,
4398 .restore
= qeth_core_restore
,
4402 qeth_core_driver_group_store(struct device_driver
*ddrv
, const char *buf
,
4406 err
= qeth_core_driver_group(buf
, qeth_core_root_dev
,
4407 qeth_core_ccwgroup_driver
.driver_id
);
4414 static DRIVER_ATTR(group
, 0200, NULL
, qeth_core_driver_group_store
);
4417 const char str
[ETH_GSTRING_LEN
];
4418 } qeth_ethtool_stats_keys
[] = {
4423 {"tx skbs no packing"},
4424 {"tx buffers no packing"},
4425 {"tx skbs packing"},
4426 {"tx buffers packing"},
4429 /* 10 */{"rx sg skbs"},
4431 {"rx sg page allocs"},
4432 {"tx large kbytes"},
4434 {"tx pk state ch n->p"},
4435 {"tx pk state ch p->n"},
4436 {"tx pk watermark low"},
4437 {"tx pk watermark high"},
4438 {"queue 0 buffer usage"},
4439 /* 20 */{"queue 1 buffer usage"},
4440 {"queue 2 buffer usage"},
4441 {"queue 3 buffer usage"},
4442 {"rx handler time"},
4443 {"rx handler count"},
4444 {"rx do_QDIO time"},
4445 {"rx do_QDIO count"},
4446 {"tx handler time"},
4447 {"tx handler count"},
4449 /* 30 */{"tx count"},
4450 {"tx do_QDIO time"},
4451 {"tx do_QDIO count"},
4456 int qeth_core_get_sset_count(struct net_device
*dev
, int stringset
)
4458 switch (stringset
) {
4460 return (sizeof(qeth_ethtool_stats_keys
) / ETH_GSTRING_LEN
);
4465 EXPORT_SYMBOL_GPL(qeth_core_get_sset_count
);
4467 void qeth_core_get_ethtool_stats(struct net_device
*dev
,
4468 struct ethtool_stats
*stats
, u64
*data
)
4470 struct qeth_card
*card
= dev
->ml_priv
;
4471 data
[0] = card
->stats
.rx_packets
-
4472 card
->perf_stats
.initial_rx_packets
;
4473 data
[1] = card
->perf_stats
.bufs_rec
;
4474 data
[2] = card
->stats
.tx_packets
-
4475 card
->perf_stats
.initial_tx_packets
;
4476 data
[3] = card
->perf_stats
.bufs_sent
;
4477 data
[4] = card
->stats
.tx_packets
- card
->perf_stats
.initial_tx_packets
4478 - card
->perf_stats
.skbs_sent_pack
;
4479 data
[5] = card
->perf_stats
.bufs_sent
- card
->perf_stats
.bufs_sent_pack
;
4480 data
[6] = card
->perf_stats
.skbs_sent_pack
;
4481 data
[7] = card
->perf_stats
.bufs_sent_pack
;
4482 data
[8] = card
->perf_stats
.sg_skbs_sent
;
4483 data
[9] = card
->perf_stats
.sg_frags_sent
;
4484 data
[10] = card
->perf_stats
.sg_skbs_rx
;
4485 data
[11] = card
->perf_stats
.sg_frags_rx
;
4486 data
[12] = card
->perf_stats
.sg_alloc_page_rx
;
4487 data
[13] = (card
->perf_stats
.large_send_bytes
>> 10);
4488 data
[14] = card
->perf_stats
.large_send_cnt
;
4489 data
[15] = card
->perf_stats
.sc_dp_p
;
4490 data
[16] = card
->perf_stats
.sc_p_dp
;
4491 data
[17] = QETH_LOW_WATERMARK_PACK
;
4492 data
[18] = QETH_HIGH_WATERMARK_PACK
;
4493 data
[19] = atomic_read(&card
->qdio
.out_qs
[0]->used_buffers
);
4494 data
[20] = (card
->qdio
.no_out_queues
> 1) ?
4495 atomic_read(&card
->qdio
.out_qs
[1]->used_buffers
) : 0;
4496 data
[21] = (card
->qdio
.no_out_queues
> 2) ?
4497 atomic_read(&card
->qdio
.out_qs
[2]->used_buffers
) : 0;
4498 data
[22] = (card
->qdio
.no_out_queues
> 3) ?
4499 atomic_read(&card
->qdio
.out_qs
[3]->used_buffers
) : 0;
4500 data
[23] = card
->perf_stats
.inbound_time
;
4501 data
[24] = card
->perf_stats
.inbound_cnt
;
4502 data
[25] = card
->perf_stats
.inbound_do_qdio_time
;
4503 data
[26] = card
->perf_stats
.inbound_do_qdio_cnt
;
4504 data
[27] = card
->perf_stats
.outbound_handler_time
;
4505 data
[28] = card
->perf_stats
.outbound_handler_cnt
;
4506 data
[29] = card
->perf_stats
.outbound_time
;
4507 data
[30] = card
->perf_stats
.outbound_cnt
;
4508 data
[31] = card
->perf_stats
.outbound_do_qdio_time
;
4509 data
[32] = card
->perf_stats
.outbound_do_qdio_cnt
;
4510 data
[33] = card
->perf_stats
.tx_csum
;
4511 data
[34] = card
->perf_stats
.tx_lin
;
4513 EXPORT_SYMBOL_GPL(qeth_core_get_ethtool_stats
);
4515 void qeth_core_get_strings(struct net_device
*dev
, u32 stringset
, u8
*data
)
4517 switch (stringset
) {
4519 memcpy(data
, &qeth_ethtool_stats_keys
,
4520 sizeof(qeth_ethtool_stats_keys
));
4527 EXPORT_SYMBOL_GPL(qeth_core_get_strings
);
4529 void qeth_core_get_drvinfo(struct net_device
*dev
,
4530 struct ethtool_drvinfo
*info
)
4532 struct qeth_card
*card
= dev
->ml_priv
;
4533 if (card
->options
.layer2
)
4534 strcpy(info
->driver
, "qeth_l2");
4536 strcpy(info
->driver
, "qeth_l3");
4538 strcpy(info
->version
, "1.0");
4539 strcpy(info
->fw_version
, card
->info
.mcl_level
);
4540 sprintf(info
->bus_info
, "%s/%s/%s",
4543 CARD_DDEV_ID(card
));
4545 EXPORT_SYMBOL_GPL(qeth_core_get_drvinfo
);
4547 int qeth_core_ethtool_get_settings(struct net_device
*netdev
,
4548 struct ethtool_cmd
*ecmd
)
4550 struct qeth_card
*card
= netdev
->ml_priv
;
4551 enum qeth_link_types link_type
;
4553 if ((card
->info
.type
== QETH_CARD_TYPE_IQD
) || (card
->info
.guestlan
))
4554 link_type
= QETH_LINK_TYPE_10GBIT_ETH
;
4556 link_type
= card
->info
.link_type
;
4558 ecmd
->transceiver
= XCVR_INTERNAL
;
4559 ecmd
->supported
= SUPPORTED_Autoneg
;
4560 ecmd
->advertising
= ADVERTISED_Autoneg
;
4561 ecmd
->duplex
= DUPLEX_FULL
;
4562 ecmd
->autoneg
= AUTONEG_ENABLE
;
4564 switch (link_type
) {
4565 case QETH_LINK_TYPE_FAST_ETH
:
4566 case QETH_LINK_TYPE_LANE_ETH100
:
4567 ecmd
->supported
|= SUPPORTED_10baseT_Half
|
4568 SUPPORTED_10baseT_Full
|
4569 SUPPORTED_100baseT_Half
|
4570 SUPPORTED_100baseT_Full
|
4572 ecmd
->advertising
|= ADVERTISED_10baseT_Half
|
4573 ADVERTISED_10baseT_Full
|
4574 ADVERTISED_100baseT_Half
|
4575 ADVERTISED_100baseT_Full
|
4577 ecmd
->speed
= SPEED_100
;
4578 ecmd
->port
= PORT_TP
;
4581 case QETH_LINK_TYPE_GBIT_ETH
:
4582 case QETH_LINK_TYPE_LANE_ETH1000
:
4583 ecmd
->supported
|= SUPPORTED_10baseT_Half
|
4584 SUPPORTED_10baseT_Full
|
4585 SUPPORTED_100baseT_Half
|
4586 SUPPORTED_100baseT_Full
|
4587 SUPPORTED_1000baseT_Half
|
4588 SUPPORTED_1000baseT_Full
|
4590 ecmd
->advertising
|= ADVERTISED_10baseT_Half
|
4591 ADVERTISED_10baseT_Full
|
4592 ADVERTISED_100baseT_Half
|
4593 ADVERTISED_100baseT_Full
|
4594 ADVERTISED_1000baseT_Half
|
4595 ADVERTISED_1000baseT_Full
|
4597 ecmd
->speed
= SPEED_1000
;
4598 ecmd
->port
= PORT_FIBRE
;
4601 case QETH_LINK_TYPE_10GBIT_ETH
:
4602 ecmd
->supported
|= SUPPORTED_10baseT_Half
|
4603 SUPPORTED_10baseT_Full
|
4604 SUPPORTED_100baseT_Half
|
4605 SUPPORTED_100baseT_Full
|
4606 SUPPORTED_1000baseT_Half
|
4607 SUPPORTED_1000baseT_Full
|
4608 SUPPORTED_10000baseT_Full
|
4610 ecmd
->advertising
|= ADVERTISED_10baseT_Half
|
4611 ADVERTISED_10baseT_Full
|
4612 ADVERTISED_100baseT_Half
|
4613 ADVERTISED_100baseT_Full
|
4614 ADVERTISED_1000baseT_Half
|
4615 ADVERTISED_1000baseT_Full
|
4616 ADVERTISED_10000baseT_Full
|
4618 ecmd
->speed
= SPEED_10000
;
4619 ecmd
->port
= PORT_FIBRE
;
4623 ecmd
->supported
|= SUPPORTED_10baseT_Half
|
4624 SUPPORTED_10baseT_Full
|
4626 ecmd
->advertising
|= ADVERTISED_10baseT_Half
|
4627 ADVERTISED_10baseT_Full
|
4629 ecmd
->speed
= SPEED_10
;
4630 ecmd
->port
= PORT_TP
;
4635 EXPORT_SYMBOL_GPL(qeth_core_ethtool_get_settings
);
4637 static int __init
qeth_core_init(void)
4641 pr_info("loading core functions\n");
4642 INIT_LIST_HEAD(&qeth_core_card_list
.list
);
4643 rwlock_init(&qeth_core_card_list
.rwlock
);
4645 rc
= qeth_register_dbf_views();
4648 rc
= ccw_driver_register(&qeth_ccw_driver
);
4651 rc
= ccwgroup_driver_register(&qeth_core_ccwgroup_driver
);
4654 rc
= driver_create_file(&qeth_core_ccwgroup_driver
.driver
,
4655 &driver_attr_group
);
4658 qeth_core_root_dev
= root_device_register("qeth");
4659 rc
= IS_ERR(qeth_core_root_dev
) ? PTR_ERR(qeth_core_root_dev
) : 0;
4663 qeth_core_header_cache
= kmem_cache_create("qeth_hdr",
4664 sizeof(struct qeth_hdr
) + ETH_HLEN
, 64, 0, NULL
);
4665 if (!qeth_core_header_cache
) {
4672 root_device_unregister(qeth_core_root_dev
);
4674 driver_remove_file(&qeth_core_ccwgroup_driver
.driver
,
4675 &driver_attr_group
);
4677 ccwgroup_driver_unregister(&qeth_core_ccwgroup_driver
);
4679 ccw_driver_unregister(&qeth_ccw_driver
);
4681 QETH_DBF_MESSAGE(2, "Initialization failed with code %d\n", rc
);
4682 qeth_unregister_dbf_views();
4684 pr_err("Initializing the qeth device driver failed\n");
4688 static void __exit
qeth_core_exit(void)
4690 root_device_unregister(qeth_core_root_dev
);
4691 driver_remove_file(&qeth_core_ccwgroup_driver
.driver
,
4692 &driver_attr_group
);
4693 ccwgroup_driver_unregister(&qeth_core_ccwgroup_driver
);
4694 ccw_driver_unregister(&qeth_ccw_driver
);
4695 kmem_cache_destroy(qeth_core_header_cache
);
4696 qeth_unregister_dbf_views();
4697 pr_info("core functions removed\n");
4700 module_init(qeth_core_init
);
4701 module_exit(qeth_core_exit
);
4702 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
4703 MODULE_DESCRIPTION("qeth core functions");
4704 MODULE_LICENSE("GPL");