2 * Copyright IBM Corp. 2007, 2009
3 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
4 * Frank Pavlic <fpavlic@de.ibm.com>,
5 * Thomas Spatzier <tspat@de.ibm.com>,
6 * Frank Blaschka <frank.blaschka@de.ibm.com>
9 #define KMSG_COMPONENT "qeth"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/module.h>
13 #include <linux/moduleparam.h>
14 #include <linux/string.h>
15 #include <linux/errno.h>
16 #include <linux/kernel.h>
18 #include <linux/tcp.h>
19 #include <linux/mii.h>
20 #include <linux/kthread.h>
21 #include <linux/slab.h>
22 #include <net/iucv/af_iucv.h>
24 #include <asm/ebcdic.h>
26 #include <asm/sysinfo.h>
27 #include <asm/compat.h>
29 #include "qeth_core.h"
31 struct qeth_dbf_info qeth_dbf
[QETH_DBF_INFOS
] = {
32 /* define dbf - Name, Pages, Areas, Maxlen, Level, View, Handle */
34 [QETH_DBF_SETUP
] = {"qeth_setup",
35 8, 1, 8, 5, &debug_hex_ascii_view
, NULL
},
36 [QETH_DBF_MSG
] = {"qeth_msg",
37 8, 1, 128, 3, &debug_sprintf_view
, NULL
},
38 [QETH_DBF_CTRL
] = {"qeth_control",
39 8, 1, QETH_DBF_CTRL_LEN
, 5, &debug_hex_ascii_view
, NULL
},
41 EXPORT_SYMBOL_GPL(qeth_dbf
);
43 struct qeth_card_list_struct qeth_core_card_list
;
44 EXPORT_SYMBOL_GPL(qeth_core_card_list
);
45 struct kmem_cache
*qeth_core_header_cache
;
46 EXPORT_SYMBOL_GPL(qeth_core_header_cache
);
47 static struct kmem_cache
*qeth_qdio_outbuf_cache
;
49 static struct device
*qeth_core_root_dev
;
50 static unsigned int known_devices
[][6] = QETH_MODELLIST_ARRAY
;
51 static struct lock_class_key qdio_out_skb_queue_key
;
52 static struct mutex qeth_mod_mutex
;
54 static void qeth_send_control_data_cb(struct qeth_channel
*,
55 struct qeth_cmd_buffer
*);
56 static int qeth_issue_next_read(struct qeth_card
*);
57 static struct qeth_cmd_buffer
*qeth_get_buffer(struct qeth_channel
*);
58 static void qeth_setup_ccw(struct qeth_channel
*, unsigned char *, __u32
);
59 static void qeth_free_buffer_pool(struct qeth_card
*);
60 static int qeth_qdio_establish(struct qeth_card
*);
61 static void qeth_free_qdio_buffers(struct qeth_card
*);
62 static void qeth_notify_skbs(struct qeth_qdio_out_q
*queue
,
63 struct qeth_qdio_out_buffer
*buf
,
64 enum iucv_tx_notify notification
);
65 static void qeth_release_skbs(struct qeth_qdio_out_buffer
*buf
);
66 static void qeth_clear_output_buffer(struct qeth_qdio_out_q
*queue
,
67 struct qeth_qdio_out_buffer
*buf
,
68 enum qeth_qdio_buffer_states newbufstate
);
69 static int qeth_init_qdio_out_buf(struct qeth_qdio_out_q
*, int);
71 struct workqueue_struct
*qeth_wq
;
72 EXPORT_SYMBOL_GPL(qeth_wq
);
74 static void qeth_close_dev_handler(struct work_struct
*work
)
76 struct qeth_card
*card
;
78 card
= container_of(work
, struct qeth_card
, close_dev_work
);
79 QETH_CARD_TEXT(card
, 2, "cldevhdl");
83 ccwgroup_set_offline(card
->gdev
);
86 void qeth_close_dev(struct qeth_card
*card
)
88 QETH_CARD_TEXT(card
, 2, "cldevsubm");
89 queue_work(qeth_wq
, &card
->close_dev_work
);
91 EXPORT_SYMBOL_GPL(qeth_close_dev
);
93 static inline const char *qeth_get_cardname(struct qeth_card
*card
)
95 if (card
->info
.guestlan
) {
96 switch (card
->info
.type
) {
97 case QETH_CARD_TYPE_OSD
:
98 return " Virtual NIC QDIO";
99 case QETH_CARD_TYPE_IQD
:
100 return " Virtual NIC Hiper";
101 case QETH_CARD_TYPE_OSM
:
102 return " Virtual NIC QDIO - OSM";
103 case QETH_CARD_TYPE_OSX
:
104 return " Virtual NIC QDIO - OSX";
109 switch (card
->info
.type
) {
110 case QETH_CARD_TYPE_OSD
:
111 return " OSD Express";
112 case QETH_CARD_TYPE_IQD
:
113 return " HiperSockets";
114 case QETH_CARD_TYPE_OSN
:
116 case QETH_CARD_TYPE_OSM
:
118 case QETH_CARD_TYPE_OSX
:
127 /* max length to be returned: 14 */
128 const char *qeth_get_cardname_short(struct qeth_card
*card
)
130 if (card
->info
.guestlan
) {
131 switch (card
->info
.type
) {
132 case QETH_CARD_TYPE_OSD
:
133 return "Virt.NIC QDIO";
134 case QETH_CARD_TYPE_IQD
:
135 return "Virt.NIC Hiper";
136 case QETH_CARD_TYPE_OSM
:
137 return "Virt.NIC OSM";
138 case QETH_CARD_TYPE_OSX
:
139 return "Virt.NIC OSX";
144 switch (card
->info
.type
) {
145 case QETH_CARD_TYPE_OSD
:
146 switch (card
->info
.link_type
) {
147 case QETH_LINK_TYPE_FAST_ETH
:
149 case QETH_LINK_TYPE_HSTR
:
151 case QETH_LINK_TYPE_GBIT_ETH
:
153 case QETH_LINK_TYPE_10GBIT_ETH
:
155 case QETH_LINK_TYPE_LANE_ETH100
:
156 return "OSD_FE_LANE";
157 case QETH_LINK_TYPE_LANE_TR
:
158 return "OSD_TR_LANE";
159 case QETH_LINK_TYPE_LANE_ETH1000
:
160 return "OSD_GbE_LANE";
161 case QETH_LINK_TYPE_LANE
:
162 return "OSD_ATM_LANE";
164 return "OSD_Express";
166 case QETH_CARD_TYPE_IQD
:
167 return "HiperSockets";
168 case QETH_CARD_TYPE_OSN
:
170 case QETH_CARD_TYPE_OSM
:
172 case QETH_CARD_TYPE_OSX
:
181 void qeth_set_recovery_task(struct qeth_card
*card
)
183 card
->recovery_task
= current
;
185 EXPORT_SYMBOL_GPL(qeth_set_recovery_task
);
187 void qeth_clear_recovery_task(struct qeth_card
*card
)
189 card
->recovery_task
= NULL
;
191 EXPORT_SYMBOL_GPL(qeth_clear_recovery_task
);
193 static bool qeth_is_recovery_task(const struct qeth_card
*card
)
195 return card
->recovery_task
== current
;
198 void qeth_set_allowed_threads(struct qeth_card
*card
, unsigned long threads
,
199 int clear_start_mask
)
203 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
204 card
->thread_allowed_mask
= threads
;
205 if (clear_start_mask
)
206 card
->thread_start_mask
&= threads
;
207 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
208 wake_up(&card
->wait_q
);
210 EXPORT_SYMBOL_GPL(qeth_set_allowed_threads
);
212 int qeth_threads_running(struct qeth_card
*card
, unsigned long threads
)
217 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
218 rc
= (card
->thread_running_mask
& threads
);
219 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
222 EXPORT_SYMBOL_GPL(qeth_threads_running
);
224 int qeth_wait_for_threads(struct qeth_card
*card
, unsigned long threads
)
226 if (qeth_is_recovery_task(card
))
228 return wait_event_interruptible(card
->wait_q
,
229 qeth_threads_running(card
, threads
) == 0);
231 EXPORT_SYMBOL_GPL(qeth_wait_for_threads
);
233 void qeth_clear_working_pool_list(struct qeth_card
*card
)
235 struct qeth_buffer_pool_entry
*pool_entry
, *tmp
;
237 QETH_CARD_TEXT(card
, 5, "clwrklst");
238 list_for_each_entry_safe(pool_entry
, tmp
,
239 &card
->qdio
.in_buf_pool
.entry_list
, list
){
240 list_del(&pool_entry
->list
);
243 EXPORT_SYMBOL_GPL(qeth_clear_working_pool_list
);
245 static int qeth_alloc_buffer_pool(struct qeth_card
*card
)
247 struct qeth_buffer_pool_entry
*pool_entry
;
251 QETH_CARD_TEXT(card
, 5, "alocpool");
252 for (i
= 0; i
< card
->qdio
.init_pool
.buf_count
; ++i
) {
253 pool_entry
= kzalloc(sizeof(*pool_entry
), GFP_KERNEL
);
255 qeth_free_buffer_pool(card
);
258 for (j
= 0; j
< QETH_MAX_BUFFER_ELEMENTS(card
); ++j
) {
259 ptr
= (void *) __get_free_page(GFP_KERNEL
);
262 free_page((unsigned long)
263 pool_entry
->elements
[--j
]);
265 qeth_free_buffer_pool(card
);
268 pool_entry
->elements
[j
] = ptr
;
270 list_add(&pool_entry
->init_list
,
271 &card
->qdio
.init_pool
.entry_list
);
276 int qeth_realloc_buffer_pool(struct qeth_card
*card
, int bufcnt
)
278 QETH_CARD_TEXT(card
, 2, "realcbp");
280 if ((card
->state
!= CARD_STATE_DOWN
) &&
281 (card
->state
!= CARD_STATE_RECOVER
))
284 /* TODO: steel/add buffers from/to a running card's buffer pool (?) */
285 qeth_clear_working_pool_list(card
);
286 qeth_free_buffer_pool(card
);
287 card
->qdio
.in_buf_pool
.buf_count
= bufcnt
;
288 card
->qdio
.init_pool
.buf_count
= bufcnt
;
289 return qeth_alloc_buffer_pool(card
);
291 EXPORT_SYMBOL_GPL(qeth_realloc_buffer_pool
);
293 static inline int qeth_cq_init(struct qeth_card
*card
)
297 if (card
->options
.cq
== QETH_CQ_ENABLED
) {
298 QETH_DBF_TEXT(SETUP
, 2, "cqinit");
299 memset(card
->qdio
.c_q
->qdio_bufs
, 0,
300 QDIO_MAX_BUFFERS_PER_Q
* sizeof(struct qdio_buffer
));
301 card
->qdio
.c_q
->next_buf_to_init
= 127;
302 rc
= do_QDIO(CARD_DDEV(card
), QDIO_FLAG_SYNC_INPUT
,
303 card
->qdio
.no_in_queues
- 1, 0,
306 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
315 static inline int qeth_alloc_cq(struct qeth_card
*card
)
319 if (card
->options
.cq
== QETH_CQ_ENABLED
) {
321 struct qdio_outbuf_state
*outbuf_states
;
323 QETH_DBF_TEXT(SETUP
, 2, "cqon");
324 card
->qdio
.c_q
= kzalloc(sizeof(struct qeth_qdio_q
),
326 if (!card
->qdio
.c_q
) {
330 QETH_DBF_HEX(SETUP
, 2, &card
->qdio
.c_q
, sizeof(void *));
332 for (i
= 0; i
< QDIO_MAX_BUFFERS_PER_Q
; ++i
) {
333 card
->qdio
.c_q
->bufs
[i
].buffer
=
334 &card
->qdio
.c_q
->qdio_bufs
[i
];
337 card
->qdio
.no_in_queues
= 2;
339 card
->qdio
.out_bufstates
=
340 kzalloc(card
->qdio
.no_out_queues
*
341 QDIO_MAX_BUFFERS_PER_Q
*
342 sizeof(struct qdio_outbuf_state
), GFP_KERNEL
);
343 outbuf_states
= card
->qdio
.out_bufstates
;
344 if (outbuf_states
== NULL
) {
348 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
349 card
->qdio
.out_qs
[i
]->bufstates
= outbuf_states
;
350 outbuf_states
+= QDIO_MAX_BUFFERS_PER_Q
;
353 QETH_DBF_TEXT(SETUP
, 2, "nocq");
354 card
->qdio
.c_q
= NULL
;
355 card
->qdio
.no_in_queues
= 1;
357 QETH_DBF_TEXT_(SETUP
, 2, "iqc%d", card
->qdio
.no_in_queues
);
362 kfree(card
->qdio
.c_q
);
363 card
->qdio
.c_q
= NULL
;
365 dev_err(&card
->gdev
->dev
, "Failed to create completion queue\n");
369 static inline void qeth_free_cq(struct qeth_card
*card
)
371 if (card
->qdio
.c_q
) {
372 --card
->qdio
.no_in_queues
;
373 kfree(card
->qdio
.c_q
);
374 card
->qdio
.c_q
= NULL
;
376 kfree(card
->qdio
.out_bufstates
);
377 card
->qdio
.out_bufstates
= NULL
;
380 static inline enum iucv_tx_notify
qeth_compute_cq_notification(int sbalf15
,
382 enum iucv_tx_notify n
;
386 n
= delayed
? TX_NOTIFY_DELAYED_OK
: TX_NOTIFY_OK
;
392 n
= delayed
? TX_NOTIFY_DELAYED_UNREACHABLE
:
393 TX_NOTIFY_UNREACHABLE
;
396 n
= delayed
? TX_NOTIFY_DELAYED_GENERALERROR
:
397 TX_NOTIFY_GENERALERROR
;
404 static inline void qeth_cleanup_handled_pending(struct qeth_qdio_out_q
*q
,
405 int bidx
, int forced_cleanup
)
407 if (q
->card
->options
.cq
!= QETH_CQ_ENABLED
)
410 if (q
->bufs
[bidx
]->next_pending
!= NULL
) {
411 struct qeth_qdio_out_buffer
*head
= q
->bufs
[bidx
];
412 struct qeth_qdio_out_buffer
*c
= q
->bufs
[bidx
]->next_pending
;
415 if (forced_cleanup
||
416 atomic_read(&c
->state
) ==
417 QETH_QDIO_BUF_HANDLED_DELAYED
) {
418 struct qeth_qdio_out_buffer
*f
= c
;
419 QETH_CARD_TEXT(f
->q
->card
, 5, "fp");
420 QETH_CARD_TEXT_(f
->q
->card
, 5, "%lx", (long) f
);
421 /* release here to avoid interleaving between
422 outbound tasklet and inbound tasklet
423 regarding notifications and lifecycle */
424 qeth_release_skbs(c
);
427 WARN_ON_ONCE(head
->next_pending
!= f
);
428 head
->next_pending
= c
;
429 kmem_cache_free(qeth_qdio_outbuf_cache
, f
);
437 if (forced_cleanup
&& (atomic_read(&(q
->bufs
[bidx
]->state
)) ==
438 QETH_QDIO_BUF_HANDLED_DELAYED
)) {
439 /* for recovery situations */
440 q
->bufs
[bidx
]->aob
= q
->bufstates
[bidx
].aob
;
441 qeth_init_qdio_out_buf(q
, bidx
);
442 QETH_CARD_TEXT(q
->card
, 2, "clprecov");
447 static inline void qeth_qdio_handle_aob(struct qeth_card
*card
,
448 unsigned long phys_aob_addr
) {
450 struct qeth_qdio_out_buffer
*buffer
;
451 enum iucv_tx_notify notification
;
453 aob
= (struct qaob
*) phys_to_virt(phys_aob_addr
);
454 QETH_CARD_TEXT(card
, 5, "haob");
455 QETH_CARD_TEXT_(card
, 5, "%lx", phys_aob_addr
);
456 buffer
= (struct qeth_qdio_out_buffer
*) aob
->user1
;
457 QETH_CARD_TEXT_(card
, 5, "%lx", aob
->user1
);
459 if (atomic_cmpxchg(&buffer
->state
, QETH_QDIO_BUF_PRIMED
,
460 QETH_QDIO_BUF_IN_CQ
) == QETH_QDIO_BUF_PRIMED
) {
461 notification
= TX_NOTIFY_OK
;
463 WARN_ON_ONCE(atomic_read(&buffer
->state
) !=
464 QETH_QDIO_BUF_PENDING
);
465 atomic_set(&buffer
->state
, QETH_QDIO_BUF_IN_CQ
);
466 notification
= TX_NOTIFY_DELAYED_OK
;
469 if (aob
->aorc
!= 0) {
470 QETH_CARD_TEXT_(card
, 2, "aorc%02X", aob
->aorc
);
471 notification
= qeth_compute_cq_notification(aob
->aorc
, 1);
473 qeth_notify_skbs(buffer
->q
, buffer
, notification
);
476 qeth_clear_output_buffer(buffer
->q
, buffer
,
477 QETH_QDIO_BUF_HANDLED_DELAYED
);
479 /* from here on: do not touch buffer anymore */
480 qdio_release_aob(aob
);
483 static inline int qeth_is_cq(struct qeth_card
*card
, unsigned int queue
)
485 return card
->options
.cq
== QETH_CQ_ENABLED
&&
486 card
->qdio
.c_q
!= NULL
&&
488 queue
== card
->qdio
.no_in_queues
- 1;
492 static int qeth_issue_next_read(struct qeth_card
*card
)
495 struct qeth_cmd_buffer
*iob
;
497 QETH_CARD_TEXT(card
, 5, "issnxrd");
498 if (card
->read
.state
!= CH_STATE_UP
)
500 iob
= qeth_get_buffer(&card
->read
);
502 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
503 "failed to recover an error on the device\n");
504 QETH_DBF_MESSAGE(2, "%s issue_next_read failed: no iob "
505 "available\n", dev_name(&card
->gdev
->dev
));
508 qeth_setup_ccw(&card
->read
, iob
->data
, QETH_BUFSIZE
);
509 QETH_CARD_TEXT(card
, 6, "noirqpnd");
510 rc
= ccw_device_start(card
->read
.ccwdev
, &card
->read
.ccw
,
513 QETH_DBF_MESSAGE(2, "%s error in starting next read ccw! "
514 "rc=%i\n", dev_name(&card
->gdev
->dev
), rc
);
515 atomic_set(&card
->read
.irq_pending
, 0);
516 card
->read_or_write_problem
= 1;
517 qeth_schedule_recovery(card
);
518 wake_up(&card
->wait_q
);
523 static struct qeth_reply
*qeth_alloc_reply(struct qeth_card
*card
)
525 struct qeth_reply
*reply
;
527 reply
= kzalloc(sizeof(struct qeth_reply
), GFP_ATOMIC
);
529 atomic_set(&reply
->refcnt
, 1);
530 atomic_set(&reply
->received
, 0);
536 static void qeth_get_reply(struct qeth_reply
*reply
)
538 WARN_ON(atomic_read(&reply
->refcnt
) <= 0);
539 atomic_inc(&reply
->refcnt
);
542 static void qeth_put_reply(struct qeth_reply
*reply
)
544 WARN_ON(atomic_read(&reply
->refcnt
) <= 0);
545 if (atomic_dec_and_test(&reply
->refcnt
))
549 static void qeth_issue_ipa_msg(struct qeth_ipa_cmd
*cmd
, int rc
,
550 struct qeth_card
*card
)
553 int com
= cmd
->hdr
.command
;
554 ipa_name
= qeth_get_ipa_cmd_name(com
);
556 QETH_DBF_MESSAGE(2, "IPA: %s(x%X) for %s/%s returned "
558 ipa_name
, com
, dev_name(&card
->gdev
->dev
),
559 QETH_CARD_IFNAME(card
), rc
,
560 qeth_get_ipa_msg(rc
));
562 QETH_DBF_MESSAGE(5, "IPA: %s(x%X) for %s/%s succeeded\n",
563 ipa_name
, com
, dev_name(&card
->gdev
->dev
),
564 QETH_CARD_IFNAME(card
));
567 static struct qeth_ipa_cmd
*qeth_check_ipa_data(struct qeth_card
*card
,
568 struct qeth_cmd_buffer
*iob
)
570 struct qeth_ipa_cmd
*cmd
= NULL
;
572 QETH_CARD_TEXT(card
, 5, "chkipad");
573 if (IS_IPA(iob
->data
)) {
574 cmd
= (struct qeth_ipa_cmd
*) PDU_ENCAPSULATION(iob
->data
);
575 if (IS_IPA_REPLY(cmd
)) {
576 if (cmd
->hdr
.command
!= IPA_CMD_SETCCID
&&
577 cmd
->hdr
.command
!= IPA_CMD_DELCCID
&&
578 cmd
->hdr
.command
!= IPA_CMD_MODCCID
&&
579 cmd
->hdr
.command
!= IPA_CMD_SET_DIAG_ASS
)
580 qeth_issue_ipa_msg(cmd
,
581 cmd
->hdr
.return_code
, card
);
584 switch (cmd
->hdr
.command
) {
585 case IPA_CMD_STOPLAN
:
586 if (cmd
->hdr
.return_code
==
587 IPA_RC_VEPA_TO_VEB_TRANSITION
) {
588 dev_err(&card
->gdev
->dev
,
589 "Interface %s is down because the "
590 "adjacent port is no longer in "
591 "reflective relay mode\n",
592 QETH_CARD_IFNAME(card
));
593 qeth_close_dev(card
);
595 dev_warn(&card
->gdev
->dev
,
596 "The link for interface %s on CHPID"
598 QETH_CARD_IFNAME(card
),
600 qeth_issue_ipa_msg(cmd
,
601 cmd
->hdr
.return_code
, card
);
603 card
->lan_online
= 0;
604 if (card
->dev
&& netif_carrier_ok(card
->dev
))
605 netif_carrier_off(card
->dev
);
607 case IPA_CMD_STARTLAN
:
608 dev_info(&card
->gdev
->dev
,
609 "The link for %s on CHPID 0x%X has"
611 QETH_CARD_IFNAME(card
),
613 netif_carrier_on(card
->dev
);
614 card
->lan_online
= 1;
615 if (card
->info
.hwtrap
)
616 card
->info
.hwtrap
= 2;
617 qeth_schedule_recovery(card
);
619 case IPA_CMD_SETBRIDGEPORT
:
620 case IPA_CMD_ADDRESS_CHANGE_NOTIF
:
621 if (card
->discipline
->control_event_handler
626 case IPA_CMD_MODCCID
:
628 case IPA_CMD_REGISTER_LOCAL_ADDR
:
629 QETH_CARD_TEXT(card
, 3, "irla");
631 case IPA_CMD_UNREGISTER_LOCAL_ADDR
:
632 QETH_CARD_TEXT(card
, 3, "urla");
635 QETH_DBF_MESSAGE(2, "Received data is IPA "
636 "but not a reply!\n");
644 void qeth_clear_ipacmd_list(struct qeth_card
*card
)
646 struct qeth_reply
*reply
, *r
;
649 QETH_CARD_TEXT(card
, 4, "clipalst");
651 spin_lock_irqsave(&card
->lock
, flags
);
652 list_for_each_entry_safe(reply
, r
, &card
->cmd_waiter_list
, list
) {
653 qeth_get_reply(reply
);
655 atomic_inc(&reply
->received
);
656 list_del_init(&reply
->list
);
657 wake_up(&reply
->wait_q
);
658 qeth_put_reply(reply
);
660 spin_unlock_irqrestore(&card
->lock
, flags
);
661 atomic_set(&card
->write
.irq_pending
, 0);
663 EXPORT_SYMBOL_GPL(qeth_clear_ipacmd_list
);
665 static int qeth_check_idx_response(struct qeth_card
*card
,
666 unsigned char *buffer
)
671 QETH_DBF_HEX(CTRL
, 2, buffer
, QETH_DBF_CTRL_LEN
);
672 if ((buffer
[2] & 0xc0) == 0xc0) {
673 QETH_DBF_MESSAGE(2, "received an IDX TERMINATE "
674 "with cause code 0x%02x%s\n",
676 ((buffer
[4] == 0x22) ?
677 " -- try another portname" : ""));
678 QETH_CARD_TEXT(card
, 2, "ckidxres");
679 QETH_CARD_TEXT(card
, 2, " idxterm");
680 QETH_CARD_TEXT_(card
, 2, " rc%d", -EIO
);
681 if (buffer
[4] == 0xf6) {
682 dev_err(&card
->gdev
->dev
,
683 "The qeth device is not configured "
684 "for the OSI layer required by z/VM\n");
692 static void qeth_setup_ccw(struct qeth_channel
*channel
, unsigned char *iob
,
695 struct qeth_card
*card
;
697 card
= CARD_FROM_CDEV(channel
->ccwdev
);
698 QETH_CARD_TEXT(card
, 4, "setupccw");
699 if (channel
== &card
->read
)
700 memcpy(&channel
->ccw
, READ_CCW
, sizeof(struct ccw1
));
702 memcpy(&channel
->ccw
, WRITE_CCW
, sizeof(struct ccw1
));
703 channel
->ccw
.count
= len
;
704 channel
->ccw
.cda
= (__u32
) __pa(iob
);
707 static struct qeth_cmd_buffer
*__qeth_get_buffer(struct qeth_channel
*channel
)
711 QETH_CARD_TEXT(CARD_FROM_CDEV(channel
->ccwdev
), 6, "getbuff");
712 index
= channel
->io_buf_no
;
714 if (channel
->iob
[index
].state
== BUF_STATE_FREE
) {
715 channel
->iob
[index
].state
= BUF_STATE_LOCKED
;
716 channel
->io_buf_no
= (channel
->io_buf_no
+ 1) %
718 memset(channel
->iob
[index
].data
, 0, QETH_BUFSIZE
);
719 return channel
->iob
+ index
;
721 index
= (index
+ 1) % QETH_CMD_BUFFER_NO
;
722 } while (index
!= channel
->io_buf_no
);
727 void qeth_release_buffer(struct qeth_channel
*channel
,
728 struct qeth_cmd_buffer
*iob
)
732 QETH_CARD_TEXT(CARD_FROM_CDEV(channel
->ccwdev
), 6, "relbuff");
733 spin_lock_irqsave(&channel
->iob_lock
, flags
);
734 memset(iob
->data
, 0, QETH_BUFSIZE
);
735 iob
->state
= BUF_STATE_FREE
;
736 iob
->callback
= qeth_send_control_data_cb
;
738 spin_unlock_irqrestore(&channel
->iob_lock
, flags
);
739 wake_up(&channel
->wait_q
);
741 EXPORT_SYMBOL_GPL(qeth_release_buffer
);
743 static struct qeth_cmd_buffer
*qeth_get_buffer(struct qeth_channel
*channel
)
745 struct qeth_cmd_buffer
*buffer
= NULL
;
748 spin_lock_irqsave(&channel
->iob_lock
, flags
);
749 buffer
= __qeth_get_buffer(channel
);
750 spin_unlock_irqrestore(&channel
->iob_lock
, flags
);
754 struct qeth_cmd_buffer
*qeth_wait_for_buffer(struct qeth_channel
*channel
)
756 struct qeth_cmd_buffer
*buffer
;
757 wait_event(channel
->wait_q
,
758 ((buffer
= qeth_get_buffer(channel
)) != NULL
));
761 EXPORT_SYMBOL_GPL(qeth_wait_for_buffer
);
763 void qeth_clear_cmd_buffers(struct qeth_channel
*channel
)
767 for (cnt
= 0; cnt
< QETH_CMD_BUFFER_NO
; cnt
++)
768 qeth_release_buffer(channel
, &channel
->iob
[cnt
]);
770 channel
->io_buf_no
= 0;
772 EXPORT_SYMBOL_GPL(qeth_clear_cmd_buffers
);
774 static void qeth_send_control_data_cb(struct qeth_channel
*channel
,
775 struct qeth_cmd_buffer
*iob
)
777 struct qeth_card
*card
;
778 struct qeth_reply
*reply
, *r
;
779 struct qeth_ipa_cmd
*cmd
;
784 card
= CARD_FROM_CDEV(channel
->ccwdev
);
785 QETH_CARD_TEXT(card
, 4, "sndctlcb");
786 rc
= qeth_check_idx_response(card
, iob
->data
);
791 qeth_clear_ipacmd_list(card
);
792 qeth_schedule_recovery(card
);
798 cmd
= qeth_check_ipa_data(card
, iob
);
799 if ((cmd
== NULL
) && (card
->state
!= CARD_STATE_DOWN
))
801 /*in case of OSN : check if cmd is set */
802 if (card
->info
.type
== QETH_CARD_TYPE_OSN
&&
804 cmd
->hdr
.command
!= IPA_CMD_STARTLAN
&&
805 card
->osn_info
.assist_cb
!= NULL
) {
806 card
->osn_info
.assist_cb(card
->dev
, cmd
);
810 spin_lock_irqsave(&card
->lock
, flags
);
811 list_for_each_entry_safe(reply
, r
, &card
->cmd_waiter_list
, list
) {
812 if ((reply
->seqno
== QETH_IDX_COMMAND_SEQNO
) ||
813 ((cmd
) && (reply
->seqno
== cmd
->hdr
.seqno
))) {
814 qeth_get_reply(reply
);
815 list_del_init(&reply
->list
);
816 spin_unlock_irqrestore(&card
->lock
, flags
);
818 if (reply
->callback
!= NULL
) {
820 reply
->offset
= (__u16
)((char *)cmd
-
822 keep_reply
= reply
->callback(card
,
826 keep_reply
= reply
->callback(card
,
831 reply
->rc
= (u16
) cmd
->hdr
.return_code
;
835 spin_lock_irqsave(&card
->lock
, flags
);
836 list_add_tail(&reply
->list
,
837 &card
->cmd_waiter_list
);
838 spin_unlock_irqrestore(&card
->lock
, flags
);
840 atomic_inc(&reply
->received
);
841 wake_up(&reply
->wait_q
);
843 qeth_put_reply(reply
);
847 spin_unlock_irqrestore(&card
->lock
, flags
);
849 memcpy(&card
->seqno
.pdu_hdr_ack
,
850 QETH_PDU_HEADER_SEQ_NO(iob
->data
),
852 qeth_release_buffer(channel
, iob
);
855 static int qeth_setup_channel(struct qeth_channel
*channel
)
859 QETH_DBF_TEXT(SETUP
, 2, "setupch");
860 for (cnt
= 0; cnt
< QETH_CMD_BUFFER_NO
; cnt
++) {
861 channel
->iob
[cnt
].data
=
862 kzalloc(QETH_BUFSIZE
, GFP_DMA
|GFP_KERNEL
);
863 if (channel
->iob
[cnt
].data
== NULL
)
865 channel
->iob
[cnt
].state
= BUF_STATE_FREE
;
866 channel
->iob
[cnt
].channel
= channel
;
867 channel
->iob
[cnt
].callback
= qeth_send_control_data_cb
;
868 channel
->iob
[cnt
].rc
= 0;
870 if (cnt
< QETH_CMD_BUFFER_NO
) {
872 kfree(channel
->iob
[cnt
].data
);
876 channel
->io_buf_no
= 0;
877 atomic_set(&channel
->irq_pending
, 0);
878 spin_lock_init(&channel
->iob_lock
);
880 init_waitqueue_head(&channel
->wait_q
);
884 static int qeth_set_thread_start_bit(struct qeth_card
*card
,
885 unsigned long thread
)
889 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
890 if (!(card
->thread_allowed_mask
& thread
) ||
891 (card
->thread_start_mask
& thread
)) {
892 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
895 card
->thread_start_mask
|= thread
;
896 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
900 void qeth_clear_thread_start_bit(struct qeth_card
*card
, unsigned long thread
)
904 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
905 card
->thread_start_mask
&= ~thread
;
906 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
907 wake_up(&card
->wait_q
);
909 EXPORT_SYMBOL_GPL(qeth_clear_thread_start_bit
);
911 void qeth_clear_thread_running_bit(struct qeth_card
*card
, unsigned long thread
)
915 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
916 card
->thread_running_mask
&= ~thread
;
917 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
918 wake_up(&card
->wait_q
);
920 EXPORT_SYMBOL_GPL(qeth_clear_thread_running_bit
);
922 static int __qeth_do_run_thread(struct qeth_card
*card
, unsigned long thread
)
927 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
928 if (card
->thread_start_mask
& thread
) {
929 if ((card
->thread_allowed_mask
& thread
) &&
930 !(card
->thread_running_mask
& thread
)) {
932 card
->thread_start_mask
&= ~thread
;
933 card
->thread_running_mask
|= thread
;
937 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
941 int qeth_do_run_thread(struct qeth_card
*card
, unsigned long thread
)
945 wait_event(card
->wait_q
,
946 (rc
= __qeth_do_run_thread(card
, thread
)) >= 0);
949 EXPORT_SYMBOL_GPL(qeth_do_run_thread
);
951 void qeth_schedule_recovery(struct qeth_card
*card
)
953 QETH_CARD_TEXT(card
, 2, "startrec");
954 if (qeth_set_thread_start_bit(card
, QETH_RECOVER_THREAD
) == 0)
955 schedule_work(&card
->kernel_thread_starter
);
957 EXPORT_SYMBOL_GPL(qeth_schedule_recovery
);
959 static int qeth_get_problem(struct ccw_device
*cdev
, struct irb
*irb
)
963 struct qeth_card
*card
;
965 sense
= (char *) irb
->ecw
;
966 cstat
= irb
->scsw
.cmd
.cstat
;
967 dstat
= irb
->scsw
.cmd
.dstat
;
968 card
= CARD_FROM_CDEV(cdev
);
970 if (cstat
& (SCHN_STAT_CHN_CTRL_CHK
| SCHN_STAT_INTF_CTRL_CHK
|
971 SCHN_STAT_CHN_DATA_CHK
| SCHN_STAT_CHAIN_CHECK
|
972 SCHN_STAT_PROT_CHECK
| SCHN_STAT_PROG_CHECK
)) {
973 QETH_CARD_TEXT(card
, 2, "CGENCHK");
974 dev_warn(&cdev
->dev
, "The qeth device driver "
975 "failed to recover an error on the device\n");
976 QETH_DBF_MESSAGE(2, "%s check on device dstat=x%x, cstat=x%x\n",
977 dev_name(&cdev
->dev
), dstat
, cstat
);
978 print_hex_dump(KERN_WARNING
, "qeth: irb ", DUMP_PREFIX_OFFSET
,
983 if (dstat
& DEV_STAT_UNIT_CHECK
) {
984 if (sense
[SENSE_RESETTING_EVENT_BYTE
] &
985 SENSE_RESETTING_EVENT_FLAG
) {
986 QETH_CARD_TEXT(card
, 2, "REVIND");
989 if (sense
[SENSE_COMMAND_REJECT_BYTE
] &
990 SENSE_COMMAND_REJECT_FLAG
) {
991 QETH_CARD_TEXT(card
, 2, "CMDREJi");
994 if ((sense
[2] == 0xaf) && (sense
[3] == 0xfe)) {
995 QETH_CARD_TEXT(card
, 2, "AFFE");
998 if ((!sense
[0]) && (!sense
[1]) && (!sense
[2]) && (!sense
[3])) {
999 QETH_CARD_TEXT(card
, 2, "ZEROSEN");
1002 QETH_CARD_TEXT(card
, 2, "DGENCHK");
1008 static long __qeth_check_irb_error(struct ccw_device
*cdev
,
1009 unsigned long intparm
, struct irb
*irb
)
1011 struct qeth_card
*card
;
1013 card
= CARD_FROM_CDEV(cdev
);
1018 switch (PTR_ERR(irb
)) {
1020 QETH_DBF_MESSAGE(2, "%s i/o-error on device\n",
1021 dev_name(&cdev
->dev
));
1022 QETH_CARD_TEXT(card
, 2, "ckirberr");
1023 QETH_CARD_TEXT_(card
, 2, " rc%d", -EIO
);
1026 dev_warn(&cdev
->dev
, "A hardware operation timed out"
1027 " on the device\n");
1028 QETH_CARD_TEXT(card
, 2, "ckirberr");
1029 QETH_CARD_TEXT_(card
, 2, " rc%d", -ETIMEDOUT
);
1030 if (intparm
== QETH_RCD_PARM
) {
1031 if (card
&& (card
->data
.ccwdev
== cdev
)) {
1032 card
->data
.state
= CH_STATE_DOWN
;
1033 wake_up(&card
->wait_q
);
1038 QETH_DBF_MESSAGE(2, "%s unknown error %ld on device\n",
1039 dev_name(&cdev
->dev
), PTR_ERR(irb
));
1040 QETH_CARD_TEXT(card
, 2, "ckirberr");
1041 QETH_CARD_TEXT(card
, 2, " rc???");
1043 return PTR_ERR(irb
);
1046 static void qeth_irq(struct ccw_device
*cdev
, unsigned long intparm
,
1051 struct qeth_cmd_buffer
*buffer
;
1052 struct qeth_channel
*channel
;
1053 struct qeth_card
*card
;
1054 struct qeth_cmd_buffer
*iob
;
1057 if (__qeth_check_irb_error(cdev
, intparm
, irb
))
1059 cstat
= irb
->scsw
.cmd
.cstat
;
1060 dstat
= irb
->scsw
.cmd
.dstat
;
1062 card
= CARD_FROM_CDEV(cdev
);
1066 QETH_CARD_TEXT(card
, 5, "irq");
1068 if (card
->read
.ccwdev
== cdev
) {
1069 channel
= &card
->read
;
1070 QETH_CARD_TEXT(card
, 5, "read");
1071 } else if (card
->write
.ccwdev
== cdev
) {
1072 channel
= &card
->write
;
1073 QETH_CARD_TEXT(card
, 5, "write");
1075 channel
= &card
->data
;
1076 QETH_CARD_TEXT(card
, 5, "data");
1078 atomic_set(&channel
->irq_pending
, 0);
1080 if (irb
->scsw
.cmd
.fctl
& (SCSW_FCTL_CLEAR_FUNC
))
1081 channel
->state
= CH_STATE_STOPPED
;
1083 if (irb
->scsw
.cmd
.fctl
& (SCSW_FCTL_HALT_FUNC
))
1084 channel
->state
= CH_STATE_HALTED
;
1086 /*let's wake up immediately on data channel*/
1087 if ((channel
== &card
->data
) && (intparm
!= 0) &&
1088 (intparm
!= QETH_RCD_PARM
))
1091 if (intparm
== QETH_CLEAR_CHANNEL_PARM
) {
1092 QETH_CARD_TEXT(card
, 6, "clrchpar");
1093 /* we don't have to handle this further */
1096 if (intparm
== QETH_HALT_CHANNEL_PARM
) {
1097 QETH_CARD_TEXT(card
, 6, "hltchpar");
1098 /* we don't have to handle this further */
1101 if ((dstat
& DEV_STAT_UNIT_EXCEP
) ||
1102 (dstat
& DEV_STAT_UNIT_CHECK
) ||
1104 if (irb
->esw
.esw0
.erw
.cons
) {
1105 dev_warn(&channel
->ccwdev
->dev
,
1106 "The qeth device driver failed to recover "
1107 "an error on the device\n");
1108 QETH_DBF_MESSAGE(2, "%s sense data available. cstat "
1109 "0x%X dstat 0x%X\n",
1110 dev_name(&channel
->ccwdev
->dev
), cstat
, dstat
);
1111 print_hex_dump(KERN_WARNING
, "qeth: irb ",
1112 DUMP_PREFIX_OFFSET
, 16, 1, irb
, 32, 1);
1113 print_hex_dump(KERN_WARNING
, "qeth: sense data ",
1114 DUMP_PREFIX_OFFSET
, 16, 1, irb
->ecw
, 32, 1);
1116 if (intparm
== QETH_RCD_PARM
) {
1117 channel
->state
= CH_STATE_DOWN
;
1120 rc
= qeth_get_problem(cdev
, irb
);
1122 qeth_clear_ipacmd_list(card
);
1123 qeth_schedule_recovery(card
);
1128 if (intparm
== QETH_RCD_PARM
) {
1129 channel
->state
= CH_STATE_RCD_DONE
;
1133 buffer
= (struct qeth_cmd_buffer
*) __va((addr_t
)intparm
);
1134 buffer
->state
= BUF_STATE_PROCESSED
;
1136 if (channel
== &card
->data
)
1138 if (channel
== &card
->read
&&
1139 channel
->state
== CH_STATE_UP
)
1140 qeth_issue_next_read(card
);
1143 index
= channel
->buf_no
;
1144 while (iob
[index
].state
== BUF_STATE_PROCESSED
) {
1145 if (iob
[index
].callback
!= NULL
)
1146 iob
[index
].callback(channel
, iob
+ index
);
1148 index
= (index
+ 1) % QETH_CMD_BUFFER_NO
;
1150 channel
->buf_no
= index
;
1152 wake_up(&card
->wait_q
);
1156 static void qeth_notify_skbs(struct qeth_qdio_out_q
*q
,
1157 struct qeth_qdio_out_buffer
*buf
,
1158 enum iucv_tx_notify notification
)
1160 struct sk_buff
*skb
;
1162 if (skb_queue_empty(&buf
->skb_list
))
1164 skb
= skb_peek(&buf
->skb_list
);
1166 QETH_CARD_TEXT_(q
->card
, 5, "skbn%d", notification
);
1167 QETH_CARD_TEXT_(q
->card
, 5, "%lx", (long) skb
);
1168 if (skb
->protocol
== ETH_P_AF_IUCV
) {
1170 struct iucv_sock
*iucv
= iucv_sk(skb
->sk
);
1171 iucv
->sk_txnotify(skb
, notification
);
1174 if (skb_queue_is_last(&buf
->skb_list
, skb
))
1177 skb
= skb_queue_next(&buf
->skb_list
, skb
);
1183 static void qeth_release_skbs(struct qeth_qdio_out_buffer
*buf
)
1185 struct sk_buff
*skb
;
1186 struct iucv_sock
*iucv
;
1187 int notify_general_error
= 0;
1189 if (atomic_read(&buf
->state
) == QETH_QDIO_BUF_PENDING
)
1190 notify_general_error
= 1;
1192 /* release may never happen from within CQ tasklet scope */
1193 WARN_ON_ONCE(atomic_read(&buf
->state
) == QETH_QDIO_BUF_IN_CQ
);
1195 skb
= skb_dequeue(&buf
->skb_list
);
1197 QETH_CARD_TEXT(buf
->q
->card
, 5, "skbr");
1198 QETH_CARD_TEXT_(buf
->q
->card
, 5, "%lx", (long) skb
);
1199 if (notify_general_error
&& skb
->protocol
== ETH_P_AF_IUCV
) {
1201 iucv
= iucv_sk(skb
->sk
);
1202 iucv
->sk_txnotify(skb
, TX_NOTIFY_GENERALERROR
);
1205 atomic_dec(&skb
->users
);
1206 dev_kfree_skb_any(skb
);
1207 skb
= skb_dequeue(&buf
->skb_list
);
1211 static void qeth_clear_output_buffer(struct qeth_qdio_out_q
*queue
,
1212 struct qeth_qdio_out_buffer
*buf
,
1213 enum qeth_qdio_buffer_states newbufstate
)
1217 /* is PCI flag set on buffer? */
1218 if (buf
->buffer
->element
[0].sflags
& SBAL_SFLAGS0_PCI_REQ
)
1219 atomic_dec(&queue
->set_pci_flags_count
);
1221 if (newbufstate
== QETH_QDIO_BUF_EMPTY
) {
1222 qeth_release_skbs(buf
);
1224 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(queue
->card
); ++i
) {
1225 if (buf
->buffer
->element
[i
].addr
&& buf
->is_header
[i
])
1226 kmem_cache_free(qeth_core_header_cache
,
1227 buf
->buffer
->element
[i
].addr
);
1228 buf
->is_header
[i
] = 0;
1229 buf
->buffer
->element
[i
].length
= 0;
1230 buf
->buffer
->element
[i
].addr
= NULL
;
1231 buf
->buffer
->element
[i
].eflags
= 0;
1232 buf
->buffer
->element
[i
].sflags
= 0;
1234 buf
->buffer
->element
[15].eflags
= 0;
1235 buf
->buffer
->element
[15].sflags
= 0;
1236 buf
->next_element_to_fill
= 0;
1237 atomic_set(&buf
->state
, newbufstate
);
1240 static void qeth_clear_outq_buffers(struct qeth_qdio_out_q
*q
, int free
)
1244 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
) {
1247 qeth_cleanup_handled_pending(q
, j
, 1);
1248 qeth_clear_output_buffer(q
, q
->bufs
[j
], QETH_QDIO_BUF_EMPTY
);
1250 kmem_cache_free(qeth_qdio_outbuf_cache
, q
->bufs
[j
]);
1256 void qeth_clear_qdio_buffers(struct qeth_card
*card
)
1260 QETH_CARD_TEXT(card
, 2, "clearqdbf");
1261 /* clear outbound buffers to free skbs */
1262 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
1263 if (card
->qdio
.out_qs
[i
]) {
1264 qeth_clear_outq_buffers(card
->qdio
.out_qs
[i
], 0);
1268 EXPORT_SYMBOL_GPL(qeth_clear_qdio_buffers
);
1270 static void qeth_free_buffer_pool(struct qeth_card
*card
)
1272 struct qeth_buffer_pool_entry
*pool_entry
, *tmp
;
1274 list_for_each_entry_safe(pool_entry
, tmp
,
1275 &card
->qdio
.init_pool
.entry_list
, init_list
){
1276 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(card
); ++i
)
1277 free_page((unsigned long)pool_entry
->elements
[i
]);
1278 list_del(&pool_entry
->init_list
);
1283 static void qeth_free_qdio_buffers(struct qeth_card
*card
)
1287 if (atomic_xchg(&card
->qdio
.state
, QETH_QDIO_UNINITIALIZED
) ==
1288 QETH_QDIO_UNINITIALIZED
)
1292 cancel_delayed_work_sync(&card
->buffer_reclaim_work
);
1293 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
) {
1294 if (card
->qdio
.in_q
->bufs
[j
].rx_skb
)
1295 dev_kfree_skb_any(card
->qdio
.in_q
->bufs
[j
].rx_skb
);
1297 kfree(card
->qdio
.in_q
);
1298 card
->qdio
.in_q
= NULL
;
1299 /* inbound buffer pool */
1300 qeth_free_buffer_pool(card
);
1301 /* free outbound qdio_qs */
1302 if (card
->qdio
.out_qs
) {
1303 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
1304 qeth_clear_outq_buffers(card
->qdio
.out_qs
[i
], 1);
1305 kfree(card
->qdio
.out_qs
[i
]);
1307 kfree(card
->qdio
.out_qs
);
1308 card
->qdio
.out_qs
= NULL
;
1312 static void qeth_clean_channel(struct qeth_channel
*channel
)
1316 QETH_DBF_TEXT(SETUP
, 2, "freech");
1317 for (cnt
= 0; cnt
< QETH_CMD_BUFFER_NO
; cnt
++)
1318 kfree(channel
->iob
[cnt
].data
);
1321 static void qeth_set_single_write_queues(struct qeth_card
*card
)
1323 if ((atomic_read(&card
->qdio
.state
) != QETH_QDIO_UNINITIALIZED
) &&
1324 (card
->qdio
.no_out_queues
== 4))
1325 qeth_free_qdio_buffers(card
);
1327 card
->qdio
.no_out_queues
= 1;
1328 if (card
->qdio
.default_out_queue
!= 0)
1329 dev_info(&card
->gdev
->dev
, "Priority Queueing not supported\n");
1331 card
->qdio
.default_out_queue
= 0;
1334 static void qeth_set_multiple_write_queues(struct qeth_card
*card
)
1336 if ((atomic_read(&card
->qdio
.state
) != QETH_QDIO_UNINITIALIZED
) &&
1337 (card
->qdio
.no_out_queues
== 1)) {
1338 qeth_free_qdio_buffers(card
);
1339 card
->qdio
.default_out_queue
= 2;
1341 card
->qdio
.no_out_queues
= 4;
1344 static void qeth_update_from_chp_desc(struct qeth_card
*card
)
1346 struct ccw_device
*ccwdev
;
1347 struct channelPath_dsc
{
1358 QETH_DBF_TEXT(SETUP
, 2, "chp_desc");
1360 ccwdev
= card
->data
.ccwdev
;
1361 chp_dsc
= ccw_device_get_chp_desc(ccwdev
, 0);
1365 card
->info
.func_level
= 0x4100 + chp_dsc
->desc
;
1366 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
1369 /* CHPP field bit 6 == 1 -> single queue */
1370 if ((chp_dsc
->chpp
& 0x02) == 0x02)
1371 qeth_set_single_write_queues(card
);
1373 qeth_set_multiple_write_queues(card
);
1376 QETH_DBF_TEXT_(SETUP
, 2, "nr:%x", card
->qdio
.no_out_queues
);
1377 QETH_DBF_TEXT_(SETUP
, 2, "lvl:%02x", card
->info
.func_level
);
1380 static void qeth_init_qdio_info(struct qeth_card
*card
)
1382 QETH_DBF_TEXT(SETUP
, 4, "intqdinf");
1383 atomic_set(&card
->qdio
.state
, QETH_QDIO_UNINITIALIZED
);
1385 card
->qdio
.in_buf_size
= QETH_IN_BUF_SIZE_DEFAULT
;
1386 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
1387 card
->qdio
.init_pool
.buf_count
= QETH_IN_BUF_COUNT_HSDEFAULT
;
1389 card
->qdio
.init_pool
.buf_count
= QETH_IN_BUF_COUNT_DEFAULT
;
1390 card
->qdio
.in_buf_pool
.buf_count
= card
->qdio
.init_pool
.buf_count
;
1391 INIT_LIST_HEAD(&card
->qdio
.in_buf_pool
.entry_list
);
1392 INIT_LIST_HEAD(&card
->qdio
.init_pool
.entry_list
);
1395 static void qeth_set_intial_options(struct qeth_card
*card
)
1397 card
->options
.route4
.type
= NO_ROUTER
;
1398 card
->options
.route6
.type
= NO_ROUTER
;
1399 card
->options
.fake_broadcast
= 0;
1400 card
->options
.add_hhlen
= DEFAULT_ADD_HHLEN
;
1401 card
->options
.performance_stats
= 0;
1402 card
->options
.rx_sg_cb
= QETH_RX_SG_CB
;
1403 card
->options
.isolation
= ISOLATION_MODE_NONE
;
1404 card
->options
.cq
= QETH_CQ_DISABLED
;
1407 static int qeth_do_start_thread(struct qeth_card
*card
, unsigned long thread
)
1409 unsigned long flags
;
1412 spin_lock_irqsave(&card
->thread_mask_lock
, flags
);
1413 QETH_CARD_TEXT_(card
, 4, " %02x%02x%02x",
1414 (u8
) card
->thread_start_mask
,
1415 (u8
) card
->thread_allowed_mask
,
1416 (u8
) card
->thread_running_mask
);
1417 rc
= (card
->thread_start_mask
& thread
);
1418 spin_unlock_irqrestore(&card
->thread_mask_lock
, flags
);
1422 static void qeth_start_kernel_thread(struct work_struct
*work
)
1424 struct task_struct
*ts
;
1425 struct qeth_card
*card
= container_of(work
, struct qeth_card
,
1426 kernel_thread_starter
);
1427 QETH_CARD_TEXT(card
, 2, "strthrd");
1429 if (card
->read
.state
!= CH_STATE_UP
&&
1430 card
->write
.state
!= CH_STATE_UP
)
1432 if (qeth_do_start_thread(card
, QETH_RECOVER_THREAD
)) {
1433 ts
= kthread_run(card
->discipline
->recover
, (void *)card
,
1436 qeth_clear_thread_start_bit(card
, QETH_RECOVER_THREAD
);
1437 qeth_clear_thread_running_bit(card
,
1438 QETH_RECOVER_THREAD
);
1443 static int qeth_setup_card(struct qeth_card
*card
)
1446 QETH_DBF_TEXT(SETUP
, 2, "setupcrd");
1447 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
1449 card
->read
.state
= CH_STATE_DOWN
;
1450 card
->write
.state
= CH_STATE_DOWN
;
1451 card
->data
.state
= CH_STATE_DOWN
;
1452 card
->state
= CARD_STATE_DOWN
;
1453 card
->lan_online
= 0;
1454 card
->read_or_write_problem
= 0;
1456 spin_lock_init(&card
->vlanlock
);
1457 spin_lock_init(&card
->mclock
);
1458 spin_lock_init(&card
->lock
);
1459 spin_lock_init(&card
->ip_lock
);
1460 spin_lock_init(&card
->thread_mask_lock
);
1461 mutex_init(&card
->conf_mutex
);
1462 mutex_init(&card
->discipline_mutex
);
1463 card
->thread_start_mask
= 0;
1464 card
->thread_allowed_mask
= 0;
1465 card
->thread_running_mask
= 0;
1466 INIT_WORK(&card
->kernel_thread_starter
, qeth_start_kernel_thread
);
1467 INIT_LIST_HEAD(&card
->ip_list
);
1468 INIT_LIST_HEAD(card
->ip_tbd_list
);
1469 INIT_LIST_HEAD(&card
->cmd_waiter_list
);
1470 init_waitqueue_head(&card
->wait_q
);
1471 /* initial options */
1472 qeth_set_intial_options(card
);
1473 /* IP address takeover */
1474 INIT_LIST_HEAD(&card
->ipato
.entries
);
1475 card
->ipato
.enabled
= 0;
1476 card
->ipato
.invert4
= 0;
1477 card
->ipato
.invert6
= 0;
1478 /* init QDIO stuff */
1479 qeth_init_qdio_info(card
);
1480 INIT_DELAYED_WORK(&card
->buffer_reclaim_work
, qeth_buffer_reclaim_work
);
1481 INIT_WORK(&card
->close_dev_work
, qeth_close_dev_handler
);
1485 static void qeth_core_sl_print(struct seq_file
*m
, struct service_level
*slr
)
1487 struct qeth_card
*card
= container_of(slr
, struct qeth_card
,
1488 qeth_service_level
);
1489 if (card
->info
.mcl_level
[0])
1490 seq_printf(m
, "qeth: %s firmware level %s\n",
1491 CARD_BUS_ID(card
), card
->info
.mcl_level
);
1494 static struct qeth_card
*qeth_alloc_card(void)
1496 struct qeth_card
*card
;
1498 QETH_DBF_TEXT(SETUP
, 2, "alloccrd");
1499 card
= kzalloc(sizeof(struct qeth_card
), GFP_DMA
|GFP_KERNEL
);
1502 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
1503 card
->ip_tbd_list
= kzalloc(sizeof(struct list_head
), GFP_KERNEL
);
1504 if (!card
->ip_tbd_list
) {
1505 QETH_DBF_TEXT(SETUP
, 0, "iptbdnom");
1508 if (qeth_setup_channel(&card
->read
))
1510 if (qeth_setup_channel(&card
->write
))
1512 card
->options
.layer2
= -1;
1513 card
->qeth_service_level
.seq_print
= qeth_core_sl_print
;
1514 register_service_level(&card
->qeth_service_level
);
1518 qeth_clean_channel(&card
->read
);
1520 kfree(card
->ip_tbd_list
);
1527 static int qeth_determine_card_type(struct qeth_card
*card
)
1531 QETH_DBF_TEXT(SETUP
, 2, "detcdtyp");
1533 card
->qdio
.do_prio_queueing
= QETH_PRIOQ_DEFAULT
;
1534 card
->qdio
.default_out_queue
= QETH_DEFAULT_QUEUE
;
1535 while (known_devices
[i
][QETH_DEV_MODEL_IND
]) {
1536 if ((CARD_RDEV(card
)->id
.dev_type
==
1537 known_devices
[i
][QETH_DEV_TYPE_IND
]) &&
1538 (CARD_RDEV(card
)->id
.dev_model
==
1539 known_devices
[i
][QETH_DEV_MODEL_IND
])) {
1540 card
->info
.type
= known_devices
[i
][QETH_DEV_MODEL_IND
];
1541 card
->qdio
.no_out_queues
=
1542 known_devices
[i
][QETH_QUEUE_NO_IND
];
1543 card
->qdio
.no_in_queues
= 1;
1544 card
->info
.is_multicast_different
=
1545 known_devices
[i
][QETH_MULTICAST_IND
];
1546 qeth_update_from_chp_desc(card
);
1551 card
->info
.type
= QETH_CARD_TYPE_UNKNOWN
;
1552 dev_err(&card
->gdev
->dev
, "The adapter hardware is of an "
1557 static int qeth_clear_channel(struct qeth_channel
*channel
)
1559 unsigned long flags
;
1560 struct qeth_card
*card
;
1563 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1564 QETH_CARD_TEXT(card
, 3, "clearch");
1565 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1566 rc
= ccw_device_clear(channel
->ccwdev
, QETH_CLEAR_CHANNEL_PARM
);
1567 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1571 rc
= wait_event_interruptible_timeout(card
->wait_q
,
1572 channel
->state
== CH_STATE_STOPPED
, QETH_TIMEOUT
);
1573 if (rc
== -ERESTARTSYS
)
1575 if (channel
->state
!= CH_STATE_STOPPED
)
1577 channel
->state
= CH_STATE_DOWN
;
1581 static int qeth_halt_channel(struct qeth_channel
*channel
)
1583 unsigned long flags
;
1584 struct qeth_card
*card
;
1587 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1588 QETH_CARD_TEXT(card
, 3, "haltch");
1589 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1590 rc
= ccw_device_halt(channel
->ccwdev
, QETH_HALT_CHANNEL_PARM
);
1591 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1595 rc
= wait_event_interruptible_timeout(card
->wait_q
,
1596 channel
->state
== CH_STATE_HALTED
, QETH_TIMEOUT
);
1597 if (rc
== -ERESTARTSYS
)
1599 if (channel
->state
!= CH_STATE_HALTED
)
1604 static int qeth_halt_channels(struct qeth_card
*card
)
1606 int rc1
= 0, rc2
= 0, rc3
= 0;
1608 QETH_CARD_TEXT(card
, 3, "haltchs");
1609 rc1
= qeth_halt_channel(&card
->read
);
1610 rc2
= qeth_halt_channel(&card
->write
);
1611 rc3
= qeth_halt_channel(&card
->data
);
1619 static int qeth_clear_channels(struct qeth_card
*card
)
1621 int rc1
= 0, rc2
= 0, rc3
= 0;
1623 QETH_CARD_TEXT(card
, 3, "clearchs");
1624 rc1
= qeth_clear_channel(&card
->read
);
1625 rc2
= qeth_clear_channel(&card
->write
);
1626 rc3
= qeth_clear_channel(&card
->data
);
1634 static int qeth_clear_halt_card(struct qeth_card
*card
, int halt
)
1638 QETH_CARD_TEXT(card
, 3, "clhacrd");
1641 rc
= qeth_halt_channels(card
);
1644 return qeth_clear_channels(card
);
1647 int qeth_qdio_clear_card(struct qeth_card
*card
, int use_halt
)
1651 QETH_CARD_TEXT(card
, 3, "qdioclr");
1652 switch (atomic_cmpxchg(&card
->qdio
.state
, QETH_QDIO_ESTABLISHED
,
1653 QETH_QDIO_CLEANING
)) {
1654 case QETH_QDIO_ESTABLISHED
:
1655 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
1656 rc
= qdio_shutdown(CARD_DDEV(card
),
1657 QDIO_FLAG_CLEANUP_USING_HALT
);
1659 rc
= qdio_shutdown(CARD_DDEV(card
),
1660 QDIO_FLAG_CLEANUP_USING_CLEAR
);
1662 QETH_CARD_TEXT_(card
, 3, "1err%d", rc
);
1663 qdio_free(CARD_DDEV(card
));
1664 atomic_set(&card
->qdio
.state
, QETH_QDIO_ALLOCATED
);
1666 case QETH_QDIO_CLEANING
:
1671 rc
= qeth_clear_halt_card(card
, use_halt
);
1673 QETH_CARD_TEXT_(card
, 3, "2err%d", rc
);
1674 card
->state
= CARD_STATE_DOWN
;
1677 EXPORT_SYMBOL_GPL(qeth_qdio_clear_card
);
1679 static int qeth_read_conf_data(struct qeth_card
*card
, void **buffer
,
1685 struct qeth_channel
*channel
= &card
->data
;
1686 unsigned long flags
;
1689 * scan for RCD command in extended SenseID data
1691 ciw
= ccw_device_get_ciw(channel
->ccwdev
, CIW_TYPE_RCD
);
1692 if (!ciw
|| ciw
->cmd
== 0)
1694 rcd_buf
= kzalloc(ciw
->count
, GFP_KERNEL
| GFP_DMA
);
1698 channel
->ccw
.cmd_code
= ciw
->cmd
;
1699 channel
->ccw
.cda
= (__u32
) __pa(rcd_buf
);
1700 channel
->ccw
.count
= ciw
->count
;
1701 channel
->ccw
.flags
= CCW_FLAG_SLI
;
1702 channel
->state
= CH_STATE_RCD
;
1703 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1704 ret
= ccw_device_start_timeout(channel
->ccwdev
, &channel
->ccw
,
1705 QETH_RCD_PARM
, LPM_ANYPATH
, 0,
1707 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1709 wait_event(card
->wait_q
,
1710 (channel
->state
== CH_STATE_RCD_DONE
||
1711 channel
->state
== CH_STATE_DOWN
));
1712 if (channel
->state
== CH_STATE_DOWN
)
1715 channel
->state
= CH_STATE_DOWN
;
1721 *length
= ciw
->count
;
1727 static void qeth_configure_unitaddr(struct qeth_card
*card
, char *prcd
)
1729 QETH_DBF_TEXT(SETUP
, 2, "cfgunit");
1730 card
->info
.chpid
= prcd
[30];
1731 card
->info
.unit_addr2
= prcd
[31];
1732 card
->info
.cula
= prcd
[63];
1733 card
->info
.guestlan
= ((prcd
[0x10] == _ascebc
['V']) &&
1734 (prcd
[0x11] == _ascebc
['M']));
1737 static void qeth_configure_blkt_default(struct qeth_card
*card
, char *prcd
)
1739 QETH_DBF_TEXT(SETUP
, 2, "cfgblkt");
1741 if (prcd
[74] == 0xF0 && prcd
[75] == 0xF0 &&
1742 prcd
[76] >= 0xF1 && prcd
[76] <= 0xF4) {
1743 card
->info
.blkt
.time_total
= 0;
1744 card
->info
.blkt
.inter_packet
= 0;
1745 card
->info
.blkt
.inter_packet_jumbo
= 0;
1747 card
->info
.blkt
.time_total
= 250;
1748 card
->info
.blkt
.inter_packet
= 5;
1749 card
->info
.blkt
.inter_packet_jumbo
= 15;
1753 static void qeth_init_tokens(struct qeth_card
*card
)
1755 card
->token
.issuer_rm_w
= 0x00010103UL
;
1756 card
->token
.cm_filter_w
= 0x00010108UL
;
1757 card
->token
.cm_connection_w
= 0x0001010aUL
;
1758 card
->token
.ulp_filter_w
= 0x0001010bUL
;
1759 card
->token
.ulp_connection_w
= 0x0001010dUL
;
1762 static void qeth_init_func_level(struct qeth_card
*card
)
1764 switch (card
->info
.type
) {
1765 case QETH_CARD_TYPE_IQD
:
1766 card
->info
.func_level
= QETH_IDX_FUNC_LEVEL_IQD
;
1768 case QETH_CARD_TYPE_OSD
:
1769 case QETH_CARD_TYPE_OSN
:
1770 card
->info
.func_level
= QETH_IDX_FUNC_LEVEL_OSD
;
1777 static int qeth_idx_activate_get_answer(struct qeth_channel
*channel
,
1778 void (*idx_reply_cb
)(struct qeth_channel
*,
1779 struct qeth_cmd_buffer
*))
1781 struct qeth_cmd_buffer
*iob
;
1782 unsigned long flags
;
1784 struct qeth_card
*card
;
1786 QETH_DBF_TEXT(SETUP
, 2, "idxanswr");
1787 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1788 iob
= qeth_get_buffer(channel
);
1789 iob
->callback
= idx_reply_cb
;
1790 memcpy(&channel
->ccw
, READ_CCW
, sizeof(struct ccw1
));
1791 channel
->ccw
.count
= QETH_BUFSIZE
;
1792 channel
->ccw
.cda
= (__u32
) __pa(iob
->data
);
1794 wait_event(card
->wait_q
,
1795 atomic_cmpxchg(&channel
->irq_pending
, 0, 1) == 0);
1796 QETH_DBF_TEXT(SETUP
, 6, "noirqpnd");
1797 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1798 rc
= ccw_device_start(channel
->ccwdev
,
1799 &channel
->ccw
, (addr_t
) iob
, 0, 0);
1800 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1803 QETH_DBF_MESSAGE(2, "Error2 in activating channel rc=%d\n", rc
);
1804 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
1805 atomic_set(&channel
->irq_pending
, 0);
1806 wake_up(&card
->wait_q
);
1809 rc
= wait_event_interruptible_timeout(card
->wait_q
,
1810 channel
->state
== CH_STATE_UP
, QETH_TIMEOUT
);
1811 if (rc
== -ERESTARTSYS
)
1813 if (channel
->state
!= CH_STATE_UP
) {
1815 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
1816 qeth_clear_cmd_buffers(channel
);
1822 static int qeth_idx_activate_channel(struct qeth_channel
*channel
,
1823 void (*idx_reply_cb
)(struct qeth_channel
*,
1824 struct qeth_cmd_buffer
*))
1826 struct qeth_card
*card
;
1827 struct qeth_cmd_buffer
*iob
;
1828 unsigned long flags
;
1832 struct ccw_dev_id temp_devid
;
1834 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1836 QETH_DBF_TEXT(SETUP
, 2, "idxactch");
1838 iob
= qeth_get_buffer(channel
);
1839 iob
->callback
= idx_reply_cb
;
1840 memcpy(&channel
->ccw
, WRITE_CCW
, sizeof(struct ccw1
));
1841 channel
->ccw
.count
= IDX_ACTIVATE_SIZE
;
1842 channel
->ccw
.cda
= (__u32
) __pa(iob
->data
);
1843 if (channel
== &card
->write
) {
1844 memcpy(iob
->data
, IDX_ACTIVATE_WRITE
, IDX_ACTIVATE_SIZE
);
1845 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob
->data
),
1846 &card
->seqno
.trans_hdr
, QETH_SEQ_NO_LENGTH
);
1847 card
->seqno
.trans_hdr
++;
1849 memcpy(iob
->data
, IDX_ACTIVATE_READ
, IDX_ACTIVATE_SIZE
);
1850 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob
->data
),
1851 &card
->seqno
.trans_hdr
, QETH_SEQ_NO_LENGTH
);
1853 tmp
= ((__u8
)card
->info
.portno
) | 0x80;
1854 memcpy(QETH_IDX_ACT_PNO(iob
->data
), &tmp
, 1);
1855 memcpy(QETH_IDX_ACT_ISSUER_RM_TOKEN(iob
->data
),
1856 &card
->token
.issuer_rm_w
, QETH_MPC_TOKEN_LENGTH
);
1857 memcpy(QETH_IDX_ACT_FUNC_LEVEL(iob
->data
),
1858 &card
->info
.func_level
, sizeof(__u16
));
1859 ccw_device_get_id(CARD_DDEV(card
), &temp_devid
);
1860 memcpy(QETH_IDX_ACT_QDIO_DEV_CUA(iob
->data
), &temp_devid
.devno
, 2);
1861 temp
= (card
->info
.cula
<< 8) + card
->info
.unit_addr2
;
1862 memcpy(QETH_IDX_ACT_QDIO_DEV_REALADDR(iob
->data
), &temp
, 2);
1864 wait_event(card
->wait_q
,
1865 atomic_cmpxchg(&channel
->irq_pending
, 0, 1) == 0);
1866 QETH_DBF_TEXT(SETUP
, 6, "noirqpnd");
1867 spin_lock_irqsave(get_ccwdev_lock(channel
->ccwdev
), flags
);
1868 rc
= ccw_device_start(channel
->ccwdev
,
1869 &channel
->ccw
, (addr_t
) iob
, 0, 0);
1870 spin_unlock_irqrestore(get_ccwdev_lock(channel
->ccwdev
), flags
);
1873 QETH_DBF_MESSAGE(2, "Error1 in activating channel. rc=%d\n",
1875 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
1876 atomic_set(&channel
->irq_pending
, 0);
1877 wake_up(&card
->wait_q
);
1880 rc
= wait_event_interruptible_timeout(card
->wait_q
,
1881 channel
->state
== CH_STATE_ACTIVATING
, QETH_TIMEOUT
);
1882 if (rc
== -ERESTARTSYS
)
1884 if (channel
->state
!= CH_STATE_ACTIVATING
) {
1885 dev_warn(&channel
->ccwdev
->dev
, "The qeth device driver"
1886 " failed to recover an error on the device\n");
1887 QETH_DBF_MESSAGE(2, "%s IDX activate timed out\n",
1888 dev_name(&channel
->ccwdev
->dev
));
1889 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", -ETIME
);
1890 qeth_clear_cmd_buffers(channel
);
1893 return qeth_idx_activate_get_answer(channel
, idx_reply_cb
);
1896 static int qeth_peer_func_level(int level
)
1898 if ((level
& 0xff) == 8)
1899 return (level
& 0xff) + 0x400;
1900 if (((level
>> 8) & 3) == 1)
1901 return (level
& 0xff) + 0x200;
1905 static void qeth_idx_write_cb(struct qeth_channel
*channel
,
1906 struct qeth_cmd_buffer
*iob
)
1908 struct qeth_card
*card
;
1911 QETH_DBF_TEXT(SETUP
, 2, "idxwrcb");
1913 if (channel
->state
== CH_STATE_DOWN
) {
1914 channel
->state
= CH_STATE_ACTIVATING
;
1917 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1919 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob
->data
))) {
1920 if (QETH_IDX_ACT_CAUSE_CODE(iob
->data
) == QETH_IDX_ACT_ERR_EXCL
)
1921 dev_err(&card
->write
.ccwdev
->dev
,
1922 "The adapter is used exclusively by another "
1925 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on write channel:"
1926 " negative reply\n",
1927 dev_name(&card
->write
.ccwdev
->dev
));
1930 memcpy(&temp
, QETH_IDX_ACT_FUNC_LEVEL(iob
->data
), 2);
1931 if ((temp
& ~0x0100) != qeth_peer_func_level(card
->info
.func_level
)) {
1932 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on write channel: "
1933 "function level mismatch (sent: 0x%x, received: "
1934 "0x%x)\n", dev_name(&card
->write
.ccwdev
->dev
),
1935 card
->info
.func_level
, temp
);
1938 channel
->state
= CH_STATE_UP
;
1940 qeth_release_buffer(channel
, iob
);
1943 static void qeth_idx_read_cb(struct qeth_channel
*channel
,
1944 struct qeth_cmd_buffer
*iob
)
1946 struct qeth_card
*card
;
1949 QETH_DBF_TEXT(SETUP
, 2, "idxrdcb");
1950 if (channel
->state
== CH_STATE_DOWN
) {
1951 channel
->state
= CH_STATE_ACTIVATING
;
1955 card
= CARD_FROM_CDEV(channel
->ccwdev
);
1956 if (qeth_check_idx_response(card
, iob
->data
))
1959 if (!(QETH_IS_IDX_ACT_POS_REPLY(iob
->data
))) {
1960 switch (QETH_IDX_ACT_CAUSE_CODE(iob
->data
)) {
1961 case QETH_IDX_ACT_ERR_EXCL
:
1962 dev_err(&card
->write
.ccwdev
->dev
,
1963 "The adapter is used exclusively by another "
1966 case QETH_IDX_ACT_ERR_AUTH
:
1967 case QETH_IDX_ACT_ERR_AUTH_USER
:
1968 dev_err(&card
->read
.ccwdev
->dev
,
1969 "Setting the device online failed because of "
1970 "insufficient authorization\n");
1973 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on read channel:"
1974 " negative reply\n",
1975 dev_name(&card
->read
.ccwdev
->dev
));
1977 QETH_CARD_TEXT_(card
, 2, "idxread%c",
1978 QETH_IDX_ACT_CAUSE_CODE(iob
->data
));
1983 * * temporary fix for microcode bug
1984 * * to revert it,replace OR by AND
1986 if ((!QETH_IDX_NO_PORTNAME_REQUIRED(iob
->data
)) ||
1987 (card
->info
.type
== QETH_CARD_TYPE_OSD
))
1988 card
->info
.portname_required
= 1;
1990 memcpy(&temp
, QETH_IDX_ACT_FUNC_LEVEL(iob
->data
), 2);
1991 if (temp
!= qeth_peer_func_level(card
->info
.func_level
)) {
1992 QETH_DBF_MESSAGE(2, "%s IDX_ACTIVATE on read channel: function "
1993 "level mismatch (sent: 0x%x, received: 0x%x)\n",
1994 dev_name(&card
->read
.ccwdev
->dev
),
1995 card
->info
.func_level
, temp
);
1998 memcpy(&card
->token
.issuer_rm_r
,
1999 QETH_IDX_ACT_ISSUER_RM_TOKEN(iob
->data
),
2000 QETH_MPC_TOKEN_LENGTH
);
2001 memcpy(&card
->info
.mcl_level
[0],
2002 QETH_IDX_REPLY_LEVEL(iob
->data
), QETH_MCL_LENGTH
);
2003 channel
->state
= CH_STATE_UP
;
2005 qeth_release_buffer(channel
, iob
);
2008 void qeth_prepare_control_data(struct qeth_card
*card
, int len
,
2009 struct qeth_cmd_buffer
*iob
)
2011 qeth_setup_ccw(&card
->write
, iob
->data
, len
);
2012 iob
->callback
= qeth_release_buffer
;
2014 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob
->data
),
2015 &card
->seqno
.trans_hdr
, QETH_SEQ_NO_LENGTH
);
2016 card
->seqno
.trans_hdr
++;
2017 memcpy(QETH_PDU_HEADER_SEQ_NO(iob
->data
),
2018 &card
->seqno
.pdu_hdr
, QETH_SEQ_NO_LENGTH
);
2019 card
->seqno
.pdu_hdr
++;
2020 memcpy(QETH_PDU_HEADER_ACK_SEQ_NO(iob
->data
),
2021 &card
->seqno
.pdu_hdr_ack
, QETH_SEQ_NO_LENGTH
);
2022 QETH_DBF_HEX(CTRL
, 2, iob
->data
, QETH_DBF_CTRL_LEN
);
2024 EXPORT_SYMBOL_GPL(qeth_prepare_control_data
);
2026 int qeth_send_control_data(struct qeth_card
*card
, int len
,
2027 struct qeth_cmd_buffer
*iob
,
2028 int (*reply_cb
)(struct qeth_card
*, struct qeth_reply
*,
2033 unsigned long flags
;
2034 struct qeth_reply
*reply
= NULL
;
2035 unsigned long timeout
, event_timeout
;
2036 struct qeth_ipa_cmd
*cmd
;
2038 QETH_CARD_TEXT(card
, 2, "sendctl");
2040 if (card
->read_or_write_problem
) {
2041 qeth_release_buffer(iob
->channel
, iob
);
2044 reply
= qeth_alloc_reply(card
);
2048 reply
->callback
= reply_cb
;
2049 reply
->param
= reply_param
;
2050 if (card
->state
== CARD_STATE_DOWN
)
2051 reply
->seqno
= QETH_IDX_COMMAND_SEQNO
;
2053 reply
->seqno
= card
->seqno
.ipa
++;
2054 init_waitqueue_head(&reply
->wait_q
);
2055 spin_lock_irqsave(&card
->lock
, flags
);
2056 list_add_tail(&reply
->list
, &card
->cmd_waiter_list
);
2057 spin_unlock_irqrestore(&card
->lock
, flags
);
2058 QETH_DBF_HEX(CTRL
, 2, iob
->data
, QETH_DBF_CTRL_LEN
);
2060 while (atomic_cmpxchg(&card
->write
.irq_pending
, 0, 1)) ;
2061 qeth_prepare_control_data(card
, len
, iob
);
2063 if (IS_IPA(iob
->data
))
2064 event_timeout
= QETH_IPA_TIMEOUT
;
2066 event_timeout
= QETH_TIMEOUT
;
2067 timeout
= jiffies
+ event_timeout
;
2069 QETH_CARD_TEXT(card
, 6, "noirqpnd");
2070 spin_lock_irqsave(get_ccwdev_lock(card
->write
.ccwdev
), flags
);
2071 rc
= ccw_device_start(card
->write
.ccwdev
, &card
->write
.ccw
,
2072 (addr_t
) iob
, 0, 0);
2073 spin_unlock_irqrestore(get_ccwdev_lock(card
->write
.ccwdev
), flags
);
2075 QETH_DBF_MESSAGE(2, "%s qeth_send_control_data: "
2076 "ccw_device_start rc = %i\n",
2077 dev_name(&card
->write
.ccwdev
->dev
), rc
);
2078 QETH_CARD_TEXT_(card
, 2, " err%d", rc
);
2079 spin_lock_irqsave(&card
->lock
, flags
);
2080 list_del_init(&reply
->list
);
2081 qeth_put_reply(reply
);
2082 spin_unlock_irqrestore(&card
->lock
, flags
);
2083 qeth_release_buffer(iob
->channel
, iob
);
2084 atomic_set(&card
->write
.irq_pending
, 0);
2085 wake_up(&card
->wait_q
);
2089 /* we have only one long running ipassist, since we can ensure
2090 process context of this command we can sleep */
2091 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
2092 if ((cmd
->hdr
.command
== IPA_CMD_SETIP
) &&
2093 (cmd
->hdr
.prot_version
== QETH_PROT_IPV4
)) {
2094 if (!wait_event_timeout(reply
->wait_q
,
2095 atomic_read(&reply
->received
), event_timeout
))
2098 while (!atomic_read(&reply
->received
)) {
2099 if (time_after(jiffies
, timeout
))
2105 if (reply
->rc
== -EIO
)
2108 qeth_put_reply(reply
);
2113 spin_lock_irqsave(&reply
->card
->lock
, flags
);
2114 list_del_init(&reply
->list
);
2115 spin_unlock_irqrestore(&reply
->card
->lock
, flags
);
2116 atomic_inc(&reply
->received
);
2118 atomic_set(&card
->write
.irq_pending
, 0);
2119 qeth_release_buffer(iob
->channel
, iob
);
2120 card
->write
.buf_no
= (card
->write
.buf_no
+ 1) % QETH_CMD_BUFFER_NO
;
2122 qeth_put_reply(reply
);
2125 EXPORT_SYMBOL_GPL(qeth_send_control_data
);
2127 static int qeth_cm_enable_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
2130 struct qeth_cmd_buffer
*iob
;
2132 QETH_DBF_TEXT(SETUP
, 2, "cmenblcb");
2134 iob
= (struct qeth_cmd_buffer
*) data
;
2135 memcpy(&card
->token
.cm_filter_r
,
2136 QETH_CM_ENABLE_RESP_FILTER_TOKEN(iob
->data
),
2137 QETH_MPC_TOKEN_LENGTH
);
2138 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
2142 static int qeth_cm_enable(struct qeth_card
*card
)
2145 struct qeth_cmd_buffer
*iob
;
2147 QETH_DBF_TEXT(SETUP
, 2, "cmenable");
2149 iob
= qeth_wait_for_buffer(&card
->write
);
2150 memcpy(iob
->data
, CM_ENABLE
, CM_ENABLE_SIZE
);
2151 memcpy(QETH_CM_ENABLE_ISSUER_RM_TOKEN(iob
->data
),
2152 &card
->token
.issuer_rm_r
, QETH_MPC_TOKEN_LENGTH
);
2153 memcpy(QETH_CM_ENABLE_FILTER_TOKEN(iob
->data
),
2154 &card
->token
.cm_filter_w
, QETH_MPC_TOKEN_LENGTH
);
2156 rc
= qeth_send_control_data(card
, CM_ENABLE_SIZE
, iob
,
2157 qeth_cm_enable_cb
, NULL
);
2161 static int qeth_cm_setup_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
2165 struct qeth_cmd_buffer
*iob
;
2167 QETH_DBF_TEXT(SETUP
, 2, "cmsetpcb");
2169 iob
= (struct qeth_cmd_buffer
*) data
;
2170 memcpy(&card
->token
.cm_connection_r
,
2171 QETH_CM_SETUP_RESP_DEST_ADDR(iob
->data
),
2172 QETH_MPC_TOKEN_LENGTH
);
2173 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
2177 static int qeth_cm_setup(struct qeth_card
*card
)
2180 struct qeth_cmd_buffer
*iob
;
2182 QETH_DBF_TEXT(SETUP
, 2, "cmsetup");
2184 iob
= qeth_wait_for_buffer(&card
->write
);
2185 memcpy(iob
->data
, CM_SETUP
, CM_SETUP_SIZE
);
2186 memcpy(QETH_CM_SETUP_DEST_ADDR(iob
->data
),
2187 &card
->token
.issuer_rm_r
, QETH_MPC_TOKEN_LENGTH
);
2188 memcpy(QETH_CM_SETUP_CONNECTION_TOKEN(iob
->data
),
2189 &card
->token
.cm_connection_w
, QETH_MPC_TOKEN_LENGTH
);
2190 memcpy(QETH_CM_SETUP_FILTER_TOKEN(iob
->data
),
2191 &card
->token
.cm_filter_r
, QETH_MPC_TOKEN_LENGTH
);
2192 rc
= qeth_send_control_data(card
, CM_SETUP_SIZE
, iob
,
2193 qeth_cm_setup_cb
, NULL
);
2198 static inline int qeth_get_initial_mtu_for_card(struct qeth_card
*card
)
2200 switch (card
->info
.type
) {
2201 case QETH_CARD_TYPE_UNKNOWN
:
2203 case QETH_CARD_TYPE_IQD
:
2204 return card
->info
.max_mtu
;
2205 case QETH_CARD_TYPE_OSD
:
2206 switch (card
->info
.link_type
) {
2207 case QETH_LINK_TYPE_HSTR
:
2208 case QETH_LINK_TYPE_LANE_TR
:
2211 return card
->options
.layer2
? 1500 : 1492;
2213 case QETH_CARD_TYPE_OSM
:
2214 case QETH_CARD_TYPE_OSX
:
2215 return card
->options
.layer2
? 1500 : 1492;
2221 static inline int qeth_get_mtu_outof_framesize(int framesize
)
2223 switch (framesize
) {
2237 static inline int qeth_mtu_is_valid(struct qeth_card
*card
, int mtu
)
2239 switch (card
->info
.type
) {
2240 case QETH_CARD_TYPE_OSD
:
2241 case QETH_CARD_TYPE_OSM
:
2242 case QETH_CARD_TYPE_OSX
:
2243 case QETH_CARD_TYPE_IQD
:
2244 return ((mtu
>= 576) &&
2245 (mtu
<= card
->info
.max_mtu
));
2246 case QETH_CARD_TYPE_OSN
:
2247 case QETH_CARD_TYPE_UNKNOWN
:
2253 static int qeth_ulp_enable_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
2257 __u16 mtu
, framesize
;
2260 struct qeth_cmd_buffer
*iob
;
2262 QETH_DBF_TEXT(SETUP
, 2, "ulpenacb");
2264 iob
= (struct qeth_cmd_buffer
*) data
;
2265 memcpy(&card
->token
.ulp_filter_r
,
2266 QETH_ULP_ENABLE_RESP_FILTER_TOKEN(iob
->data
),
2267 QETH_MPC_TOKEN_LENGTH
);
2268 if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
2269 memcpy(&framesize
, QETH_ULP_ENABLE_RESP_MAX_MTU(iob
->data
), 2);
2270 mtu
= qeth_get_mtu_outof_framesize(framesize
);
2273 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
2276 if (card
->info
.initial_mtu
&& (card
->info
.initial_mtu
!= mtu
)) {
2277 /* frame size has changed */
2279 ((card
->dev
->mtu
== card
->info
.initial_mtu
) ||
2280 (card
->dev
->mtu
> mtu
)))
2281 card
->dev
->mtu
= mtu
;
2282 qeth_free_qdio_buffers(card
);
2284 card
->info
.initial_mtu
= mtu
;
2285 card
->info
.max_mtu
= mtu
;
2286 card
->qdio
.in_buf_size
= mtu
+ 2 * PAGE_SIZE
;
2288 card
->info
.max_mtu
= *(__u16
*)QETH_ULP_ENABLE_RESP_MAX_MTU(
2290 card
->info
.initial_mtu
= min(card
->info
.max_mtu
,
2291 qeth_get_initial_mtu_for_card(card
));
2292 card
->qdio
.in_buf_size
= QETH_IN_BUF_SIZE_DEFAULT
;
2295 memcpy(&len
, QETH_ULP_ENABLE_RESP_DIFINFO_LEN(iob
->data
), 2);
2296 if (len
>= QETH_MPC_DIFINFO_LEN_INDICATES_LINK_TYPE
) {
2298 QETH_ULP_ENABLE_RESP_LINK_TYPE(iob
->data
), 1);
2299 card
->info
.link_type
= link_type
;
2301 card
->info
.link_type
= 0;
2302 QETH_DBF_TEXT_(SETUP
, 2, "link%d", card
->info
.link_type
);
2303 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
2307 static int qeth_ulp_enable(struct qeth_card
*card
)
2311 struct qeth_cmd_buffer
*iob
;
2313 /*FIXME: trace view callbacks*/
2314 QETH_DBF_TEXT(SETUP
, 2, "ulpenabl");
2316 iob
= qeth_wait_for_buffer(&card
->write
);
2317 memcpy(iob
->data
, ULP_ENABLE
, ULP_ENABLE_SIZE
);
2319 *(QETH_ULP_ENABLE_LINKNUM(iob
->data
)) =
2320 (__u8
) card
->info
.portno
;
2321 if (card
->options
.layer2
)
2322 if (card
->info
.type
== QETH_CARD_TYPE_OSN
)
2323 prot_type
= QETH_PROT_OSN2
;
2325 prot_type
= QETH_PROT_LAYER2
;
2327 prot_type
= QETH_PROT_TCPIP
;
2329 memcpy(QETH_ULP_ENABLE_PROT_TYPE(iob
->data
), &prot_type
, 1);
2330 memcpy(QETH_ULP_ENABLE_DEST_ADDR(iob
->data
),
2331 &card
->token
.cm_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2332 memcpy(QETH_ULP_ENABLE_FILTER_TOKEN(iob
->data
),
2333 &card
->token
.ulp_filter_w
, QETH_MPC_TOKEN_LENGTH
);
2334 memcpy(QETH_ULP_ENABLE_PORTNAME_AND_LL(iob
->data
),
2335 card
->info
.portname
, 9);
2336 rc
= qeth_send_control_data(card
, ULP_ENABLE_SIZE
, iob
,
2337 qeth_ulp_enable_cb
, NULL
);
2342 static int qeth_ulp_setup_cb(struct qeth_card
*card
, struct qeth_reply
*reply
,
2345 struct qeth_cmd_buffer
*iob
;
2347 QETH_DBF_TEXT(SETUP
, 2, "ulpstpcb");
2349 iob
= (struct qeth_cmd_buffer
*) data
;
2350 memcpy(&card
->token
.ulp_connection_r
,
2351 QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob
->data
),
2352 QETH_MPC_TOKEN_LENGTH
);
2353 if (!strncmp("00S", QETH_ULP_SETUP_RESP_CONNECTION_TOKEN(iob
->data
),
2355 QETH_DBF_TEXT(SETUP
, 2, "olmlimit");
2356 dev_err(&card
->gdev
->dev
, "A connection could not be "
2357 "established because of an OLM limit\n");
2360 QETH_DBF_TEXT_(SETUP
, 2, " rc%d", iob
->rc
);
2364 static int qeth_ulp_setup(struct qeth_card
*card
)
2368 struct qeth_cmd_buffer
*iob
;
2369 struct ccw_dev_id dev_id
;
2371 QETH_DBF_TEXT(SETUP
, 2, "ulpsetup");
2373 iob
= qeth_wait_for_buffer(&card
->write
);
2374 memcpy(iob
->data
, ULP_SETUP
, ULP_SETUP_SIZE
);
2376 memcpy(QETH_ULP_SETUP_DEST_ADDR(iob
->data
),
2377 &card
->token
.cm_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2378 memcpy(QETH_ULP_SETUP_CONNECTION_TOKEN(iob
->data
),
2379 &card
->token
.ulp_connection_w
, QETH_MPC_TOKEN_LENGTH
);
2380 memcpy(QETH_ULP_SETUP_FILTER_TOKEN(iob
->data
),
2381 &card
->token
.ulp_filter_r
, QETH_MPC_TOKEN_LENGTH
);
2383 ccw_device_get_id(CARD_DDEV(card
), &dev_id
);
2384 memcpy(QETH_ULP_SETUP_CUA(iob
->data
), &dev_id
.devno
, 2);
2385 temp
= (card
->info
.cula
<< 8) + card
->info
.unit_addr2
;
2386 memcpy(QETH_ULP_SETUP_REAL_DEVADDR(iob
->data
), &temp
, 2);
2387 rc
= qeth_send_control_data(card
, ULP_SETUP_SIZE
, iob
,
2388 qeth_ulp_setup_cb
, NULL
);
2392 static int qeth_init_qdio_out_buf(struct qeth_qdio_out_q
*q
, int bidx
)
2395 struct qeth_qdio_out_buffer
*newbuf
;
2398 newbuf
= kmem_cache_zalloc(qeth_qdio_outbuf_cache
, GFP_ATOMIC
);
2403 newbuf
->buffer
= &q
->qdio_bufs
[bidx
];
2404 skb_queue_head_init(&newbuf
->skb_list
);
2405 lockdep_set_class(&newbuf
->skb_list
.lock
, &qdio_out_skb_queue_key
);
2408 newbuf
->next_pending
= q
->bufs
[bidx
];
2409 atomic_set(&newbuf
->state
, QETH_QDIO_BUF_EMPTY
);
2410 q
->bufs
[bidx
] = newbuf
;
2412 q
->bufstates
[bidx
].user
= newbuf
;
2413 QETH_CARD_TEXT_(q
->card
, 2, "nbs%d", bidx
);
2414 QETH_CARD_TEXT_(q
->card
, 2, "%lx", (long) newbuf
);
2415 QETH_CARD_TEXT_(q
->card
, 2, "%lx",
2416 (long) newbuf
->next_pending
);
2423 static int qeth_alloc_qdio_buffers(struct qeth_card
*card
)
2427 QETH_DBF_TEXT(SETUP
, 2, "allcqdbf");
2429 if (atomic_cmpxchg(&card
->qdio
.state
, QETH_QDIO_UNINITIALIZED
,
2430 QETH_QDIO_ALLOCATED
) != QETH_QDIO_UNINITIALIZED
)
2433 card
->qdio
.in_q
= kzalloc(sizeof(struct qeth_qdio_q
),
2435 if (!card
->qdio
.in_q
)
2437 QETH_DBF_TEXT(SETUP
, 2, "inq");
2438 QETH_DBF_HEX(SETUP
, 2, &card
->qdio
.in_q
, sizeof(void *));
2439 memset(card
->qdio
.in_q
, 0, sizeof(struct qeth_qdio_q
));
2440 /* give inbound qeth_qdio_buffers their qdio_buffers */
2441 for (i
= 0; i
< QDIO_MAX_BUFFERS_PER_Q
; ++i
) {
2442 card
->qdio
.in_q
->bufs
[i
].buffer
=
2443 &card
->qdio
.in_q
->qdio_bufs
[i
];
2444 card
->qdio
.in_q
->bufs
[i
].rx_skb
= NULL
;
2446 /* inbound buffer pool */
2447 if (qeth_alloc_buffer_pool(card
))
2452 kzalloc(card
->qdio
.no_out_queues
*
2453 sizeof(struct qeth_qdio_out_q
*), GFP_KERNEL
);
2454 if (!card
->qdio
.out_qs
)
2456 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
2457 card
->qdio
.out_qs
[i
] = kzalloc(sizeof(struct qeth_qdio_out_q
),
2459 if (!card
->qdio
.out_qs
[i
])
2461 QETH_DBF_TEXT_(SETUP
, 2, "outq %i", i
);
2462 QETH_DBF_HEX(SETUP
, 2, &card
->qdio
.out_qs
[i
], sizeof(void *));
2463 card
->qdio
.out_qs
[i
]->queue_no
= i
;
2464 /* give outbound qeth_qdio_buffers their qdio_buffers */
2465 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
) {
2466 WARN_ON(card
->qdio
.out_qs
[i
]->bufs
[j
] != NULL
);
2467 if (qeth_init_qdio_out_buf(card
->qdio
.out_qs
[i
], j
))
2468 goto out_freeoutqbufs
;
2473 if (qeth_alloc_cq(card
))
2481 kmem_cache_free(qeth_qdio_outbuf_cache
,
2482 card
->qdio
.out_qs
[i
]->bufs
[j
]);
2483 card
->qdio
.out_qs
[i
]->bufs
[j
] = NULL
;
2487 kfree(card
->qdio
.out_qs
[--i
]);
2488 qeth_clear_outq_buffers(card
->qdio
.out_qs
[i
], 1);
2490 kfree(card
->qdio
.out_qs
);
2491 card
->qdio
.out_qs
= NULL
;
2493 qeth_free_buffer_pool(card
);
2495 kfree(card
->qdio
.in_q
);
2496 card
->qdio
.in_q
= NULL
;
2498 atomic_set(&card
->qdio
.state
, QETH_QDIO_UNINITIALIZED
);
2502 static void qeth_create_qib_param_field(struct qeth_card
*card
,
2506 param_field
[0] = _ascebc
['P'];
2507 param_field
[1] = _ascebc
['C'];
2508 param_field
[2] = _ascebc
['I'];
2509 param_field
[3] = _ascebc
['T'];
2510 *((unsigned int *) (¶m_field
[4])) = QETH_PCI_THRESHOLD_A(card
);
2511 *((unsigned int *) (¶m_field
[8])) = QETH_PCI_THRESHOLD_B(card
);
2512 *((unsigned int *) (¶m_field
[12])) = QETH_PCI_TIMER_VALUE(card
);
2515 static void qeth_create_qib_param_field_blkt(struct qeth_card
*card
,
2518 param_field
[16] = _ascebc
['B'];
2519 param_field
[17] = _ascebc
['L'];
2520 param_field
[18] = _ascebc
['K'];
2521 param_field
[19] = _ascebc
['T'];
2522 *((unsigned int *) (¶m_field
[20])) = card
->info
.blkt
.time_total
;
2523 *((unsigned int *) (¶m_field
[24])) = card
->info
.blkt
.inter_packet
;
2524 *((unsigned int *) (¶m_field
[28])) =
2525 card
->info
.blkt
.inter_packet_jumbo
;
2528 static int qeth_qdio_activate(struct qeth_card
*card
)
2530 QETH_DBF_TEXT(SETUP
, 3, "qdioact");
2531 return qdio_activate(CARD_DDEV(card
));
2534 static int qeth_dm_act(struct qeth_card
*card
)
2537 struct qeth_cmd_buffer
*iob
;
2539 QETH_DBF_TEXT(SETUP
, 2, "dmact");
2541 iob
= qeth_wait_for_buffer(&card
->write
);
2542 memcpy(iob
->data
, DM_ACT
, DM_ACT_SIZE
);
2544 memcpy(QETH_DM_ACT_DEST_ADDR(iob
->data
),
2545 &card
->token
.cm_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2546 memcpy(QETH_DM_ACT_CONNECTION_TOKEN(iob
->data
),
2547 &card
->token
.ulp_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2548 rc
= qeth_send_control_data(card
, DM_ACT_SIZE
, iob
, NULL
, NULL
);
2552 static int qeth_mpc_initialize(struct qeth_card
*card
)
2556 QETH_DBF_TEXT(SETUP
, 2, "mpcinit");
2558 rc
= qeth_issue_next_read(card
);
2560 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
2563 rc
= qeth_cm_enable(card
);
2565 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
2568 rc
= qeth_cm_setup(card
);
2570 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
2573 rc
= qeth_ulp_enable(card
);
2575 QETH_DBF_TEXT_(SETUP
, 2, "4err%d", rc
);
2578 rc
= qeth_ulp_setup(card
);
2580 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
2583 rc
= qeth_alloc_qdio_buffers(card
);
2585 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
2588 rc
= qeth_qdio_establish(card
);
2590 QETH_DBF_TEXT_(SETUP
, 2, "6err%d", rc
);
2591 qeth_free_qdio_buffers(card
);
2594 rc
= qeth_qdio_activate(card
);
2596 QETH_DBF_TEXT_(SETUP
, 2, "7err%d", rc
);
2599 rc
= qeth_dm_act(card
);
2601 QETH_DBF_TEXT_(SETUP
, 2, "8err%d", rc
);
2607 qeth_qdio_clear_card(card
, card
->info
.type
!= QETH_CARD_TYPE_IQD
);
2611 static void qeth_print_status_with_portname(struct qeth_card
*card
)
2616 sprintf(dbf_text
, "%s", card
->info
.portname
+ 1);
2617 for (i
= 0; i
< 8; i
++)
2619 (char) _ebcasc
[(__u8
) dbf_text
[i
]];
2621 dev_info(&card
->gdev
->dev
, "Device is a%s card%s%s%s\n"
2622 "with link type %s (portname: %s)\n",
2623 qeth_get_cardname(card
),
2624 (card
->info
.mcl_level
[0]) ? " (level: " : "",
2625 (card
->info
.mcl_level
[0]) ? card
->info
.mcl_level
: "",
2626 (card
->info
.mcl_level
[0]) ? ")" : "",
2627 qeth_get_cardname_short(card
),
2632 static void qeth_print_status_no_portname(struct qeth_card
*card
)
2634 if (card
->info
.portname
[0])
2635 dev_info(&card
->gdev
->dev
, "Device is a%s "
2636 "card%s%s%s\nwith link type %s "
2637 "(no portname needed by interface).\n",
2638 qeth_get_cardname(card
),
2639 (card
->info
.mcl_level
[0]) ? " (level: " : "",
2640 (card
->info
.mcl_level
[0]) ? card
->info
.mcl_level
: "",
2641 (card
->info
.mcl_level
[0]) ? ")" : "",
2642 qeth_get_cardname_short(card
));
2644 dev_info(&card
->gdev
->dev
, "Device is a%s "
2645 "card%s%s%s\nwith link type %s.\n",
2646 qeth_get_cardname(card
),
2647 (card
->info
.mcl_level
[0]) ? " (level: " : "",
2648 (card
->info
.mcl_level
[0]) ? card
->info
.mcl_level
: "",
2649 (card
->info
.mcl_level
[0]) ? ")" : "",
2650 qeth_get_cardname_short(card
));
2653 void qeth_print_status_message(struct qeth_card
*card
)
2655 switch (card
->info
.type
) {
2656 case QETH_CARD_TYPE_OSD
:
2657 case QETH_CARD_TYPE_OSM
:
2658 case QETH_CARD_TYPE_OSX
:
2659 /* VM will use a non-zero first character
2660 * to indicate a HiperSockets like reporting
2661 * of the level OSA sets the first character to zero
2663 if (!card
->info
.mcl_level
[0]) {
2664 sprintf(card
->info
.mcl_level
, "%02x%02x",
2665 card
->info
.mcl_level
[2],
2666 card
->info
.mcl_level
[3]);
2668 card
->info
.mcl_level
[QETH_MCL_LENGTH
] = 0;
2672 case QETH_CARD_TYPE_IQD
:
2673 if ((card
->info
.guestlan
) ||
2674 (card
->info
.mcl_level
[0] & 0x80)) {
2675 card
->info
.mcl_level
[0] = (char) _ebcasc
[(__u8
)
2676 card
->info
.mcl_level
[0]];
2677 card
->info
.mcl_level
[1] = (char) _ebcasc
[(__u8
)
2678 card
->info
.mcl_level
[1]];
2679 card
->info
.mcl_level
[2] = (char) _ebcasc
[(__u8
)
2680 card
->info
.mcl_level
[2]];
2681 card
->info
.mcl_level
[3] = (char) _ebcasc
[(__u8
)
2682 card
->info
.mcl_level
[3]];
2683 card
->info
.mcl_level
[QETH_MCL_LENGTH
] = 0;
2687 memset(&card
->info
.mcl_level
[0], 0, QETH_MCL_LENGTH
+ 1);
2689 if (card
->info
.portname_required
)
2690 qeth_print_status_with_portname(card
);
2692 qeth_print_status_no_portname(card
);
2694 EXPORT_SYMBOL_GPL(qeth_print_status_message
);
2696 static void qeth_initialize_working_pool_list(struct qeth_card
*card
)
2698 struct qeth_buffer_pool_entry
*entry
;
2700 QETH_CARD_TEXT(card
, 5, "inwrklst");
2702 list_for_each_entry(entry
,
2703 &card
->qdio
.init_pool
.entry_list
, init_list
) {
2704 qeth_put_buffer_pool_entry(card
, entry
);
2708 static inline struct qeth_buffer_pool_entry
*qeth_find_free_buffer_pool_entry(
2709 struct qeth_card
*card
)
2711 struct list_head
*plh
;
2712 struct qeth_buffer_pool_entry
*entry
;
2716 if (list_empty(&card
->qdio
.in_buf_pool
.entry_list
))
2719 list_for_each(plh
, &card
->qdio
.in_buf_pool
.entry_list
) {
2720 entry
= list_entry(plh
, struct qeth_buffer_pool_entry
, list
);
2722 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(card
); ++i
) {
2723 if (page_count(virt_to_page(entry
->elements
[i
])) > 1) {
2729 list_del_init(&entry
->list
);
2734 /* no free buffer in pool so take first one and swap pages */
2735 entry
= list_entry(card
->qdio
.in_buf_pool
.entry_list
.next
,
2736 struct qeth_buffer_pool_entry
, list
);
2737 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(card
); ++i
) {
2738 if (page_count(virt_to_page(entry
->elements
[i
])) > 1) {
2739 page
= alloc_page(GFP_ATOMIC
);
2743 free_page((unsigned long)entry
->elements
[i
]);
2744 entry
->elements
[i
] = page_address(page
);
2745 if (card
->options
.performance_stats
)
2746 card
->perf_stats
.sg_alloc_page_rx
++;
2750 list_del_init(&entry
->list
);
2754 static int qeth_init_input_buffer(struct qeth_card
*card
,
2755 struct qeth_qdio_buffer
*buf
)
2757 struct qeth_buffer_pool_entry
*pool_entry
;
2760 if ((card
->options
.cq
== QETH_CQ_ENABLED
) && (!buf
->rx_skb
)) {
2761 buf
->rx_skb
= dev_alloc_skb(QETH_RX_PULL_LEN
+ ETH_HLEN
);
2766 pool_entry
= qeth_find_free_buffer_pool_entry(card
);
2771 * since the buffer is accessed only from the input_tasklet
2772 * there shouldn't be a need to synchronize; also, since we use
2773 * the QETH_IN_BUF_REQUEUE_THRESHOLD we should never run out off
2777 buf
->pool_entry
= pool_entry
;
2778 for (i
= 0; i
< QETH_MAX_BUFFER_ELEMENTS(card
); ++i
) {
2779 buf
->buffer
->element
[i
].length
= PAGE_SIZE
;
2780 buf
->buffer
->element
[i
].addr
= pool_entry
->elements
[i
];
2781 if (i
== QETH_MAX_BUFFER_ELEMENTS(card
) - 1)
2782 buf
->buffer
->element
[i
].eflags
= SBAL_EFLAGS_LAST_ENTRY
;
2784 buf
->buffer
->element
[i
].eflags
= 0;
2785 buf
->buffer
->element
[i
].sflags
= 0;
2790 int qeth_init_qdio_queues(struct qeth_card
*card
)
2795 QETH_DBF_TEXT(SETUP
, 2, "initqdqs");
2798 memset(card
->qdio
.in_q
->qdio_bufs
, 0,
2799 QDIO_MAX_BUFFERS_PER_Q
* sizeof(struct qdio_buffer
));
2800 qeth_initialize_working_pool_list(card
);
2801 /*give only as many buffers to hardware as we have buffer pool entries*/
2802 for (i
= 0; i
< card
->qdio
.in_buf_pool
.buf_count
- 1; ++i
)
2803 qeth_init_input_buffer(card
, &card
->qdio
.in_q
->bufs
[i
]);
2804 card
->qdio
.in_q
->next_buf_to_init
=
2805 card
->qdio
.in_buf_pool
.buf_count
- 1;
2806 rc
= do_QDIO(CARD_DDEV(card
), QDIO_FLAG_SYNC_INPUT
, 0, 0,
2807 card
->qdio
.in_buf_pool
.buf_count
- 1);
2809 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
2814 rc
= qeth_cq_init(card
);
2819 /* outbound queue */
2820 for (i
= 0; i
< card
->qdio
.no_out_queues
; ++i
) {
2821 memset(card
->qdio
.out_qs
[i
]->qdio_bufs
, 0,
2822 QDIO_MAX_BUFFERS_PER_Q
* sizeof(struct qdio_buffer
));
2823 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
) {
2824 qeth_clear_output_buffer(card
->qdio
.out_qs
[i
],
2825 card
->qdio
.out_qs
[i
]->bufs
[j
],
2826 QETH_QDIO_BUF_EMPTY
);
2828 card
->qdio
.out_qs
[i
]->card
= card
;
2829 card
->qdio
.out_qs
[i
]->next_buf_to_fill
= 0;
2830 card
->qdio
.out_qs
[i
]->do_pack
= 0;
2831 atomic_set(&card
->qdio
.out_qs
[i
]->used_buffers
, 0);
2832 atomic_set(&card
->qdio
.out_qs
[i
]->set_pci_flags_count
, 0);
2833 atomic_set(&card
->qdio
.out_qs
[i
]->state
,
2834 QETH_OUT_Q_UNLOCKED
);
2838 EXPORT_SYMBOL_GPL(qeth_init_qdio_queues
);
2840 static inline __u8
qeth_get_ipa_adp_type(enum qeth_link_types link_type
)
2842 switch (link_type
) {
2843 case QETH_LINK_TYPE_HSTR
:
2850 static void qeth_fill_ipacmd_header(struct qeth_card
*card
,
2851 struct qeth_ipa_cmd
*cmd
, __u8 command
,
2852 enum qeth_prot_versions prot
)
2854 memset(cmd
, 0, sizeof(struct qeth_ipa_cmd
));
2855 cmd
->hdr
.command
= command
;
2856 cmd
->hdr
.initiator
= IPA_CMD_INITIATOR_HOST
;
2857 cmd
->hdr
.seqno
= card
->seqno
.ipa
;
2858 cmd
->hdr
.adapter_type
= qeth_get_ipa_adp_type(card
->info
.link_type
);
2859 cmd
->hdr
.rel_adapter_no
= (__u8
) card
->info
.portno
;
2860 if (card
->options
.layer2
)
2861 cmd
->hdr
.prim_version_no
= 2;
2863 cmd
->hdr
.prim_version_no
= 1;
2864 cmd
->hdr
.param_count
= 1;
2865 cmd
->hdr
.prot_version
= prot
;
2866 cmd
->hdr
.ipa_supported
= 0;
2867 cmd
->hdr
.ipa_enabled
= 0;
2870 struct qeth_cmd_buffer
*qeth_get_ipacmd_buffer(struct qeth_card
*card
,
2871 enum qeth_ipa_cmds ipacmd
, enum qeth_prot_versions prot
)
2873 struct qeth_cmd_buffer
*iob
;
2874 struct qeth_ipa_cmd
*cmd
;
2876 iob
= qeth_wait_for_buffer(&card
->write
);
2877 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
2878 qeth_fill_ipacmd_header(card
, cmd
, ipacmd
, prot
);
2882 EXPORT_SYMBOL_GPL(qeth_get_ipacmd_buffer
);
2884 void qeth_prepare_ipa_cmd(struct qeth_card
*card
, struct qeth_cmd_buffer
*iob
,
2887 memcpy(iob
->data
, IPA_PDU_HEADER
, IPA_PDU_HEADER_SIZE
);
2888 memcpy(QETH_IPA_CMD_PROT_TYPE(iob
->data
), &prot_type
, 1);
2889 memcpy(QETH_IPA_CMD_DEST_ADDR(iob
->data
),
2890 &card
->token
.ulp_connection_r
, QETH_MPC_TOKEN_LENGTH
);
2892 EXPORT_SYMBOL_GPL(qeth_prepare_ipa_cmd
);
2894 int qeth_send_ipa_cmd(struct qeth_card
*card
, struct qeth_cmd_buffer
*iob
,
2895 int (*reply_cb
)(struct qeth_card
*, struct qeth_reply
*,
2902 QETH_CARD_TEXT(card
, 4, "sendipa");
2904 if (card
->options
.layer2
)
2905 if (card
->info
.type
== QETH_CARD_TYPE_OSN
)
2906 prot_type
= QETH_PROT_OSN2
;
2908 prot_type
= QETH_PROT_LAYER2
;
2910 prot_type
= QETH_PROT_TCPIP
;
2911 qeth_prepare_ipa_cmd(card
, iob
, prot_type
);
2912 rc
= qeth_send_control_data(card
, IPA_CMD_LENGTH
,
2913 iob
, reply_cb
, reply_param
);
2915 qeth_clear_ipacmd_list(card
);
2916 qeth_schedule_recovery(card
);
2920 EXPORT_SYMBOL_GPL(qeth_send_ipa_cmd
);
2922 int qeth_send_startlan(struct qeth_card
*card
)
2925 struct qeth_cmd_buffer
*iob
;
2927 QETH_DBF_TEXT(SETUP
, 2, "strtlan");
2929 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_STARTLAN
, 0);
2930 rc
= qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
2933 EXPORT_SYMBOL_GPL(qeth_send_startlan
);
2935 static int qeth_default_setadapterparms_cb(struct qeth_card
*card
,
2936 struct qeth_reply
*reply
, unsigned long data
)
2938 struct qeth_ipa_cmd
*cmd
;
2940 QETH_CARD_TEXT(card
, 4, "defadpcb");
2942 cmd
= (struct qeth_ipa_cmd
*) data
;
2943 if (cmd
->hdr
.return_code
== 0)
2944 cmd
->hdr
.return_code
=
2945 cmd
->data
.setadapterparms
.hdr
.return_code
;
2949 static int qeth_query_setadapterparms_cb(struct qeth_card
*card
,
2950 struct qeth_reply
*reply
, unsigned long data
)
2952 struct qeth_ipa_cmd
*cmd
;
2954 QETH_CARD_TEXT(card
, 3, "quyadpcb");
2956 cmd
= (struct qeth_ipa_cmd
*) data
;
2957 if (cmd
->data
.setadapterparms
.data
.query_cmds_supp
.lan_type
& 0x7f) {
2958 card
->info
.link_type
=
2959 cmd
->data
.setadapterparms
.data
.query_cmds_supp
.lan_type
;
2960 QETH_DBF_TEXT_(SETUP
, 2, "lnk %d", card
->info
.link_type
);
2962 card
->options
.adp
.supported_funcs
=
2963 cmd
->data
.setadapterparms
.data
.query_cmds_supp
.supported_cmds
;
2964 return qeth_default_setadapterparms_cb(card
, reply
, (unsigned long)cmd
);
2967 static struct qeth_cmd_buffer
*qeth_get_adapter_cmd(struct qeth_card
*card
,
2968 __u32 command
, __u32 cmdlen
)
2970 struct qeth_cmd_buffer
*iob
;
2971 struct qeth_ipa_cmd
*cmd
;
2973 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SETADAPTERPARMS
,
2975 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
2976 cmd
->data
.setadapterparms
.hdr
.cmdlength
= cmdlen
;
2977 cmd
->data
.setadapterparms
.hdr
.command_code
= command
;
2978 cmd
->data
.setadapterparms
.hdr
.used_total
= 1;
2979 cmd
->data
.setadapterparms
.hdr
.seq_no
= 1;
2984 int qeth_query_setadapterparms(struct qeth_card
*card
)
2987 struct qeth_cmd_buffer
*iob
;
2989 QETH_CARD_TEXT(card
, 3, "queryadp");
2990 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_QUERY_COMMANDS_SUPPORTED
,
2991 sizeof(struct qeth_ipacmd_setadpparms
));
2992 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_query_setadapterparms_cb
, NULL
);
2995 EXPORT_SYMBOL_GPL(qeth_query_setadapterparms
);
2997 static int qeth_query_ipassists_cb(struct qeth_card
*card
,
2998 struct qeth_reply
*reply
, unsigned long data
)
3000 struct qeth_ipa_cmd
*cmd
;
3002 QETH_DBF_TEXT(SETUP
, 2, "qipasscb");
3004 cmd
= (struct qeth_ipa_cmd
*) data
;
3006 switch (cmd
->hdr
.return_code
) {
3007 case IPA_RC_NOTSUPP
:
3008 case IPA_RC_L2_UNSUPPORTED_CMD
:
3009 QETH_DBF_TEXT(SETUP
, 2, "ipaunsup");
3010 card
->options
.ipa4
.supported_funcs
|= IPA_SETADAPTERPARMS
;
3011 card
->options
.ipa6
.supported_funcs
|= IPA_SETADAPTERPARMS
;
3014 if (cmd
->hdr
.return_code
) {
3015 QETH_DBF_MESSAGE(1, "%s IPA_CMD_QIPASSIST: Unhandled "
3017 dev_name(&card
->gdev
->dev
),
3018 cmd
->hdr
.return_code
);
3023 if (cmd
->hdr
.prot_version
== QETH_PROT_IPV4
) {
3024 card
->options
.ipa4
.supported_funcs
= cmd
->hdr
.ipa_supported
;
3025 card
->options
.ipa4
.enabled_funcs
= cmd
->hdr
.ipa_enabled
;
3026 } else if (cmd
->hdr
.prot_version
== QETH_PROT_IPV6
) {
3027 card
->options
.ipa6
.supported_funcs
= cmd
->hdr
.ipa_supported
;
3028 card
->options
.ipa6
.enabled_funcs
= cmd
->hdr
.ipa_enabled
;
3030 QETH_DBF_MESSAGE(1, "%s IPA_CMD_QIPASSIST: Flawed LIC detected"
3031 "\n", dev_name(&card
->gdev
->dev
));
3035 int qeth_query_ipassists(struct qeth_card
*card
, enum qeth_prot_versions prot
)
3038 struct qeth_cmd_buffer
*iob
;
3040 QETH_DBF_TEXT_(SETUP
, 2, "qipassi%i", prot
);
3041 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_QIPASSIST
, prot
);
3042 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_query_ipassists_cb
, NULL
);
3045 EXPORT_SYMBOL_GPL(qeth_query_ipassists
);
3047 static int qeth_query_setdiagass_cb(struct qeth_card
*card
,
3048 struct qeth_reply
*reply
, unsigned long data
)
3050 struct qeth_ipa_cmd
*cmd
;
3053 cmd
= (struct qeth_ipa_cmd
*)data
;
3054 rc
= cmd
->hdr
.return_code
;
3056 QETH_CARD_TEXT_(card
, 2, "diagq:%x", rc
);
3058 card
->info
.diagass_support
= cmd
->data
.diagass
.ext
;
3062 static int qeth_query_setdiagass(struct qeth_card
*card
)
3064 struct qeth_cmd_buffer
*iob
;
3065 struct qeth_ipa_cmd
*cmd
;
3067 QETH_DBF_TEXT(SETUP
, 2, "qdiagass");
3068 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SET_DIAG_ASS
, 0);
3069 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
3070 cmd
->data
.diagass
.subcmd_len
= 16;
3071 cmd
->data
.diagass
.subcmd
= QETH_DIAGS_CMD_QUERY
;
3072 return qeth_send_ipa_cmd(card
, iob
, qeth_query_setdiagass_cb
, NULL
);
3075 static void qeth_get_trap_id(struct qeth_card
*card
, struct qeth_trap_id
*tid
)
3077 unsigned long info
= get_zeroed_page(GFP_KERNEL
);
3078 struct sysinfo_2_2_2
*info222
= (struct sysinfo_2_2_2
*)info
;
3079 struct sysinfo_3_2_2
*info322
= (struct sysinfo_3_2_2
*)info
;
3080 struct ccw_dev_id ccwid
;
3083 tid
->chpid
= card
->info
.chpid
;
3084 ccw_device_get_id(CARD_RDEV(card
), &ccwid
);
3085 tid
->ssid
= ccwid
.ssid
;
3086 tid
->devno
= ccwid
.devno
;
3089 level
= stsi(NULL
, 0, 0, 0);
3090 if ((level
>= 2) && (stsi(info222
, 2, 2, 2) == 0))
3091 tid
->lparnr
= info222
->lpar_number
;
3092 if ((level
>= 3) && (stsi(info322
, 3, 2, 2) == 0)) {
3093 EBCASC(info322
->vm
[0].name
, sizeof(info322
->vm
[0].name
));
3094 memcpy(tid
->vmname
, info322
->vm
[0].name
, sizeof(tid
->vmname
));
3100 static int qeth_hw_trap_cb(struct qeth_card
*card
,
3101 struct qeth_reply
*reply
, unsigned long data
)
3103 struct qeth_ipa_cmd
*cmd
;
3106 cmd
= (struct qeth_ipa_cmd
*)data
;
3107 rc
= cmd
->hdr
.return_code
;
3109 QETH_CARD_TEXT_(card
, 2, "trapc:%x", rc
);
3113 int qeth_hw_trap(struct qeth_card
*card
, enum qeth_diags_trap_action action
)
3115 struct qeth_cmd_buffer
*iob
;
3116 struct qeth_ipa_cmd
*cmd
;
3118 QETH_DBF_TEXT(SETUP
, 2, "diagtrap");
3119 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_SET_DIAG_ASS
, 0);
3120 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
3121 cmd
->data
.diagass
.subcmd_len
= 80;
3122 cmd
->data
.diagass
.subcmd
= QETH_DIAGS_CMD_TRAP
;
3123 cmd
->data
.diagass
.type
= 1;
3124 cmd
->data
.diagass
.action
= action
;
3126 case QETH_DIAGS_TRAP_ARM
:
3127 cmd
->data
.diagass
.options
= 0x0003;
3128 cmd
->data
.diagass
.ext
= 0x00010000 +
3129 sizeof(struct qeth_trap_id
);
3130 qeth_get_trap_id(card
,
3131 (struct qeth_trap_id
*)cmd
->data
.diagass
.cdata
);
3133 case QETH_DIAGS_TRAP_DISARM
:
3134 cmd
->data
.diagass
.options
= 0x0001;
3136 case QETH_DIAGS_TRAP_CAPTURE
:
3139 return qeth_send_ipa_cmd(card
, iob
, qeth_hw_trap_cb
, NULL
);
3141 EXPORT_SYMBOL_GPL(qeth_hw_trap
);
3143 int qeth_check_qdio_errors(struct qeth_card
*card
, struct qdio_buffer
*buf
,
3144 unsigned int qdio_error
, const char *dbftext
)
3147 QETH_CARD_TEXT(card
, 2, dbftext
);
3148 QETH_CARD_TEXT_(card
, 2, " F15=%02X",
3149 buf
->element
[15].sflags
);
3150 QETH_CARD_TEXT_(card
, 2, " F14=%02X",
3151 buf
->element
[14].sflags
);
3152 QETH_CARD_TEXT_(card
, 2, " qerr=%X", qdio_error
);
3153 if ((buf
->element
[15].sflags
) == 0x12) {
3154 card
->stats
.rx_dropped
++;
3161 EXPORT_SYMBOL_GPL(qeth_check_qdio_errors
);
3163 void qeth_buffer_reclaim_work(struct work_struct
*work
)
3165 struct qeth_card
*card
= container_of(work
, struct qeth_card
,
3166 buffer_reclaim_work
.work
);
3168 QETH_CARD_TEXT_(card
, 2, "brw:%x", card
->reclaim_index
);
3169 qeth_queue_input_buffer(card
, card
->reclaim_index
);
3172 void qeth_queue_input_buffer(struct qeth_card
*card
, int index
)
3174 struct qeth_qdio_q
*queue
= card
->qdio
.in_q
;
3175 struct list_head
*lh
;
3181 count
= (index
< queue
->next_buf_to_init
)?
3182 card
->qdio
.in_buf_pool
.buf_count
-
3183 (queue
->next_buf_to_init
- index
) :
3184 card
->qdio
.in_buf_pool
.buf_count
-
3185 (queue
->next_buf_to_init
+ QDIO_MAX_BUFFERS_PER_Q
- index
);
3186 /* only requeue at a certain threshold to avoid SIGAs */
3187 if (count
>= QETH_IN_BUF_REQUEUE_THRESHOLD(card
)) {
3188 for (i
= queue
->next_buf_to_init
;
3189 i
< queue
->next_buf_to_init
+ count
; ++i
) {
3190 if (qeth_init_input_buffer(card
,
3191 &queue
->bufs
[i
% QDIO_MAX_BUFFERS_PER_Q
])) {
3198 if (newcount
< count
) {
3199 /* we are in memory shortage so we switch back to
3200 traditional skb allocation and drop packages */
3201 atomic_set(&card
->force_alloc_skb
, 3);
3204 atomic_add_unless(&card
->force_alloc_skb
, -1, 0);
3209 list_for_each(lh
, &card
->qdio
.in_buf_pool
.entry_list
)
3211 if (i
== card
->qdio
.in_buf_pool
.buf_count
) {
3212 QETH_CARD_TEXT(card
, 2, "qsarbw");
3213 card
->reclaim_index
= index
;
3214 schedule_delayed_work(
3215 &card
->buffer_reclaim_work
,
3216 QETH_RECLAIM_WORK_TIME
);
3222 * according to old code it should be avoided to requeue all
3223 * 128 buffers in order to benefit from PCI avoidance.
3224 * this function keeps at least one buffer (the buffer at
3225 * 'index') un-requeued -> this buffer is the first buffer that
3226 * will be requeued the next time
3228 if (card
->options
.performance_stats
) {
3229 card
->perf_stats
.inbound_do_qdio_cnt
++;
3230 card
->perf_stats
.inbound_do_qdio_start_time
=
3233 rc
= do_QDIO(CARD_DDEV(card
), QDIO_FLAG_SYNC_INPUT
, 0,
3234 queue
->next_buf_to_init
, count
);
3235 if (card
->options
.performance_stats
)
3236 card
->perf_stats
.inbound_do_qdio_time
+=
3238 card
->perf_stats
.inbound_do_qdio_start_time
;
3240 QETH_CARD_TEXT(card
, 2, "qinberr");
3242 queue
->next_buf_to_init
= (queue
->next_buf_to_init
+ count
) %
3243 QDIO_MAX_BUFFERS_PER_Q
;
3246 EXPORT_SYMBOL_GPL(qeth_queue_input_buffer
);
3248 static int qeth_handle_send_error(struct qeth_card
*card
,
3249 struct qeth_qdio_out_buffer
*buffer
, unsigned int qdio_err
)
3251 int sbalf15
= buffer
->buffer
->element
[15].sflags
;
3253 QETH_CARD_TEXT(card
, 6, "hdsnderr");
3254 if (card
->info
.type
== QETH_CARD_TYPE_IQD
) {
3261 qeth_check_qdio_errors(card
, buffer
->buffer
, qdio_err
, "qouterr");
3264 return QETH_SEND_ERROR_NONE
;
3266 if ((sbalf15
>= 15) && (sbalf15
<= 31))
3267 return QETH_SEND_ERROR_RETRY
;
3269 QETH_CARD_TEXT(card
, 1, "lnkfail");
3270 QETH_CARD_TEXT_(card
, 1, "%04x %02x",
3271 (u16
)qdio_err
, (u8
)sbalf15
);
3272 return QETH_SEND_ERROR_LINK_FAILURE
;
3276 * Switched to packing state if the number of used buffers on a queue
3277 * reaches a certain limit.
3279 static void qeth_switch_to_packing_if_needed(struct qeth_qdio_out_q
*queue
)
3281 if (!queue
->do_pack
) {
3282 if (atomic_read(&queue
->used_buffers
)
3283 >= QETH_HIGH_WATERMARK_PACK
){
3284 /* switch non-PACKING -> PACKING */
3285 QETH_CARD_TEXT(queue
->card
, 6, "np->pack");
3286 if (queue
->card
->options
.performance_stats
)
3287 queue
->card
->perf_stats
.sc_dp_p
++;
3294 * Switches from packing to non-packing mode. If there is a packing
3295 * buffer on the queue this buffer will be prepared to be flushed.
3296 * In that case 1 is returned to inform the caller. If no buffer
3297 * has to be flushed, zero is returned.
3299 static int qeth_switch_to_nonpacking_if_needed(struct qeth_qdio_out_q
*queue
)
3301 struct qeth_qdio_out_buffer
*buffer
;
3302 int flush_count
= 0;
3304 if (queue
->do_pack
) {
3305 if (atomic_read(&queue
->used_buffers
)
3306 <= QETH_LOW_WATERMARK_PACK
) {
3307 /* switch PACKING -> non-PACKING */
3308 QETH_CARD_TEXT(queue
->card
, 6, "pack->np");
3309 if (queue
->card
->options
.performance_stats
)
3310 queue
->card
->perf_stats
.sc_p_dp
++;
3312 /* flush packing buffers */
3313 buffer
= queue
->bufs
[queue
->next_buf_to_fill
];
3314 if ((atomic_read(&buffer
->state
) ==
3315 QETH_QDIO_BUF_EMPTY
) &&
3316 (buffer
->next_element_to_fill
> 0)) {
3317 atomic_set(&buffer
->state
,
3318 QETH_QDIO_BUF_PRIMED
);
3320 queue
->next_buf_to_fill
=
3321 (queue
->next_buf_to_fill
+ 1) %
3322 QDIO_MAX_BUFFERS_PER_Q
;
3331 * Called to flush a packing buffer if no more pci flags are on the queue.
3332 * Checks if there is a packing buffer and prepares it to be flushed.
3333 * In that case returns 1, otherwise zero.
3335 static int qeth_flush_buffers_on_no_pci(struct qeth_qdio_out_q
*queue
)
3337 struct qeth_qdio_out_buffer
*buffer
;
3339 buffer
= queue
->bufs
[queue
->next_buf_to_fill
];
3340 if ((atomic_read(&buffer
->state
) == QETH_QDIO_BUF_EMPTY
) &&
3341 (buffer
->next_element_to_fill
> 0)) {
3342 /* it's a packing buffer */
3343 atomic_set(&buffer
->state
, QETH_QDIO_BUF_PRIMED
);
3344 queue
->next_buf_to_fill
=
3345 (queue
->next_buf_to_fill
+ 1) % QDIO_MAX_BUFFERS_PER_Q
;
3351 static void qeth_flush_buffers(struct qeth_qdio_out_q
*queue
, int index
,
3354 struct qeth_qdio_out_buffer
*buf
;
3357 unsigned int qdio_flags
;
3359 for (i
= index
; i
< index
+ count
; ++i
) {
3360 int bidx
= i
% QDIO_MAX_BUFFERS_PER_Q
;
3361 buf
= queue
->bufs
[bidx
];
3362 buf
->buffer
->element
[buf
->next_element_to_fill
- 1].eflags
|=
3363 SBAL_EFLAGS_LAST_ENTRY
;
3365 if (queue
->bufstates
)
3366 queue
->bufstates
[bidx
].user
= buf
;
3368 if (queue
->card
->info
.type
== QETH_CARD_TYPE_IQD
)
3371 if (!queue
->do_pack
) {
3372 if ((atomic_read(&queue
->used_buffers
) >=
3373 (QETH_HIGH_WATERMARK_PACK
-
3374 QETH_WATERMARK_PACK_FUZZ
)) &&
3375 !atomic_read(&queue
->set_pci_flags_count
)) {
3376 /* it's likely that we'll go to packing
3378 atomic_inc(&queue
->set_pci_flags_count
);
3379 buf
->buffer
->element
[0].sflags
|= SBAL_SFLAGS0_PCI_REQ
;
3382 if (!atomic_read(&queue
->set_pci_flags_count
)) {
3384 * there's no outstanding PCI any more, so we
3385 * have to request a PCI to be sure the the PCI
3386 * will wake at some time in the future then we
3387 * can flush packed buffers that might still be
3388 * hanging around, which can happen if no
3389 * further send was requested by the stack
3391 atomic_inc(&queue
->set_pci_flags_count
);
3392 buf
->buffer
->element
[0].sflags
|= SBAL_SFLAGS0_PCI_REQ
;
3397 queue
->card
->dev
->trans_start
= jiffies
;
3398 if (queue
->card
->options
.performance_stats
) {
3399 queue
->card
->perf_stats
.outbound_do_qdio_cnt
++;
3400 queue
->card
->perf_stats
.outbound_do_qdio_start_time
=
3403 qdio_flags
= QDIO_FLAG_SYNC_OUTPUT
;
3404 if (atomic_read(&queue
->set_pci_flags_count
))
3405 qdio_flags
|= QDIO_FLAG_PCI_OUT
;
3406 rc
= do_QDIO(CARD_DDEV(queue
->card
), qdio_flags
,
3407 queue
->queue_no
, index
, count
);
3408 if (queue
->card
->options
.performance_stats
)
3409 queue
->card
->perf_stats
.outbound_do_qdio_time
+=
3411 queue
->card
->perf_stats
.outbound_do_qdio_start_time
;
3412 atomic_add(count
, &queue
->used_buffers
);
3414 queue
->card
->stats
.tx_errors
+= count
;
3415 /* ignore temporary SIGA errors without busy condition */
3418 QETH_CARD_TEXT(queue
->card
, 2, "flushbuf");
3419 QETH_CARD_TEXT_(queue
->card
, 2, " q%d", queue
->queue_no
);
3420 QETH_CARD_TEXT_(queue
->card
, 2, " idx%d", index
);
3421 QETH_CARD_TEXT_(queue
->card
, 2, " c%d", count
);
3422 QETH_CARD_TEXT_(queue
->card
, 2, " err%d", rc
);
3424 /* this must not happen under normal circumstances. if it
3425 * happens something is really wrong -> recover */
3426 qeth_schedule_recovery(queue
->card
);
3429 if (queue
->card
->options
.performance_stats
)
3430 queue
->card
->perf_stats
.bufs_sent
+= count
;
3433 static void qeth_check_outbound_queue(struct qeth_qdio_out_q
*queue
)
3437 int q_was_packing
= 0;
3440 * check if weed have to switch to non-packing mode or if
3441 * we have to get a pci flag out on the queue
3443 if ((atomic_read(&queue
->used_buffers
) <= QETH_LOW_WATERMARK_PACK
) ||
3444 !atomic_read(&queue
->set_pci_flags_count
)) {
3445 if (atomic_xchg(&queue
->state
, QETH_OUT_Q_LOCKED_FLUSH
) ==
3446 QETH_OUT_Q_UNLOCKED
) {
3448 * If we get in here, there was no action in
3449 * do_send_packet. So, we check if there is a
3450 * packing buffer to be flushed here.
3452 netif_stop_queue(queue
->card
->dev
);
3453 index
= queue
->next_buf_to_fill
;
3454 q_was_packing
= queue
->do_pack
;
3455 /* queue->do_pack may change */
3457 flush_cnt
+= qeth_switch_to_nonpacking_if_needed(queue
);
3459 !atomic_read(&queue
->set_pci_flags_count
))
3461 qeth_flush_buffers_on_no_pci(queue
);
3462 if (queue
->card
->options
.performance_stats
&&
3464 queue
->card
->perf_stats
.bufs_sent_pack
+=
3467 qeth_flush_buffers(queue
, index
, flush_cnt
);
3468 atomic_set(&queue
->state
, QETH_OUT_Q_UNLOCKED
);
3473 void qeth_qdio_start_poll(struct ccw_device
*ccwdev
, int queue
,
3474 unsigned long card_ptr
)
3476 struct qeth_card
*card
= (struct qeth_card
*)card_ptr
;
3478 if (card
->dev
&& (card
->dev
->flags
& IFF_UP
))
3479 napi_schedule(&card
->napi
);
3481 EXPORT_SYMBOL_GPL(qeth_qdio_start_poll
);
3483 int qeth_configure_cq(struct qeth_card
*card
, enum qeth_cq cq
)
3487 if (card
->options
.cq
== QETH_CQ_NOTAVAILABLE
) {
3491 if (card
->options
.cq
== cq
) {
3496 if (card
->state
!= CARD_STATE_DOWN
&&
3497 card
->state
!= CARD_STATE_RECOVER
) {
3502 qeth_free_qdio_buffers(card
);
3503 card
->options
.cq
= cq
;
3510 EXPORT_SYMBOL_GPL(qeth_configure_cq
);
3513 static void qeth_qdio_cq_handler(struct qeth_card
*card
,
3514 unsigned int qdio_err
,
3515 unsigned int queue
, int first_element
, int count
) {
3516 struct qeth_qdio_q
*cq
= card
->qdio
.c_q
;
3520 if (!qeth_is_cq(card
, queue
))
3523 QETH_CARD_TEXT_(card
, 5, "qcqhe%d", first_element
);
3524 QETH_CARD_TEXT_(card
, 5, "qcqhc%d", count
);
3525 QETH_CARD_TEXT_(card
, 5, "qcqherr%d", qdio_err
);
3528 netif_stop_queue(card
->dev
);
3529 qeth_schedule_recovery(card
);
3533 if (card
->options
.performance_stats
) {
3534 card
->perf_stats
.cq_cnt
++;
3535 card
->perf_stats
.cq_start_time
= qeth_get_micros();
3538 for (i
= first_element
; i
< first_element
+ count
; ++i
) {
3539 int bidx
= i
% QDIO_MAX_BUFFERS_PER_Q
;
3540 struct qdio_buffer
*buffer
= &cq
->qdio_bufs
[bidx
];
3544 while (buffer
->element
[e
].addr
) {
3545 unsigned long phys_aob_addr
;
3547 phys_aob_addr
= (unsigned long) buffer
->element
[e
].addr
;
3548 qeth_qdio_handle_aob(card
, phys_aob_addr
);
3549 buffer
->element
[e
].addr
= NULL
;
3550 buffer
->element
[e
].eflags
= 0;
3551 buffer
->element
[e
].sflags
= 0;
3552 buffer
->element
[e
].length
= 0;
3557 buffer
->element
[15].eflags
= 0;
3558 buffer
->element
[15].sflags
= 0;
3560 rc
= do_QDIO(CARD_DDEV(card
), QDIO_FLAG_SYNC_INPUT
, queue
,
3561 card
->qdio
.c_q
->next_buf_to_init
,
3564 dev_warn(&card
->gdev
->dev
,
3565 "QDIO reported an error, rc=%i\n", rc
);
3566 QETH_CARD_TEXT(card
, 2, "qcqherr");
3568 card
->qdio
.c_q
->next_buf_to_init
= (card
->qdio
.c_q
->next_buf_to_init
3569 + count
) % QDIO_MAX_BUFFERS_PER_Q
;
3571 netif_wake_queue(card
->dev
);
3573 if (card
->options
.performance_stats
) {
3574 int delta_t
= qeth_get_micros();
3575 delta_t
-= card
->perf_stats
.cq_start_time
;
3576 card
->perf_stats
.cq_time
+= delta_t
;
3582 void qeth_qdio_input_handler(struct ccw_device
*ccwdev
, unsigned int qdio_err
,
3583 unsigned int queue
, int first_elem
, int count
,
3584 unsigned long card_ptr
)
3586 struct qeth_card
*card
= (struct qeth_card
*)card_ptr
;
3588 QETH_CARD_TEXT_(card
, 2, "qihq%d", queue
);
3589 QETH_CARD_TEXT_(card
, 2, "qiec%d", qdio_err
);
3591 if (qeth_is_cq(card
, queue
))
3592 qeth_qdio_cq_handler(card
, qdio_err
, queue
, first_elem
, count
);
3594 qeth_schedule_recovery(card
);
3598 EXPORT_SYMBOL_GPL(qeth_qdio_input_handler
);
3600 void qeth_qdio_output_handler(struct ccw_device
*ccwdev
,
3601 unsigned int qdio_error
, int __queue
, int first_element
,
3602 int count
, unsigned long card_ptr
)
3604 struct qeth_card
*card
= (struct qeth_card
*) card_ptr
;
3605 struct qeth_qdio_out_q
*queue
= card
->qdio
.out_qs
[__queue
];
3606 struct qeth_qdio_out_buffer
*buffer
;
3609 QETH_CARD_TEXT(card
, 6, "qdouhdl");
3610 if (qdio_error
& QDIO_ERROR_FATAL
) {
3611 QETH_CARD_TEXT(card
, 2, "achkcond");
3612 netif_stop_queue(card
->dev
);
3613 qeth_schedule_recovery(card
);
3616 if (card
->options
.performance_stats
) {
3617 card
->perf_stats
.outbound_handler_cnt
++;
3618 card
->perf_stats
.outbound_handler_start_time
=
3621 for (i
= first_element
; i
< (first_element
+ count
); ++i
) {
3622 int bidx
= i
% QDIO_MAX_BUFFERS_PER_Q
;
3623 buffer
= queue
->bufs
[bidx
];
3624 qeth_handle_send_error(card
, buffer
, qdio_error
);
3626 if (queue
->bufstates
&&
3627 (queue
->bufstates
[bidx
].flags
&
3628 QDIO_OUTBUF_STATE_FLAG_PENDING
) != 0) {
3629 WARN_ON_ONCE(card
->options
.cq
!= QETH_CQ_ENABLED
);
3631 if (atomic_cmpxchg(&buffer
->state
,
3632 QETH_QDIO_BUF_PRIMED
,
3633 QETH_QDIO_BUF_PENDING
) ==
3634 QETH_QDIO_BUF_PRIMED
) {
3635 qeth_notify_skbs(queue
, buffer
,
3638 buffer
->aob
= queue
->bufstates
[bidx
].aob
;
3639 QETH_CARD_TEXT_(queue
->card
, 5, "pel%d", bidx
);
3640 QETH_CARD_TEXT(queue
->card
, 5, "aob");
3641 QETH_CARD_TEXT_(queue
->card
, 5, "%lx",
3642 virt_to_phys(buffer
->aob
));
3643 if (qeth_init_qdio_out_buf(queue
, bidx
)) {
3644 QETH_CARD_TEXT(card
, 2, "outofbuf");
3645 qeth_schedule_recovery(card
);
3648 if (card
->options
.cq
== QETH_CQ_ENABLED
) {
3649 enum iucv_tx_notify n
;
3651 n
= qeth_compute_cq_notification(
3652 buffer
->buffer
->element
[15].sflags
, 0);
3653 qeth_notify_skbs(queue
, buffer
, n
);
3656 qeth_clear_output_buffer(queue
, buffer
,
3657 QETH_QDIO_BUF_EMPTY
);
3659 qeth_cleanup_handled_pending(queue
, bidx
, 0);
3661 atomic_sub(count
, &queue
->used_buffers
);
3662 /* check if we need to do something on this outbound queue */
3663 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
)
3664 qeth_check_outbound_queue(queue
);
3666 netif_wake_queue(queue
->card
->dev
);
3667 if (card
->options
.performance_stats
)
3668 card
->perf_stats
.outbound_handler_time
+= qeth_get_micros() -
3669 card
->perf_stats
.outbound_handler_start_time
;
3671 EXPORT_SYMBOL_GPL(qeth_qdio_output_handler
);
3673 int qeth_get_priority_queue(struct qeth_card
*card
, struct sk_buff
*skb
,
3674 int ipv
, int cast_type
)
3676 if (!ipv
&& (card
->info
.type
== QETH_CARD_TYPE_OSD
||
3677 card
->info
.type
== QETH_CARD_TYPE_OSX
))
3678 return card
->qdio
.default_out_queue
;
3679 switch (card
->qdio
.no_out_queues
) {
3681 if (cast_type
&& card
->info
.is_multicast_different
)
3682 return card
->info
.is_multicast_different
&
3683 (card
->qdio
.no_out_queues
- 1);
3684 if (card
->qdio
.do_prio_queueing
&& (ipv
== 4)) {
3685 const u8 tos
= ip_hdr(skb
)->tos
;
3687 if (card
->qdio
.do_prio_queueing
==
3688 QETH_PRIO_Q_ING_TOS
) {
3689 if (tos
& IP_TOS_NOTIMPORTANT
)
3691 if (tos
& IP_TOS_HIGHRELIABILITY
)
3693 if (tos
& IP_TOS_HIGHTHROUGHPUT
)
3695 if (tos
& IP_TOS_LOWDELAY
)
3698 if (card
->qdio
.do_prio_queueing
==
3699 QETH_PRIO_Q_ING_PREC
)
3700 return 3 - (tos
>> 6);
3701 } else if (card
->qdio
.do_prio_queueing
&& (ipv
== 6)) {
3704 return card
->qdio
.default_out_queue
;
3705 case 1: /* fallthrough for single-out-queue 1920-device */
3707 return card
->qdio
.default_out_queue
;
3710 EXPORT_SYMBOL_GPL(qeth_get_priority_queue
);
3712 int qeth_get_elements_for_frags(struct sk_buff
*skb
)
3714 int cnt
, length
, e
, elements
= 0;
3715 struct skb_frag_struct
*frag
;
3718 for (cnt
= 0; cnt
< skb_shinfo(skb
)->nr_frags
; cnt
++) {
3719 frag
= &skb_shinfo(skb
)->frags
[cnt
];
3720 data
= (char *)page_to_phys(skb_frag_page(frag
)) +
3722 length
= frag
->size
;
3723 e
= PFN_UP((unsigned long)data
+ length
- 1) -
3724 PFN_DOWN((unsigned long)data
);
3729 EXPORT_SYMBOL_GPL(qeth_get_elements_for_frags
);
3731 int qeth_get_elements_no(struct qeth_card
*card
,
3732 struct sk_buff
*skb
, int elems
)
3734 int dlen
= skb
->len
- skb
->data_len
;
3735 int elements_needed
= PFN_UP((unsigned long)skb
->data
+ dlen
- 1) -
3736 PFN_DOWN((unsigned long)skb
->data
);
3738 elements_needed
+= qeth_get_elements_for_frags(skb
);
3740 if ((elements_needed
+ elems
) > QETH_MAX_BUFFER_ELEMENTS(card
)) {
3741 QETH_DBF_MESSAGE(2, "Invalid size of IP packet "
3742 "(Number=%d / Length=%d). Discarded.\n",
3743 (elements_needed
+elems
), skb
->len
);
3746 return elements_needed
;
3748 EXPORT_SYMBOL_GPL(qeth_get_elements_no
);
3750 int qeth_hdr_chk_and_bounce(struct sk_buff
*skb
, struct qeth_hdr
**hdr
, int len
)
3752 int hroom
, inpage
, rest
;
3754 if (((unsigned long)skb
->data
& PAGE_MASK
) !=
3755 (((unsigned long)skb
->data
+ len
- 1) & PAGE_MASK
)) {
3756 hroom
= skb_headroom(skb
);
3757 inpage
= PAGE_SIZE
- ((unsigned long) skb
->data
% PAGE_SIZE
);
3758 rest
= len
- inpage
;
3761 memmove(skb
->data
- rest
, skb
->data
, skb
->len
- skb
->data_len
);
3764 *hdr
= (struct qeth_hdr
*)skb
->data
;
3765 QETH_DBF_MESSAGE(2, "skb bounce len: %d rest: %d\n", len
, rest
);
3769 EXPORT_SYMBOL_GPL(qeth_hdr_chk_and_bounce
);
3771 static inline void __qeth_fill_buffer(struct sk_buff
*skb
,
3772 struct qdio_buffer
*buffer
, int is_tso
, int *next_element_to_fill
,
3775 int length
= skb
->len
- skb
->data_len
;
3780 struct skb_frag_struct
*frag
;
3782 element
= *next_element_to_fill
;
3784 first_lap
= (is_tso
== 0 ? 1 : 0);
3787 data
= skb
->data
+ offset
;
3792 while (length
> 0) {
3793 /* length_here is the remaining amount of data in this page */
3794 length_here
= PAGE_SIZE
- ((unsigned long) data
% PAGE_SIZE
);
3795 if (length
< length_here
)
3796 length_here
= length
;
3798 buffer
->element
[element
].addr
= data
;
3799 buffer
->element
[element
].length
= length_here
;
3800 length
-= length_here
;
3803 if (skb_shinfo(skb
)->nr_frags
)
3804 buffer
->element
[element
].eflags
=
3805 SBAL_EFLAGS_FIRST_FRAG
;
3807 buffer
->element
[element
].eflags
= 0;
3809 buffer
->element
[element
].eflags
=
3810 SBAL_EFLAGS_MIDDLE_FRAG
;
3813 buffer
->element
[element
].eflags
=
3814 SBAL_EFLAGS_FIRST_FRAG
;
3816 buffer
->element
[element
].eflags
=
3817 SBAL_EFLAGS_MIDDLE_FRAG
;
3819 data
+= length_here
;
3824 for (cnt
= 0; cnt
< skb_shinfo(skb
)->nr_frags
; cnt
++) {
3825 frag
= &skb_shinfo(skb
)->frags
[cnt
];
3826 data
= (char *)page_to_phys(skb_frag_page(frag
)) +
3828 length
= frag
->size
;
3829 while (length
> 0) {
3830 length_here
= PAGE_SIZE
-
3831 ((unsigned long) data
% PAGE_SIZE
);
3832 if (length
< length_here
)
3833 length_here
= length
;
3835 buffer
->element
[element
].addr
= data
;
3836 buffer
->element
[element
].length
= length_here
;
3837 buffer
->element
[element
].eflags
=
3838 SBAL_EFLAGS_MIDDLE_FRAG
;
3839 length
-= length_here
;
3840 data
+= length_here
;
3845 if (buffer
->element
[element
- 1].eflags
)
3846 buffer
->element
[element
- 1].eflags
= SBAL_EFLAGS_LAST_FRAG
;
3847 *next_element_to_fill
= element
;
3850 static inline int qeth_fill_buffer(struct qeth_qdio_out_q
*queue
,
3851 struct qeth_qdio_out_buffer
*buf
, struct sk_buff
*skb
,
3852 struct qeth_hdr
*hdr
, int offset
, int hd_len
)
3854 struct qdio_buffer
*buffer
;
3855 int flush_cnt
= 0, hdr_len
, large_send
= 0;
3857 buffer
= buf
->buffer
;
3858 atomic_inc(&skb
->users
);
3859 skb_queue_tail(&buf
->skb_list
, skb
);
3861 /*check first on TSO ....*/
3862 if (hdr
->hdr
.l3
.id
== QETH_HEADER_TYPE_TSO
) {
3863 int element
= buf
->next_element_to_fill
;
3865 hdr_len
= sizeof(struct qeth_hdr_tso
) +
3866 ((struct qeth_hdr_tso
*)hdr
)->ext
.dg_hdr_len
;
3867 /*fill first buffer entry only with header information */
3868 buffer
->element
[element
].addr
= skb
->data
;
3869 buffer
->element
[element
].length
= hdr_len
;
3870 buffer
->element
[element
].eflags
= SBAL_EFLAGS_FIRST_FRAG
;
3871 buf
->next_element_to_fill
++;
3872 skb
->data
+= hdr_len
;
3873 skb
->len
-= hdr_len
;
3878 int element
= buf
->next_element_to_fill
;
3879 buffer
->element
[element
].addr
= hdr
;
3880 buffer
->element
[element
].length
= sizeof(struct qeth_hdr
) +
3882 buffer
->element
[element
].eflags
= SBAL_EFLAGS_FIRST_FRAG
;
3883 buf
->is_header
[element
] = 1;
3884 buf
->next_element_to_fill
++;
3887 __qeth_fill_buffer(skb
, buffer
, large_send
,
3888 (int *)&buf
->next_element_to_fill
, offset
);
3890 if (!queue
->do_pack
) {
3891 QETH_CARD_TEXT(queue
->card
, 6, "fillbfnp");
3892 /* set state to PRIMED -> will be flushed */
3893 atomic_set(&buf
->state
, QETH_QDIO_BUF_PRIMED
);
3896 QETH_CARD_TEXT(queue
->card
, 6, "fillbfpa");
3897 if (queue
->card
->options
.performance_stats
)
3898 queue
->card
->perf_stats
.skbs_sent_pack
++;
3899 if (buf
->next_element_to_fill
>=
3900 QETH_MAX_BUFFER_ELEMENTS(queue
->card
)) {
3902 * packed buffer if full -> set state PRIMED
3903 * -> will be flushed
3905 atomic_set(&buf
->state
, QETH_QDIO_BUF_PRIMED
);
3912 int qeth_do_send_packet_fast(struct qeth_card
*card
,
3913 struct qeth_qdio_out_q
*queue
, struct sk_buff
*skb
,
3914 struct qeth_hdr
*hdr
, int elements_needed
,
3915 int offset
, int hd_len
)
3917 struct qeth_qdio_out_buffer
*buffer
;
3920 /* spin until we get the queue ... */
3921 while (atomic_cmpxchg(&queue
->state
, QETH_OUT_Q_UNLOCKED
,
3922 QETH_OUT_Q_LOCKED
) != QETH_OUT_Q_UNLOCKED
);
3923 /* ... now we've got the queue */
3924 index
= queue
->next_buf_to_fill
;
3925 buffer
= queue
->bufs
[queue
->next_buf_to_fill
];
3927 * check if buffer is empty to make sure that we do not 'overtake'
3928 * ourselves and try to fill a buffer that is already primed
3930 if (atomic_read(&buffer
->state
) != QETH_QDIO_BUF_EMPTY
)
3932 queue
->next_buf_to_fill
= (queue
->next_buf_to_fill
+ 1) %
3933 QDIO_MAX_BUFFERS_PER_Q
;
3934 atomic_set(&queue
->state
, QETH_OUT_Q_UNLOCKED
);
3935 qeth_fill_buffer(queue
, buffer
, skb
, hdr
, offset
, hd_len
);
3936 qeth_flush_buffers(queue
, index
, 1);
3939 atomic_set(&queue
->state
, QETH_OUT_Q_UNLOCKED
);
3942 EXPORT_SYMBOL_GPL(qeth_do_send_packet_fast
);
3944 int qeth_do_send_packet(struct qeth_card
*card
, struct qeth_qdio_out_q
*queue
,
3945 struct sk_buff
*skb
, struct qeth_hdr
*hdr
,
3946 int elements_needed
)
3948 struct qeth_qdio_out_buffer
*buffer
;
3950 int flush_count
= 0;
3955 /* spin until we get the queue ... */
3956 while (atomic_cmpxchg(&queue
->state
, QETH_OUT_Q_UNLOCKED
,
3957 QETH_OUT_Q_LOCKED
) != QETH_OUT_Q_UNLOCKED
);
3958 start_index
= queue
->next_buf_to_fill
;
3959 buffer
= queue
->bufs
[queue
->next_buf_to_fill
];
3961 * check if buffer is empty to make sure that we do not 'overtake'
3962 * ourselves and try to fill a buffer that is already primed
3964 if (atomic_read(&buffer
->state
) != QETH_QDIO_BUF_EMPTY
) {
3965 atomic_set(&queue
->state
, QETH_OUT_Q_UNLOCKED
);
3968 /* check if we need to switch packing state of this queue */
3969 qeth_switch_to_packing_if_needed(queue
);
3970 if (queue
->do_pack
) {
3972 /* does packet fit in current buffer? */
3973 if ((QETH_MAX_BUFFER_ELEMENTS(card
) -
3974 buffer
->next_element_to_fill
) < elements_needed
) {
3975 /* ... no -> set state PRIMED */
3976 atomic_set(&buffer
->state
, QETH_QDIO_BUF_PRIMED
);
3978 queue
->next_buf_to_fill
=
3979 (queue
->next_buf_to_fill
+ 1) %
3980 QDIO_MAX_BUFFERS_PER_Q
;
3981 buffer
= queue
->bufs
[queue
->next_buf_to_fill
];
3982 /* we did a step forward, so check buffer state
3984 if (atomic_read(&buffer
->state
) !=
3985 QETH_QDIO_BUF_EMPTY
) {
3986 qeth_flush_buffers(queue
, start_index
,
3988 atomic_set(&queue
->state
,
3989 QETH_OUT_Q_UNLOCKED
);
3994 tmp
= qeth_fill_buffer(queue
, buffer
, skb
, hdr
, -1, 0);
3995 queue
->next_buf_to_fill
= (queue
->next_buf_to_fill
+ tmp
) %
3996 QDIO_MAX_BUFFERS_PER_Q
;
3999 qeth_flush_buffers(queue
, start_index
, flush_count
);
4000 else if (!atomic_read(&queue
->set_pci_flags_count
))
4001 atomic_xchg(&queue
->state
, QETH_OUT_Q_LOCKED_FLUSH
);
4003 * queue->state will go from LOCKED -> UNLOCKED or from
4004 * LOCKED_FLUSH -> LOCKED if output_handler wanted to 'notify' us
4005 * (switch packing state or flush buffer to get another pci flag out).
4006 * In that case we will enter this loop
4008 while (atomic_dec_return(&queue
->state
)) {
4010 start_index
= queue
->next_buf_to_fill
;
4011 /* check if we can go back to non-packing state */
4012 flush_count
+= qeth_switch_to_nonpacking_if_needed(queue
);
4014 * check if we need to flush a packing buffer to get a pci
4015 * flag out on the queue
4017 if (!flush_count
&& !atomic_read(&queue
->set_pci_flags_count
))
4018 flush_count
+= qeth_flush_buffers_on_no_pci(queue
);
4020 qeth_flush_buffers(queue
, start_index
, flush_count
);
4022 /* at this point the queue is UNLOCKED again */
4023 if (queue
->card
->options
.performance_stats
&& do_pack
)
4024 queue
->card
->perf_stats
.bufs_sent_pack
+= flush_count
;
4028 EXPORT_SYMBOL_GPL(qeth_do_send_packet
);
4030 static int qeth_setadp_promisc_mode_cb(struct qeth_card
*card
,
4031 struct qeth_reply
*reply
, unsigned long data
)
4033 struct qeth_ipa_cmd
*cmd
;
4034 struct qeth_ipacmd_setadpparms
*setparms
;
4036 QETH_CARD_TEXT(card
, 4, "prmadpcb");
4038 cmd
= (struct qeth_ipa_cmd
*) data
;
4039 setparms
= &(cmd
->data
.setadapterparms
);
4041 qeth_default_setadapterparms_cb(card
, reply
, (unsigned long)cmd
);
4042 if (cmd
->hdr
.return_code
) {
4043 QETH_CARD_TEXT_(card
, 4, "prmrc%2.2x", cmd
->hdr
.return_code
);
4044 setparms
->data
.mode
= SET_PROMISC_MODE_OFF
;
4046 card
->info
.promisc_mode
= setparms
->data
.mode
;
4050 void qeth_setadp_promisc_mode(struct qeth_card
*card
)
4052 enum qeth_ipa_promisc_modes mode
;
4053 struct net_device
*dev
= card
->dev
;
4054 struct qeth_cmd_buffer
*iob
;
4055 struct qeth_ipa_cmd
*cmd
;
4057 QETH_CARD_TEXT(card
, 4, "setprom");
4059 if (((dev
->flags
& IFF_PROMISC
) &&
4060 (card
->info
.promisc_mode
== SET_PROMISC_MODE_ON
)) ||
4061 (!(dev
->flags
& IFF_PROMISC
) &&
4062 (card
->info
.promisc_mode
== SET_PROMISC_MODE_OFF
)))
4064 mode
= SET_PROMISC_MODE_OFF
;
4065 if (dev
->flags
& IFF_PROMISC
)
4066 mode
= SET_PROMISC_MODE_ON
;
4067 QETH_CARD_TEXT_(card
, 4, "mode:%x", mode
);
4069 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_SET_PROMISC_MODE
,
4070 sizeof(struct qeth_ipacmd_setadpparms
));
4071 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+ IPA_PDU_HEADER_SIZE
);
4072 cmd
->data
.setadapterparms
.data
.mode
= mode
;
4073 qeth_send_ipa_cmd(card
, iob
, qeth_setadp_promisc_mode_cb
, NULL
);
4075 EXPORT_SYMBOL_GPL(qeth_setadp_promisc_mode
);
4077 int qeth_change_mtu(struct net_device
*dev
, int new_mtu
)
4079 struct qeth_card
*card
;
4082 card
= dev
->ml_priv
;
4084 QETH_CARD_TEXT(card
, 4, "chgmtu");
4085 sprintf(dbf_text
, "%8x", new_mtu
);
4086 QETH_CARD_TEXT(card
, 4, dbf_text
);
4090 if (new_mtu
> 65535)
4092 if ((!qeth_is_supported(card
, IPA_IP_FRAGMENTATION
)) &&
4093 (!qeth_mtu_is_valid(card
, new_mtu
)))
4098 EXPORT_SYMBOL_GPL(qeth_change_mtu
);
4100 struct net_device_stats
*qeth_get_stats(struct net_device
*dev
)
4102 struct qeth_card
*card
;
4104 card
= dev
->ml_priv
;
4106 QETH_CARD_TEXT(card
, 5, "getstat");
4108 return &card
->stats
;
4110 EXPORT_SYMBOL_GPL(qeth_get_stats
);
4112 static int qeth_setadpparms_change_macaddr_cb(struct qeth_card
*card
,
4113 struct qeth_reply
*reply
, unsigned long data
)
4115 struct qeth_ipa_cmd
*cmd
;
4117 QETH_CARD_TEXT(card
, 4, "chgmaccb");
4119 cmd
= (struct qeth_ipa_cmd
*) data
;
4120 if (!card
->options
.layer2
||
4121 !(card
->info
.mac_bits
& QETH_LAYER2_MAC_READ
)) {
4122 memcpy(card
->dev
->dev_addr
,
4123 &cmd
->data
.setadapterparms
.data
.change_addr
.addr
,
4125 card
->info
.mac_bits
|= QETH_LAYER2_MAC_READ
;
4127 qeth_default_setadapterparms_cb(card
, reply
, (unsigned long) cmd
);
4131 int qeth_setadpparms_change_macaddr(struct qeth_card
*card
)
4134 struct qeth_cmd_buffer
*iob
;
4135 struct qeth_ipa_cmd
*cmd
;
4137 QETH_CARD_TEXT(card
, 4, "chgmac");
4139 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_ALTER_MAC_ADDRESS
,
4140 sizeof(struct qeth_ipacmd_setadpparms
));
4141 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
4142 cmd
->data
.setadapterparms
.data
.change_addr
.cmd
= CHANGE_ADDR_READ_MAC
;
4143 cmd
->data
.setadapterparms
.data
.change_addr
.addr_size
= OSA_ADDR_LEN
;
4144 memcpy(&cmd
->data
.setadapterparms
.data
.change_addr
.addr
,
4145 card
->dev
->dev_addr
, OSA_ADDR_LEN
);
4146 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_setadpparms_change_macaddr_cb
,
4150 EXPORT_SYMBOL_GPL(qeth_setadpparms_change_macaddr
);
4152 static int qeth_setadpparms_set_access_ctrl_cb(struct qeth_card
*card
,
4153 struct qeth_reply
*reply
, unsigned long data
)
4155 struct qeth_ipa_cmd
*cmd
;
4156 struct qeth_set_access_ctrl
*access_ctrl_req
;
4157 int fallback
= *(int *)reply
->param
;
4159 QETH_CARD_TEXT(card
, 4, "setaccb");
4161 cmd
= (struct qeth_ipa_cmd
*) data
;
4162 access_ctrl_req
= &cmd
->data
.setadapterparms
.data
.set_access_ctrl
;
4163 QETH_DBF_TEXT_(SETUP
, 2, "setaccb");
4164 QETH_DBF_TEXT_(SETUP
, 2, "%s", card
->gdev
->dev
.kobj
.name
);
4165 QETH_DBF_TEXT_(SETUP
, 2, "rc=%d",
4166 cmd
->data
.setadapterparms
.hdr
.return_code
);
4167 if (cmd
->data
.setadapterparms
.hdr
.return_code
!=
4168 SET_ACCESS_CTRL_RC_SUCCESS
)
4169 QETH_DBF_MESSAGE(3, "ERR:SET_ACCESS_CTRL(%s,%d)==%d\n",
4170 card
->gdev
->dev
.kobj
.name
,
4171 access_ctrl_req
->subcmd_code
,
4172 cmd
->data
.setadapterparms
.hdr
.return_code
);
4173 switch (cmd
->data
.setadapterparms
.hdr
.return_code
) {
4174 case SET_ACCESS_CTRL_RC_SUCCESS
:
4175 if (card
->options
.isolation
== ISOLATION_MODE_NONE
) {
4176 dev_info(&card
->gdev
->dev
,
4177 "QDIO data connection isolation is deactivated\n");
4179 dev_info(&card
->gdev
->dev
,
4180 "QDIO data connection isolation is activated\n");
4183 case SET_ACCESS_CTRL_RC_ALREADY_NOT_ISOLATED
:
4184 QETH_DBF_MESSAGE(2, "%s QDIO data connection isolation already "
4185 "deactivated\n", dev_name(&card
->gdev
->dev
));
4187 card
->options
.isolation
= card
->options
.prev_isolation
;
4189 case SET_ACCESS_CTRL_RC_ALREADY_ISOLATED
:
4190 QETH_DBF_MESSAGE(2, "%s QDIO data connection isolation already"
4191 " activated\n", dev_name(&card
->gdev
->dev
));
4193 card
->options
.isolation
= card
->options
.prev_isolation
;
4195 case SET_ACCESS_CTRL_RC_NOT_SUPPORTED
:
4196 dev_err(&card
->gdev
->dev
, "Adapter does not "
4197 "support QDIO data connection isolation\n");
4199 case SET_ACCESS_CTRL_RC_NONE_SHARED_ADAPTER
:
4200 dev_err(&card
->gdev
->dev
,
4201 "Adapter is dedicated. "
4202 "QDIO data connection isolation not supported\n");
4204 card
->options
.isolation
= card
->options
.prev_isolation
;
4206 case SET_ACCESS_CTRL_RC_ACTIVE_CHECKSUM_OFF
:
4207 dev_err(&card
->gdev
->dev
,
4208 "TSO does not permit QDIO data connection isolation\n");
4210 card
->options
.isolation
= card
->options
.prev_isolation
;
4212 case SET_ACCESS_CTRL_RC_REFLREL_UNSUPPORTED
:
4213 dev_err(&card
->gdev
->dev
, "The adjacent switch port does not "
4214 "support reflective relay mode\n");
4216 card
->options
.isolation
= card
->options
.prev_isolation
;
4218 case SET_ACCESS_CTRL_RC_REFLREL_FAILED
:
4219 dev_err(&card
->gdev
->dev
, "The reflective relay mode cannot be "
4220 "enabled at the adjacent switch port");
4222 card
->options
.isolation
= card
->options
.prev_isolation
;
4224 case SET_ACCESS_CTRL_RC_REFLREL_DEACT_FAILED
:
4225 dev_warn(&card
->gdev
->dev
, "Turning off reflective relay mode "
4226 "at the adjacent switch failed\n");
4229 /* this should never happen */
4231 card
->options
.isolation
= card
->options
.prev_isolation
;
4234 qeth_default_setadapterparms_cb(card
, reply
, (unsigned long) cmd
);
4238 static int qeth_setadpparms_set_access_ctrl(struct qeth_card
*card
,
4239 enum qeth_ipa_isolation_modes isolation
, int fallback
)
4242 struct qeth_cmd_buffer
*iob
;
4243 struct qeth_ipa_cmd
*cmd
;
4244 struct qeth_set_access_ctrl
*access_ctrl_req
;
4246 QETH_CARD_TEXT(card
, 4, "setacctl");
4248 QETH_DBF_TEXT_(SETUP
, 2, "setacctl");
4249 QETH_DBF_TEXT_(SETUP
, 2, "%s", card
->gdev
->dev
.kobj
.name
);
4251 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_SET_ACCESS_CONTROL
,
4252 sizeof(struct qeth_ipacmd_setadpparms_hdr
) +
4253 sizeof(struct qeth_set_access_ctrl
));
4254 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
4255 access_ctrl_req
= &cmd
->data
.setadapterparms
.data
.set_access_ctrl
;
4256 access_ctrl_req
->subcmd_code
= isolation
;
4258 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_setadpparms_set_access_ctrl_cb
,
4260 QETH_DBF_TEXT_(SETUP
, 2, "rc=%d", rc
);
4264 int qeth_set_access_ctrl_online(struct qeth_card
*card
, int fallback
)
4268 QETH_CARD_TEXT(card
, 4, "setactlo");
4270 if ((card
->info
.type
== QETH_CARD_TYPE_OSD
||
4271 card
->info
.type
== QETH_CARD_TYPE_OSX
) &&
4272 qeth_adp_supported(card
, IPA_SETADP_SET_ACCESS_CONTROL
)) {
4273 rc
= qeth_setadpparms_set_access_ctrl(card
,
4274 card
->options
.isolation
, fallback
);
4277 "IPA(SET_ACCESS_CTRL,%s,%d) sent failed\n",
4278 card
->gdev
->dev
.kobj
.name
,
4282 } else if (card
->options
.isolation
!= ISOLATION_MODE_NONE
) {
4283 card
->options
.isolation
= ISOLATION_MODE_NONE
;
4285 dev_err(&card
->gdev
->dev
, "Adapter does not "
4286 "support QDIO data connection isolation\n");
4291 EXPORT_SYMBOL_GPL(qeth_set_access_ctrl_online
);
4293 void qeth_tx_timeout(struct net_device
*dev
)
4295 struct qeth_card
*card
;
4297 card
= dev
->ml_priv
;
4298 QETH_CARD_TEXT(card
, 4, "txtimeo");
4299 card
->stats
.tx_errors
++;
4300 qeth_schedule_recovery(card
);
4302 EXPORT_SYMBOL_GPL(qeth_tx_timeout
);
4304 int qeth_mdio_read(struct net_device
*dev
, int phy_id
, int regnum
)
4306 struct qeth_card
*card
= dev
->ml_priv
;
4310 case MII_BMCR
: /* Basic mode control register */
4312 if ((card
->info
.link_type
!= QETH_LINK_TYPE_GBIT_ETH
) &&
4313 (card
->info
.link_type
!= QETH_LINK_TYPE_OSN
) &&
4314 (card
->info
.link_type
!= QETH_LINK_TYPE_10GBIT_ETH
))
4315 rc
|= BMCR_SPEED100
;
4317 case MII_BMSR
: /* Basic mode status register */
4318 rc
= BMSR_ERCAP
| BMSR_ANEGCOMPLETE
| BMSR_LSTATUS
|
4319 BMSR_10HALF
| BMSR_10FULL
| BMSR_100HALF
| BMSR_100FULL
|
4322 case MII_PHYSID1
: /* PHYS ID 1 */
4323 rc
= (dev
->dev_addr
[0] << 16) | (dev
->dev_addr
[1] << 8) |
4325 rc
= (rc
>> 5) & 0xFFFF;
4327 case MII_PHYSID2
: /* PHYS ID 2 */
4328 rc
= (dev
->dev_addr
[2] << 10) & 0xFFFF;
4330 case MII_ADVERTISE
: /* Advertisement control reg */
4333 case MII_LPA
: /* Link partner ability reg */
4334 rc
= LPA_10HALF
| LPA_10FULL
| LPA_100HALF
| LPA_100FULL
|
4335 LPA_100BASE4
| LPA_LPACK
;
4337 case MII_EXPANSION
: /* Expansion register */
4339 case MII_DCOUNTER
: /* disconnect counter */
4341 case MII_FCSCOUNTER
: /* false carrier counter */
4343 case MII_NWAYTEST
: /* N-way auto-neg test register */
4345 case MII_RERRCOUNTER
: /* rx error counter */
4346 rc
= card
->stats
.rx_errors
;
4348 case MII_SREVISION
: /* silicon revision */
4350 case MII_RESV1
: /* reserved 1 */
4352 case MII_LBRERROR
: /* loopback, rx, bypass error */
4354 case MII_PHYADDR
: /* physical address */
4356 case MII_RESV2
: /* reserved 2 */
4358 case MII_TPISTATUS
: /* TPI status for 10mbps */
4360 case MII_NCONFIG
: /* network interface config */
4367 EXPORT_SYMBOL_GPL(qeth_mdio_read
);
4369 static int qeth_send_ipa_snmp_cmd(struct qeth_card
*card
,
4370 struct qeth_cmd_buffer
*iob
, int len
,
4371 int (*reply_cb
)(struct qeth_card
*, struct qeth_reply
*,
4377 QETH_CARD_TEXT(card
, 4, "sendsnmp");
4379 memcpy(iob
->data
, IPA_PDU_HEADER
, IPA_PDU_HEADER_SIZE
);
4380 memcpy(QETH_IPA_CMD_DEST_ADDR(iob
->data
),
4381 &card
->token
.ulp_connection_r
, QETH_MPC_TOKEN_LENGTH
);
4382 /* adjust PDU length fields in IPA_PDU_HEADER */
4383 s1
= (u32
) IPA_PDU_HEADER_SIZE
+ len
;
4385 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob
->data
), &s1
, 2);
4386 memcpy(QETH_IPA_PDU_LEN_PDU1(iob
->data
), &s2
, 2);
4387 memcpy(QETH_IPA_PDU_LEN_PDU2(iob
->data
), &s2
, 2);
4388 memcpy(QETH_IPA_PDU_LEN_PDU3(iob
->data
), &s2
, 2);
4389 return qeth_send_control_data(card
, IPA_PDU_HEADER_SIZE
+ len
, iob
,
4390 reply_cb
, reply_param
);
4393 static int qeth_snmp_command_cb(struct qeth_card
*card
,
4394 struct qeth_reply
*reply
, unsigned long sdata
)
4396 struct qeth_ipa_cmd
*cmd
;
4397 struct qeth_arp_query_info
*qinfo
;
4398 struct qeth_snmp_cmd
*snmp
;
4399 unsigned char *data
;
4402 QETH_CARD_TEXT(card
, 3, "snpcmdcb");
4404 cmd
= (struct qeth_ipa_cmd
*) sdata
;
4405 data
= (unsigned char *)((char *)cmd
- reply
->offset
);
4406 qinfo
= (struct qeth_arp_query_info
*) reply
->param
;
4407 snmp
= &cmd
->data
.setadapterparms
.data
.snmp
;
4409 if (cmd
->hdr
.return_code
) {
4410 QETH_CARD_TEXT_(card
, 4, "scer1%i", cmd
->hdr
.return_code
);
4413 if (cmd
->data
.setadapterparms
.hdr
.return_code
) {
4414 cmd
->hdr
.return_code
=
4415 cmd
->data
.setadapterparms
.hdr
.return_code
;
4416 QETH_CARD_TEXT_(card
, 4, "scer2%i", cmd
->hdr
.return_code
);
4419 data_len
= *((__u16
*)QETH_IPA_PDU_LEN_PDU1(data
));
4420 if (cmd
->data
.setadapterparms
.hdr
.seq_no
== 1)
4421 data_len
-= (__u16
)((char *)&snmp
->data
- (char *)cmd
);
4423 data_len
-= (__u16
)((char *)&snmp
->request
- (char *)cmd
);
4425 /* check if there is enough room in userspace */
4426 if ((qinfo
->udata_len
- qinfo
->udata_offset
) < data_len
) {
4427 QETH_CARD_TEXT_(card
, 4, "scer3%i", -ENOMEM
);
4428 cmd
->hdr
.return_code
= IPA_RC_ENOMEM
;
4431 QETH_CARD_TEXT_(card
, 4, "snore%i",
4432 cmd
->data
.setadapterparms
.hdr
.used_total
);
4433 QETH_CARD_TEXT_(card
, 4, "sseqn%i",
4434 cmd
->data
.setadapterparms
.hdr
.seq_no
);
4435 /*copy entries to user buffer*/
4436 if (cmd
->data
.setadapterparms
.hdr
.seq_no
== 1) {
4437 memcpy(qinfo
->udata
+ qinfo
->udata_offset
,
4439 data_len
+ offsetof(struct qeth_snmp_cmd
, data
));
4440 qinfo
->udata_offset
+= offsetof(struct qeth_snmp_cmd
, data
);
4442 memcpy(qinfo
->udata
+ qinfo
->udata_offset
,
4443 (char *)&snmp
->request
, data_len
);
4445 qinfo
->udata_offset
+= data_len
;
4446 /* check if all replies received ... */
4447 QETH_CARD_TEXT_(card
, 4, "srtot%i",
4448 cmd
->data
.setadapterparms
.hdr
.used_total
);
4449 QETH_CARD_TEXT_(card
, 4, "srseq%i",
4450 cmd
->data
.setadapterparms
.hdr
.seq_no
);
4451 if (cmd
->data
.setadapterparms
.hdr
.seq_no
<
4452 cmd
->data
.setadapterparms
.hdr
.used_total
)
4457 int qeth_snmp_command(struct qeth_card
*card
, char __user
*udata
)
4459 struct qeth_cmd_buffer
*iob
;
4460 struct qeth_ipa_cmd
*cmd
;
4461 struct qeth_snmp_ureq
*ureq
;
4462 unsigned int req_len
;
4463 struct qeth_arp_query_info qinfo
= {0, };
4466 QETH_CARD_TEXT(card
, 3, "snmpcmd");
4468 if (card
->info
.guestlan
)
4471 if ((!qeth_adp_supported(card
, IPA_SETADP_SET_SNMP_CONTROL
)) &&
4472 (!card
->options
.layer2
)) {
4475 /* skip 4 bytes (data_len struct member) to get req_len */
4476 if (copy_from_user(&req_len
, udata
+ sizeof(int), sizeof(int)))
4478 if (req_len
> (QETH_BUFSIZE
- IPA_PDU_HEADER_SIZE
-
4479 sizeof(struct qeth_ipacmd_hdr
) -
4480 sizeof(struct qeth_ipacmd_setadpparms_hdr
)))
4482 ureq
= memdup_user(udata
, req_len
+ sizeof(struct qeth_snmp_ureq_hdr
));
4484 QETH_CARD_TEXT(card
, 2, "snmpnome");
4485 return PTR_ERR(ureq
);
4487 qinfo
.udata_len
= ureq
->hdr
.data_len
;
4488 qinfo
.udata
= kzalloc(qinfo
.udata_len
, GFP_KERNEL
);
4493 qinfo
.udata_offset
= sizeof(struct qeth_snmp_ureq_hdr
);
4495 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_SET_SNMP_CONTROL
,
4496 QETH_SNMP_SETADP_CMDLENGTH
+ req_len
);
4497 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
4498 memcpy(&cmd
->data
.setadapterparms
.data
.snmp
, &ureq
->cmd
, req_len
);
4499 rc
= qeth_send_ipa_snmp_cmd(card
, iob
, QETH_SETADP_BASE_LEN
+ req_len
,
4500 qeth_snmp_command_cb
, (void *)&qinfo
);
4502 QETH_DBF_MESSAGE(2, "SNMP command failed on %s: (0x%x)\n",
4503 QETH_CARD_IFNAME(card
), rc
);
4505 if (copy_to_user(udata
, qinfo
.udata
, qinfo
.udata_len
))
4513 EXPORT_SYMBOL_GPL(qeth_snmp_command
);
4515 static int qeth_setadpparms_query_oat_cb(struct qeth_card
*card
,
4516 struct qeth_reply
*reply
, unsigned long data
)
4518 struct qeth_ipa_cmd
*cmd
;
4519 struct qeth_qoat_priv
*priv
;
4523 QETH_CARD_TEXT(card
, 3, "qoatcb");
4525 cmd
= (struct qeth_ipa_cmd
*)data
;
4526 priv
= (struct qeth_qoat_priv
*)reply
->param
;
4527 resdatalen
= cmd
->data
.setadapterparms
.hdr
.cmdlength
;
4528 resdata
= (char *)data
+ 28;
4530 if (resdatalen
> (priv
->buffer_len
- priv
->response_len
)) {
4531 cmd
->hdr
.return_code
= IPA_RC_FFFF
;
4535 memcpy((priv
->buffer
+ priv
->response_len
), resdata
,
4537 priv
->response_len
+= resdatalen
;
4539 if (cmd
->data
.setadapterparms
.hdr
.seq_no
<
4540 cmd
->data
.setadapterparms
.hdr
.used_total
)
4545 int qeth_query_oat_command(struct qeth_card
*card
, char __user
*udata
)
4548 struct qeth_cmd_buffer
*iob
;
4549 struct qeth_ipa_cmd
*cmd
;
4550 struct qeth_query_oat
*oat_req
;
4551 struct qeth_query_oat_data oat_data
;
4552 struct qeth_qoat_priv priv
;
4555 QETH_CARD_TEXT(card
, 3, "qoatcmd");
4557 if (!qeth_adp_supported(card
, IPA_SETADP_QUERY_OAT
)) {
4562 if (copy_from_user(&oat_data
, udata
,
4563 sizeof(struct qeth_query_oat_data
))) {
4568 priv
.buffer_len
= oat_data
.buffer_len
;
4569 priv
.response_len
= 0;
4570 priv
.buffer
= kzalloc(oat_data
.buffer_len
, GFP_KERNEL
);
4576 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_QUERY_OAT
,
4577 sizeof(struct qeth_ipacmd_setadpparms_hdr
) +
4578 sizeof(struct qeth_query_oat
));
4579 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
4580 oat_req
= &cmd
->data
.setadapterparms
.data
.query_oat
;
4581 oat_req
->subcmd_code
= oat_data
.command
;
4583 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_setadpparms_query_oat_cb
,
4586 if (is_compat_task())
4587 tmp
= compat_ptr(oat_data
.ptr
);
4589 tmp
= (void __user
*)(unsigned long)oat_data
.ptr
;
4591 if (copy_to_user(tmp
, priv
.buffer
,
4592 priv
.response_len
)) {
4597 oat_data
.response_len
= priv
.response_len
;
4599 if (copy_to_user(udata
, &oat_data
,
4600 sizeof(struct qeth_query_oat_data
)))
4603 if (rc
== IPA_RC_FFFF
)
4611 EXPORT_SYMBOL_GPL(qeth_query_oat_command
);
4613 int qeth_query_card_info_cb(struct qeth_card
*card
,
4614 struct qeth_reply
*reply
, unsigned long data
)
4616 struct qeth_ipa_cmd
*cmd
;
4617 struct qeth_query_card_info
*card_info
;
4618 struct carrier_info
*carrier_info
;
4620 QETH_CARD_TEXT(card
, 2, "qcrdincb");
4621 carrier_info
= (struct carrier_info
*)reply
->param
;
4622 cmd
= (struct qeth_ipa_cmd
*)data
;
4623 card_info
= &cmd
->data
.setadapterparms
.data
.card_info
;
4624 if (cmd
->data
.setadapterparms
.hdr
.return_code
== 0) {
4625 carrier_info
->card_type
= card_info
->card_type
;
4626 carrier_info
->port_mode
= card_info
->port_mode
;
4627 carrier_info
->port_speed
= card_info
->port_speed
;
4630 qeth_default_setadapterparms_cb(card
, reply
, (unsigned long) cmd
);
4634 int qeth_query_card_info(struct qeth_card
*card
,
4635 struct carrier_info
*carrier_info
)
4637 struct qeth_cmd_buffer
*iob
;
4639 QETH_CARD_TEXT(card
, 2, "qcrdinfo");
4640 if (!qeth_adp_supported(card
, IPA_SETADP_QUERY_CARD_INFO
))
4642 iob
= qeth_get_adapter_cmd(card
, IPA_SETADP_QUERY_CARD_INFO
,
4643 sizeof(struct qeth_ipacmd_setadpparms_hdr
));
4644 return qeth_send_ipa_cmd(card
, iob
, qeth_query_card_info_cb
,
4645 (void *)carrier_info
);
4647 EXPORT_SYMBOL_GPL(qeth_query_card_info
);
4649 static inline int qeth_get_qdio_q_format(struct qeth_card
*card
)
4651 switch (card
->info
.type
) {
4652 case QETH_CARD_TYPE_IQD
:
4659 static void qeth_determine_capabilities(struct qeth_card
*card
)
4664 struct ccw_device
*ddev
;
4665 int ddev_offline
= 0;
4667 QETH_DBF_TEXT(SETUP
, 2, "detcapab");
4668 ddev
= CARD_DDEV(card
);
4669 if (!ddev
->online
) {
4671 rc
= ccw_device_set_online(ddev
);
4673 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
4678 rc
= qeth_read_conf_data(card
, (void **) &prcd
, &length
);
4680 QETH_DBF_MESSAGE(2, "%s qeth_read_conf_data returned %i\n",
4681 dev_name(&card
->gdev
->dev
), rc
);
4682 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
4685 qeth_configure_unitaddr(card
, prcd
);
4687 qeth_configure_blkt_default(card
, prcd
);
4690 rc
= qdio_get_ssqd_desc(ddev
, &card
->ssqd
);
4692 QETH_DBF_TEXT_(SETUP
, 2, "6err%d", rc
);
4694 QETH_DBF_TEXT_(SETUP
, 2, "qfmt%d", card
->ssqd
.qfmt
);
4695 QETH_DBF_TEXT_(SETUP
, 2, "%d", card
->ssqd
.qdioac1
);
4696 QETH_DBF_TEXT_(SETUP
, 2, "%d", card
->ssqd
.qdioac3
);
4697 QETH_DBF_TEXT_(SETUP
, 2, "icnt%d", card
->ssqd
.icnt
);
4698 if (!((card
->ssqd
.qfmt
!= QDIO_IQDIO_QFMT
) ||
4699 ((card
->ssqd
.qdioac1
& CHSC_AC1_INITIATE_INPUTQ
) == 0) ||
4700 ((card
->ssqd
.qdioac3
& CHSC_AC3_FORMAT2_CQ_AVAILABLE
) == 0))) {
4701 dev_info(&card
->gdev
->dev
,
4702 "Completion Queueing supported\n");
4704 card
->options
.cq
= QETH_CQ_NOTAVAILABLE
;
4709 if (ddev_offline
== 1)
4710 ccw_device_set_offline(ddev
);
4715 static inline void qeth_qdio_establish_cq(struct qeth_card
*card
,
4716 struct qdio_buffer
**in_sbal_ptrs
,
4717 void (**queue_start_poll
) (struct ccw_device
*, int, unsigned long)) {
4720 if (card
->options
.cq
== QETH_CQ_ENABLED
) {
4721 int offset
= QDIO_MAX_BUFFERS_PER_Q
*
4722 (card
->qdio
.no_in_queues
- 1);
4723 i
= QDIO_MAX_BUFFERS_PER_Q
* (card
->qdio
.no_in_queues
- 1);
4724 for (i
= 0; i
< QDIO_MAX_BUFFERS_PER_Q
; ++i
) {
4725 in_sbal_ptrs
[offset
+ i
] = (struct qdio_buffer
*)
4726 virt_to_phys(card
->qdio
.c_q
->bufs
[i
].buffer
);
4729 queue_start_poll
[card
->qdio
.no_in_queues
- 1] = NULL
;
4733 static int qeth_qdio_establish(struct qeth_card
*card
)
4735 struct qdio_initialize init_data
;
4736 char *qib_param_field
;
4737 struct qdio_buffer
**in_sbal_ptrs
;
4738 void (**queue_start_poll
) (struct ccw_device
*, int, unsigned long);
4739 struct qdio_buffer
**out_sbal_ptrs
;
4743 QETH_DBF_TEXT(SETUP
, 2, "qdioest");
4745 qib_param_field
= kzalloc(QDIO_MAX_BUFFERS_PER_Q
* sizeof(char),
4747 if (!qib_param_field
) {
4749 goto out_free_nothing
;
4752 qeth_create_qib_param_field(card
, qib_param_field
);
4753 qeth_create_qib_param_field_blkt(card
, qib_param_field
);
4755 in_sbal_ptrs
= kzalloc(card
->qdio
.no_in_queues
*
4756 QDIO_MAX_BUFFERS_PER_Q
* sizeof(void *),
4758 if (!in_sbal_ptrs
) {
4760 goto out_free_qib_param
;
4762 for (i
= 0; i
< QDIO_MAX_BUFFERS_PER_Q
; ++i
) {
4763 in_sbal_ptrs
[i
] = (struct qdio_buffer
*)
4764 virt_to_phys(card
->qdio
.in_q
->bufs
[i
].buffer
);
4767 queue_start_poll
= kzalloc(sizeof(void *) * card
->qdio
.no_in_queues
,
4769 if (!queue_start_poll
) {
4771 goto out_free_in_sbals
;
4773 for (i
= 0; i
< card
->qdio
.no_in_queues
; ++i
)
4774 queue_start_poll
[i
] = card
->discipline
->start_poll
;
4776 qeth_qdio_establish_cq(card
, in_sbal_ptrs
, queue_start_poll
);
4779 kzalloc(card
->qdio
.no_out_queues
* QDIO_MAX_BUFFERS_PER_Q
*
4780 sizeof(void *), GFP_KERNEL
);
4781 if (!out_sbal_ptrs
) {
4783 goto out_free_queue_start_poll
;
4785 for (i
= 0, k
= 0; i
< card
->qdio
.no_out_queues
; ++i
)
4786 for (j
= 0; j
< QDIO_MAX_BUFFERS_PER_Q
; ++j
, ++k
) {
4787 out_sbal_ptrs
[k
] = (struct qdio_buffer
*)virt_to_phys(
4788 card
->qdio
.out_qs
[i
]->bufs
[j
]->buffer
);
4791 memset(&init_data
, 0, sizeof(struct qdio_initialize
));
4792 init_data
.cdev
= CARD_DDEV(card
);
4793 init_data
.q_format
= qeth_get_qdio_q_format(card
);
4794 init_data
.qib_param_field_format
= 0;
4795 init_data
.qib_param_field
= qib_param_field
;
4796 init_data
.no_input_qs
= card
->qdio
.no_in_queues
;
4797 init_data
.no_output_qs
= card
->qdio
.no_out_queues
;
4798 init_data
.input_handler
= card
->discipline
->input_handler
;
4799 init_data
.output_handler
= card
->discipline
->output_handler
;
4800 init_data
.queue_start_poll_array
= queue_start_poll
;
4801 init_data
.int_parm
= (unsigned long) card
;
4802 init_data
.input_sbal_addr_array
= (void **) in_sbal_ptrs
;
4803 init_data
.output_sbal_addr_array
= (void **) out_sbal_ptrs
;
4804 init_data
.output_sbal_state_array
= card
->qdio
.out_bufstates
;
4805 init_data
.scan_threshold
=
4806 (card
->info
.type
== QETH_CARD_TYPE_IQD
) ? 1 : 32;
4808 if (atomic_cmpxchg(&card
->qdio
.state
, QETH_QDIO_ALLOCATED
,
4809 QETH_QDIO_ESTABLISHED
) == QETH_QDIO_ALLOCATED
) {
4810 rc
= qdio_allocate(&init_data
);
4812 atomic_set(&card
->qdio
.state
, QETH_QDIO_ALLOCATED
);
4815 rc
= qdio_establish(&init_data
);
4817 atomic_set(&card
->qdio
.state
, QETH_QDIO_ALLOCATED
);
4818 qdio_free(CARD_DDEV(card
));
4822 switch (card
->options
.cq
) {
4823 case QETH_CQ_ENABLED
:
4824 dev_info(&card
->gdev
->dev
, "Completion Queue support enabled");
4826 case QETH_CQ_DISABLED
:
4827 dev_info(&card
->gdev
->dev
, "Completion Queue support disabled");
4833 kfree(out_sbal_ptrs
);
4834 out_free_queue_start_poll
:
4835 kfree(queue_start_poll
);
4837 kfree(in_sbal_ptrs
);
4839 kfree(qib_param_field
);
4844 static void qeth_core_free_card(struct qeth_card
*card
)
4847 QETH_DBF_TEXT(SETUP
, 2, "freecrd");
4848 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
4849 qeth_clean_channel(&card
->read
);
4850 qeth_clean_channel(&card
->write
);
4852 free_netdev(card
->dev
);
4853 kfree(card
->ip_tbd_list
);
4854 qeth_free_qdio_buffers(card
);
4855 unregister_service_level(&card
->qeth_service_level
);
4859 void qeth_trace_features(struct qeth_card
*card
)
4861 QETH_CARD_TEXT(card
, 2, "features");
4862 QETH_CARD_TEXT_(card
, 2, "%x", card
->options
.ipa4
.supported_funcs
);
4863 QETH_CARD_TEXT_(card
, 2, "%x", card
->options
.ipa4
.enabled_funcs
);
4864 QETH_CARD_TEXT_(card
, 2, "%x", card
->options
.ipa6
.supported_funcs
);
4865 QETH_CARD_TEXT_(card
, 2, "%x", card
->options
.ipa6
.enabled_funcs
);
4866 QETH_CARD_TEXT_(card
, 2, "%x", card
->options
.adp
.supported_funcs
);
4867 QETH_CARD_TEXT_(card
, 2, "%x", card
->options
.adp
.enabled_funcs
);
4868 QETH_CARD_TEXT_(card
, 2, "%x", card
->info
.diagass_support
);
4870 EXPORT_SYMBOL_GPL(qeth_trace_features
);
4872 static struct ccw_device_id qeth_ids
[] = {
4873 {CCW_DEVICE_DEVTYPE(0x1731, 0x01, 0x1732, 0x01),
4874 .driver_info
= QETH_CARD_TYPE_OSD
},
4875 {CCW_DEVICE_DEVTYPE(0x1731, 0x05, 0x1732, 0x05),
4876 .driver_info
= QETH_CARD_TYPE_IQD
},
4877 {CCW_DEVICE_DEVTYPE(0x1731, 0x06, 0x1732, 0x06),
4878 .driver_info
= QETH_CARD_TYPE_OSN
},
4879 {CCW_DEVICE_DEVTYPE(0x1731, 0x02, 0x1732, 0x03),
4880 .driver_info
= QETH_CARD_TYPE_OSM
},
4881 {CCW_DEVICE_DEVTYPE(0x1731, 0x02, 0x1732, 0x02),
4882 .driver_info
= QETH_CARD_TYPE_OSX
},
4885 MODULE_DEVICE_TABLE(ccw
, qeth_ids
);
4887 static struct ccw_driver qeth_ccw_driver
= {
4889 .owner
= THIS_MODULE
,
4893 .probe
= ccwgroup_probe_ccwdev
,
4894 .remove
= ccwgroup_remove_ccwdev
,
4897 int qeth_core_hardsetup_card(struct qeth_card
*card
)
4902 QETH_DBF_TEXT(SETUP
, 2, "hrdsetup");
4903 atomic_set(&card
->force_alloc_skb
, 0);
4904 qeth_update_from_chp_desc(card
);
4907 QETH_DBF_MESSAGE(2, "%s Retrying to do IDX activates.\n",
4908 dev_name(&card
->gdev
->dev
));
4909 ccw_device_set_offline(CARD_DDEV(card
));
4910 ccw_device_set_offline(CARD_WDEV(card
));
4911 ccw_device_set_offline(CARD_RDEV(card
));
4912 rc
= ccw_device_set_online(CARD_RDEV(card
));
4915 rc
= ccw_device_set_online(CARD_WDEV(card
));
4918 rc
= ccw_device_set_online(CARD_DDEV(card
));
4921 rc
= qeth_qdio_clear_card(card
, card
->info
.type
!= QETH_CARD_TYPE_IQD
);
4923 if (rc
== -ERESTARTSYS
) {
4924 QETH_DBF_TEXT(SETUP
, 2, "break1");
4927 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
4933 qeth_determine_capabilities(card
);
4934 qeth_init_tokens(card
);
4935 qeth_init_func_level(card
);
4936 rc
= qeth_idx_activate_channel(&card
->read
, qeth_idx_read_cb
);
4937 if (rc
== -ERESTARTSYS
) {
4938 QETH_DBF_TEXT(SETUP
, 2, "break2");
4941 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
4947 rc
= qeth_idx_activate_channel(&card
->write
, qeth_idx_write_cb
);
4948 if (rc
== -ERESTARTSYS
) {
4949 QETH_DBF_TEXT(SETUP
, 2, "break3");
4952 QETH_DBF_TEXT_(SETUP
, 2, "4err%d", rc
);
4958 card
->read_or_write_problem
= 0;
4959 rc
= qeth_mpc_initialize(card
);
4961 QETH_DBF_TEXT_(SETUP
, 2, "5err%d", rc
);
4965 card
->options
.ipa4
.supported_funcs
= 0;
4966 card
->options
.adp
.supported_funcs
= 0;
4967 card
->options
.sbp
.supported_funcs
= 0;
4968 card
->info
.diagass_support
= 0;
4969 qeth_query_ipassists(card
, QETH_PROT_IPV4
);
4970 if (qeth_is_supported(card
, IPA_SETADAPTERPARMS
))
4971 qeth_query_setadapterparms(card
);
4972 if (qeth_adp_supported(card
, IPA_SETADP_SET_DIAG_ASSIST
))
4973 qeth_query_setdiagass(card
);
4976 dev_warn(&card
->gdev
->dev
, "The qeth device driver failed to recover "
4977 "an error on the device\n");
4978 QETH_DBF_MESSAGE(2, "%s Initialization in hardsetup failed! rc=%d\n",
4979 dev_name(&card
->gdev
->dev
), rc
);
4982 EXPORT_SYMBOL_GPL(qeth_core_hardsetup_card
);
4984 static inline int qeth_create_skb_frag(struct qeth_qdio_buffer
*qethbuffer
,
4985 struct qdio_buffer_element
*element
,
4986 struct sk_buff
**pskb
, int offset
, int *pfrag
, int data_len
)
4988 struct page
*page
= virt_to_page(element
->addr
);
4989 if (*pskb
== NULL
) {
4990 if (qethbuffer
->rx_skb
) {
4991 /* only if qeth_card.options.cq == QETH_CQ_ENABLED */
4992 *pskb
= qethbuffer
->rx_skb
;
4993 qethbuffer
->rx_skb
= NULL
;
4995 *pskb
= dev_alloc_skb(QETH_RX_PULL_LEN
+ ETH_HLEN
);
5000 skb_reserve(*pskb
, ETH_HLEN
);
5001 if (data_len
<= QETH_RX_PULL_LEN
) {
5002 memcpy(skb_put(*pskb
, data_len
), element
->addr
+ offset
,
5006 memcpy(skb_put(*pskb
, QETH_RX_PULL_LEN
),
5007 element
->addr
+ offset
, QETH_RX_PULL_LEN
);
5008 skb_fill_page_desc(*pskb
, *pfrag
, page
,
5009 offset
+ QETH_RX_PULL_LEN
,
5010 data_len
- QETH_RX_PULL_LEN
);
5011 (*pskb
)->data_len
+= data_len
- QETH_RX_PULL_LEN
;
5012 (*pskb
)->len
+= data_len
- QETH_RX_PULL_LEN
;
5013 (*pskb
)->truesize
+= data_len
- QETH_RX_PULL_LEN
;
5018 skb_fill_page_desc(*pskb
, *pfrag
, page
, offset
, data_len
);
5019 (*pskb
)->data_len
+= data_len
;
5020 (*pskb
)->len
+= data_len
;
5021 (*pskb
)->truesize
+= data_len
;
5029 struct sk_buff
*qeth_core_get_next_skb(struct qeth_card
*card
,
5030 struct qeth_qdio_buffer
*qethbuffer
,
5031 struct qdio_buffer_element
**__element
, int *__offset
,
5032 struct qeth_hdr
**hdr
)
5034 struct qdio_buffer_element
*element
= *__element
;
5035 struct qdio_buffer
*buffer
= qethbuffer
->buffer
;
5036 int offset
= *__offset
;
5037 struct sk_buff
*skb
= NULL
;
5045 /* qeth_hdr must not cross element boundaries */
5046 if (element
->length
< offset
+ sizeof(struct qeth_hdr
)) {
5047 if (qeth_is_last_sbale(element
))
5051 if (element
->length
< sizeof(struct qeth_hdr
))
5054 *hdr
= element
->addr
+ offset
;
5056 offset
+= sizeof(struct qeth_hdr
);
5057 switch ((*hdr
)->hdr
.l2
.id
) {
5058 case QETH_HEADER_TYPE_LAYER2
:
5059 skb_len
= (*hdr
)->hdr
.l2
.pkt_length
;
5061 case QETH_HEADER_TYPE_LAYER3
:
5062 skb_len
= (*hdr
)->hdr
.l3
.length
;
5063 headroom
= ETH_HLEN
;
5065 case QETH_HEADER_TYPE_OSN
:
5066 skb_len
= (*hdr
)->hdr
.osn
.pdu_length
;
5067 headroom
= sizeof(struct qeth_hdr
);
5076 if (((skb_len
>= card
->options
.rx_sg_cb
) &&
5077 (!(card
->info
.type
== QETH_CARD_TYPE_OSN
)) &&
5078 (!atomic_read(&card
->force_alloc_skb
))) ||
5079 (card
->options
.cq
== QETH_CQ_ENABLED
)) {
5082 skb
= dev_alloc_skb(skb_len
+ headroom
);
5086 skb_reserve(skb
, headroom
);
5089 data_ptr
= element
->addr
+ offset
;
5091 data_len
= min(skb_len
, (int)(element
->length
- offset
));
5094 if (qeth_create_skb_frag(qethbuffer
, element
,
5095 &skb
, offset
, &frag
, data_len
))
5098 memcpy(skb_put(skb
, data_len
), data_ptr
,
5102 skb_len
-= data_len
;
5104 if (qeth_is_last_sbale(element
)) {
5105 QETH_CARD_TEXT(card
, 4, "unexeob");
5106 QETH_CARD_HEX(card
, 2, buffer
, sizeof(void *));
5107 dev_kfree_skb_any(skb
);
5108 card
->stats
.rx_errors
++;
5113 data_ptr
= element
->addr
;
5118 *__element
= element
;
5120 if (use_rx_sg
&& card
->options
.performance_stats
) {
5121 card
->perf_stats
.sg_skbs_rx
++;
5122 card
->perf_stats
.sg_frags_rx
+= skb_shinfo(skb
)->nr_frags
;
5126 if (net_ratelimit()) {
5127 QETH_CARD_TEXT(card
, 2, "noskbmem");
5129 card
->stats
.rx_dropped
++;
5132 EXPORT_SYMBOL_GPL(qeth_core_get_next_skb
);
5134 static void qeth_unregister_dbf_views(void)
5137 for (x
= 0; x
< QETH_DBF_INFOS
; x
++) {
5138 debug_unregister(qeth_dbf
[x
].id
);
5139 qeth_dbf
[x
].id
= NULL
;
5143 void qeth_dbf_longtext(debug_info_t
*id
, int level
, char *fmt
, ...)
5145 char dbf_txt_buf
[32];
5148 if (!debug_level_enabled(id
, level
))
5150 va_start(args
, fmt
);
5151 vsnprintf(dbf_txt_buf
, sizeof(dbf_txt_buf
), fmt
, args
);
5153 debug_text_event(id
, level
, dbf_txt_buf
);
5155 EXPORT_SYMBOL_GPL(qeth_dbf_longtext
);
5157 static int qeth_register_dbf_views(void)
5162 for (x
= 0; x
< QETH_DBF_INFOS
; x
++) {
5163 /* register the areas */
5164 qeth_dbf
[x
].id
= debug_register(qeth_dbf
[x
].name
,
5168 if (qeth_dbf
[x
].id
== NULL
) {
5169 qeth_unregister_dbf_views();
5173 /* register a view */
5174 ret
= debug_register_view(qeth_dbf
[x
].id
, qeth_dbf
[x
].view
);
5176 qeth_unregister_dbf_views();
5180 /* set a passing level */
5181 debug_set_level(qeth_dbf
[x
].id
, qeth_dbf
[x
].level
);
5187 int qeth_core_load_discipline(struct qeth_card
*card
,
5188 enum qeth_discipline_id discipline
)
5191 mutex_lock(&qeth_mod_mutex
);
5192 switch (discipline
) {
5193 case QETH_DISCIPLINE_LAYER3
:
5194 card
->discipline
= try_then_request_module(
5195 symbol_get(qeth_l3_discipline
), "qeth_l3");
5197 case QETH_DISCIPLINE_LAYER2
:
5198 card
->discipline
= try_then_request_module(
5199 symbol_get(qeth_l2_discipline
), "qeth_l2");
5202 if (!card
->discipline
) {
5203 dev_err(&card
->gdev
->dev
, "There is no kernel module to "
5204 "support discipline %d\n", discipline
);
5207 mutex_unlock(&qeth_mod_mutex
);
5211 void qeth_core_free_discipline(struct qeth_card
*card
)
5213 if (card
->options
.layer2
)
5214 symbol_put(qeth_l2_discipline
);
5216 symbol_put(qeth_l3_discipline
);
5217 card
->discipline
= NULL
;
5220 static const struct device_type qeth_generic_devtype
= {
5221 .name
= "qeth_generic",
5222 .groups
= qeth_generic_attr_groups
,
5224 static const struct device_type qeth_osn_devtype
= {
5226 .groups
= qeth_osn_attr_groups
,
5229 #define DBF_NAME_LEN 20
5231 struct qeth_dbf_entry
{
5232 char dbf_name
[DBF_NAME_LEN
];
5233 debug_info_t
*dbf_info
;
5234 struct list_head dbf_list
;
5237 static LIST_HEAD(qeth_dbf_list
);
5238 static DEFINE_MUTEX(qeth_dbf_list_mutex
);
5240 static debug_info_t
*qeth_get_dbf_entry(char *name
)
5242 struct qeth_dbf_entry
*entry
;
5243 debug_info_t
*rc
= NULL
;
5245 mutex_lock(&qeth_dbf_list_mutex
);
5246 list_for_each_entry(entry
, &qeth_dbf_list
, dbf_list
) {
5247 if (strcmp(entry
->dbf_name
, name
) == 0) {
5248 rc
= entry
->dbf_info
;
5252 mutex_unlock(&qeth_dbf_list_mutex
);
5256 static int qeth_add_dbf_entry(struct qeth_card
*card
, char *name
)
5258 struct qeth_dbf_entry
*new_entry
;
5260 card
->debug
= debug_register(name
, 2, 1, 8);
5262 QETH_DBF_TEXT_(SETUP
, 2, "%s", "qcdbf");
5265 if (debug_register_view(card
->debug
, &debug_hex_ascii_view
))
5267 new_entry
= kzalloc(sizeof(struct qeth_dbf_entry
), GFP_KERNEL
);
5270 strncpy(new_entry
->dbf_name
, name
, DBF_NAME_LEN
);
5271 new_entry
->dbf_info
= card
->debug
;
5272 mutex_lock(&qeth_dbf_list_mutex
);
5273 list_add(&new_entry
->dbf_list
, &qeth_dbf_list
);
5274 mutex_unlock(&qeth_dbf_list_mutex
);
5279 debug_unregister(card
->debug
);
5284 static void qeth_clear_dbf_list(void)
5286 struct qeth_dbf_entry
*entry
, *tmp
;
5288 mutex_lock(&qeth_dbf_list_mutex
);
5289 list_for_each_entry_safe(entry
, tmp
, &qeth_dbf_list
, dbf_list
) {
5290 list_del(&entry
->dbf_list
);
5291 debug_unregister(entry
->dbf_info
);
5294 mutex_unlock(&qeth_dbf_list_mutex
);
5297 static int qeth_core_probe_device(struct ccwgroup_device
*gdev
)
5299 struct qeth_card
*card
;
5302 unsigned long flags
;
5303 char dbf_name
[DBF_NAME_LEN
];
5305 QETH_DBF_TEXT(SETUP
, 2, "probedev");
5308 if (!get_device(dev
))
5311 QETH_DBF_TEXT_(SETUP
, 2, "%s", dev_name(&gdev
->dev
));
5313 card
= qeth_alloc_card();
5315 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", -ENOMEM
);
5320 snprintf(dbf_name
, sizeof(dbf_name
), "qeth_card_%s",
5321 dev_name(&gdev
->dev
));
5322 card
->debug
= qeth_get_dbf_entry(dbf_name
);
5324 rc
= qeth_add_dbf_entry(card
, dbf_name
);
5329 card
->read
.ccwdev
= gdev
->cdev
[0];
5330 card
->write
.ccwdev
= gdev
->cdev
[1];
5331 card
->data
.ccwdev
= gdev
->cdev
[2];
5332 dev_set_drvdata(&gdev
->dev
, card
);
5334 gdev
->cdev
[0]->handler
= qeth_irq
;
5335 gdev
->cdev
[1]->handler
= qeth_irq
;
5336 gdev
->cdev
[2]->handler
= qeth_irq
;
5338 rc
= qeth_determine_card_type(card
);
5340 QETH_DBF_TEXT_(SETUP
, 2, "3err%d", rc
);
5343 rc
= qeth_setup_card(card
);
5345 QETH_DBF_TEXT_(SETUP
, 2, "2err%d", rc
);
5349 if (card
->info
.type
== QETH_CARD_TYPE_OSN
)
5350 gdev
->dev
.type
= &qeth_osn_devtype
;
5352 gdev
->dev
.type
= &qeth_generic_devtype
;
5354 switch (card
->info
.type
) {
5355 case QETH_CARD_TYPE_OSN
:
5356 case QETH_CARD_TYPE_OSM
:
5357 rc
= qeth_core_load_discipline(card
, QETH_DISCIPLINE_LAYER2
);
5360 rc
= card
->discipline
->setup(card
->gdev
);
5363 case QETH_CARD_TYPE_OSD
:
5364 case QETH_CARD_TYPE_OSX
:
5369 write_lock_irqsave(&qeth_core_card_list
.rwlock
, flags
);
5370 list_add_tail(&card
->list
, &qeth_core_card_list
.list
);
5371 write_unlock_irqrestore(&qeth_core_card_list
.rwlock
, flags
);
5373 qeth_determine_capabilities(card
);
5377 qeth_core_free_discipline(card
);
5379 qeth_core_free_card(card
);
5385 static void qeth_core_remove_device(struct ccwgroup_device
*gdev
)
5387 unsigned long flags
;
5388 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5390 QETH_DBF_TEXT(SETUP
, 2, "removedv");
5392 if (card
->discipline
) {
5393 card
->discipline
->remove(gdev
);
5394 qeth_core_free_discipline(card
);
5397 write_lock_irqsave(&qeth_core_card_list
.rwlock
, flags
);
5398 list_del(&card
->list
);
5399 write_unlock_irqrestore(&qeth_core_card_list
.rwlock
, flags
);
5400 qeth_core_free_card(card
);
5401 dev_set_drvdata(&gdev
->dev
, NULL
);
5402 put_device(&gdev
->dev
);
5406 static int qeth_core_set_online(struct ccwgroup_device
*gdev
)
5408 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5412 if (!card
->discipline
) {
5413 if (card
->info
.type
== QETH_CARD_TYPE_IQD
)
5414 def_discipline
= QETH_DISCIPLINE_LAYER3
;
5416 def_discipline
= QETH_DISCIPLINE_LAYER2
;
5417 rc
= qeth_core_load_discipline(card
, def_discipline
);
5420 rc
= card
->discipline
->setup(card
->gdev
);
5424 rc
= card
->discipline
->set_online(gdev
);
5429 static int qeth_core_set_offline(struct ccwgroup_device
*gdev
)
5431 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5432 return card
->discipline
->set_offline(gdev
);
5435 static void qeth_core_shutdown(struct ccwgroup_device
*gdev
)
5437 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5438 if (card
->discipline
&& card
->discipline
->shutdown
)
5439 card
->discipline
->shutdown(gdev
);
5442 static int qeth_core_prepare(struct ccwgroup_device
*gdev
)
5444 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5445 if (card
->discipline
&& card
->discipline
->prepare
)
5446 return card
->discipline
->prepare(gdev
);
5450 static void qeth_core_complete(struct ccwgroup_device
*gdev
)
5452 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5453 if (card
->discipline
&& card
->discipline
->complete
)
5454 card
->discipline
->complete(gdev
);
5457 static int qeth_core_freeze(struct ccwgroup_device
*gdev
)
5459 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5460 if (card
->discipline
&& card
->discipline
->freeze
)
5461 return card
->discipline
->freeze(gdev
);
5465 static int qeth_core_thaw(struct ccwgroup_device
*gdev
)
5467 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5468 if (card
->discipline
&& card
->discipline
->thaw
)
5469 return card
->discipline
->thaw(gdev
);
5473 static int qeth_core_restore(struct ccwgroup_device
*gdev
)
5475 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
5476 if (card
->discipline
&& card
->discipline
->restore
)
5477 return card
->discipline
->restore(gdev
);
5481 static struct ccwgroup_driver qeth_core_ccwgroup_driver
= {
5483 .owner
= THIS_MODULE
,
5486 .setup
= qeth_core_probe_device
,
5487 .remove
= qeth_core_remove_device
,
5488 .set_online
= qeth_core_set_online
,
5489 .set_offline
= qeth_core_set_offline
,
5490 .shutdown
= qeth_core_shutdown
,
5491 .prepare
= qeth_core_prepare
,
5492 .complete
= qeth_core_complete
,
5493 .freeze
= qeth_core_freeze
,
5494 .thaw
= qeth_core_thaw
,
5495 .restore
= qeth_core_restore
,
5498 static ssize_t
qeth_core_driver_group_store(struct device_driver
*ddrv
,
5499 const char *buf
, size_t count
)
5503 err
= ccwgroup_create_dev(qeth_core_root_dev
,
5504 &qeth_core_ccwgroup_driver
, 3, buf
);
5506 return err
? err
: count
;
5508 static DRIVER_ATTR(group
, 0200, NULL
, qeth_core_driver_group_store
);
5510 static struct attribute
*qeth_drv_attrs
[] = {
5511 &driver_attr_group
.attr
,
5514 static struct attribute_group qeth_drv_attr_group
= {
5515 .attrs
= qeth_drv_attrs
,
5517 static const struct attribute_group
*qeth_drv_attr_groups
[] = {
5518 &qeth_drv_attr_group
,
5523 const char str
[ETH_GSTRING_LEN
];
5524 } qeth_ethtool_stats_keys
[] = {
5529 {"tx skbs no packing"},
5530 {"tx buffers no packing"},
5531 {"tx skbs packing"},
5532 {"tx buffers packing"},
5535 /* 10 */{"rx sg skbs"},
5537 {"rx sg page allocs"},
5538 {"tx large kbytes"},
5540 {"tx pk state ch n->p"},
5541 {"tx pk state ch p->n"},
5542 {"tx pk watermark low"},
5543 {"tx pk watermark high"},
5544 {"queue 0 buffer usage"},
5545 /* 20 */{"queue 1 buffer usage"},
5546 {"queue 2 buffer usage"},
5547 {"queue 3 buffer usage"},
5550 {"rx do_QDIO time"},
5551 {"rx do_QDIO count"},
5552 {"tx handler time"},
5553 {"tx handler count"},
5555 /* 30 */{"tx count"},
5556 {"tx do_QDIO time"},
5557 {"tx do_QDIO count"},
5560 {"cq handler count"},
5564 int qeth_core_get_sset_count(struct net_device
*dev
, int stringset
)
5566 switch (stringset
) {
5568 return (sizeof(qeth_ethtool_stats_keys
) / ETH_GSTRING_LEN
);
5573 EXPORT_SYMBOL_GPL(qeth_core_get_sset_count
);
5575 void qeth_core_get_ethtool_stats(struct net_device
*dev
,
5576 struct ethtool_stats
*stats
, u64
*data
)
5578 struct qeth_card
*card
= dev
->ml_priv
;
5579 data
[0] = card
->stats
.rx_packets
-
5580 card
->perf_stats
.initial_rx_packets
;
5581 data
[1] = card
->perf_stats
.bufs_rec
;
5582 data
[2] = card
->stats
.tx_packets
-
5583 card
->perf_stats
.initial_tx_packets
;
5584 data
[3] = card
->perf_stats
.bufs_sent
;
5585 data
[4] = card
->stats
.tx_packets
- card
->perf_stats
.initial_tx_packets
5586 - card
->perf_stats
.skbs_sent_pack
;
5587 data
[5] = card
->perf_stats
.bufs_sent
- card
->perf_stats
.bufs_sent_pack
;
5588 data
[6] = card
->perf_stats
.skbs_sent_pack
;
5589 data
[7] = card
->perf_stats
.bufs_sent_pack
;
5590 data
[8] = card
->perf_stats
.sg_skbs_sent
;
5591 data
[9] = card
->perf_stats
.sg_frags_sent
;
5592 data
[10] = card
->perf_stats
.sg_skbs_rx
;
5593 data
[11] = card
->perf_stats
.sg_frags_rx
;
5594 data
[12] = card
->perf_stats
.sg_alloc_page_rx
;
5595 data
[13] = (card
->perf_stats
.large_send_bytes
>> 10);
5596 data
[14] = card
->perf_stats
.large_send_cnt
;
5597 data
[15] = card
->perf_stats
.sc_dp_p
;
5598 data
[16] = card
->perf_stats
.sc_p_dp
;
5599 data
[17] = QETH_LOW_WATERMARK_PACK
;
5600 data
[18] = QETH_HIGH_WATERMARK_PACK
;
5601 data
[19] = atomic_read(&card
->qdio
.out_qs
[0]->used_buffers
);
5602 data
[20] = (card
->qdio
.no_out_queues
> 1) ?
5603 atomic_read(&card
->qdio
.out_qs
[1]->used_buffers
) : 0;
5604 data
[21] = (card
->qdio
.no_out_queues
> 2) ?
5605 atomic_read(&card
->qdio
.out_qs
[2]->used_buffers
) : 0;
5606 data
[22] = (card
->qdio
.no_out_queues
> 3) ?
5607 atomic_read(&card
->qdio
.out_qs
[3]->used_buffers
) : 0;
5608 data
[23] = card
->perf_stats
.inbound_time
;
5609 data
[24] = card
->perf_stats
.inbound_cnt
;
5610 data
[25] = card
->perf_stats
.inbound_do_qdio_time
;
5611 data
[26] = card
->perf_stats
.inbound_do_qdio_cnt
;
5612 data
[27] = card
->perf_stats
.outbound_handler_time
;
5613 data
[28] = card
->perf_stats
.outbound_handler_cnt
;
5614 data
[29] = card
->perf_stats
.outbound_time
;
5615 data
[30] = card
->perf_stats
.outbound_cnt
;
5616 data
[31] = card
->perf_stats
.outbound_do_qdio_time
;
5617 data
[32] = card
->perf_stats
.outbound_do_qdio_cnt
;
5618 data
[33] = card
->perf_stats
.tx_csum
;
5619 data
[34] = card
->perf_stats
.tx_lin
;
5620 data
[35] = card
->perf_stats
.cq_cnt
;
5621 data
[36] = card
->perf_stats
.cq_time
;
5623 EXPORT_SYMBOL_GPL(qeth_core_get_ethtool_stats
);
5625 void qeth_core_get_strings(struct net_device
*dev
, u32 stringset
, u8
*data
)
5627 switch (stringset
) {
5629 memcpy(data
, &qeth_ethtool_stats_keys
,
5630 sizeof(qeth_ethtool_stats_keys
));
5637 EXPORT_SYMBOL_GPL(qeth_core_get_strings
);
5639 void qeth_core_get_drvinfo(struct net_device
*dev
,
5640 struct ethtool_drvinfo
*info
)
5642 struct qeth_card
*card
= dev
->ml_priv
;
5644 strlcpy(info
->driver
, card
->options
.layer2
? "qeth_l2" : "qeth_l3",
5645 sizeof(info
->driver
));
5646 strlcpy(info
->version
, "1.0", sizeof(info
->version
));
5647 strlcpy(info
->fw_version
, card
->info
.mcl_level
,
5648 sizeof(info
->fw_version
));
5649 snprintf(info
->bus_info
, sizeof(info
->bus_info
), "%s/%s/%s",
5650 CARD_RDEV_ID(card
), CARD_WDEV_ID(card
), CARD_DDEV_ID(card
));
5652 EXPORT_SYMBOL_GPL(qeth_core_get_drvinfo
);
5654 /* Helper function to fill 'advertizing' and 'supported' which are the same. */
5655 /* Autoneg and full-duplex are supported and advertized uncondionally. */
5656 /* Always advertize and support all speeds up to specified, and only one */
5657 /* specified port type. */
5658 static void qeth_set_ecmd_adv_sup(struct ethtool_cmd
*ecmd
,
5659 int maxspeed
, int porttype
)
5661 int port_sup
, port_adv
, spd_sup
, spd_adv
;
5665 port_sup
= SUPPORTED_TP
;
5666 port_adv
= ADVERTISED_TP
;
5669 port_sup
= SUPPORTED_FIBRE
;
5670 port_adv
= ADVERTISED_FIBRE
;
5673 port_sup
= SUPPORTED_TP
;
5674 port_adv
= ADVERTISED_TP
;
5678 /* "Fallthrough" case'es ordered from high to low result in setting */
5679 /* flags cumulatively, starting from the specified speed and down to */
5680 /* the lowest possible. */
5685 spd_sup
|= SUPPORTED_10000baseT_Full
;
5686 spd_adv
|= ADVERTISED_10000baseT_Full
;
5688 spd_sup
|= SUPPORTED_1000baseT_Half
| SUPPORTED_1000baseT_Full
;
5689 spd_adv
|= ADVERTISED_1000baseT_Half
|
5690 ADVERTISED_1000baseT_Full
;
5692 spd_sup
|= SUPPORTED_100baseT_Half
| SUPPORTED_100baseT_Full
;
5693 spd_adv
|= ADVERTISED_100baseT_Half
| ADVERTISED_100baseT_Full
;
5695 spd_sup
|= SUPPORTED_10baseT_Half
| SUPPORTED_10baseT_Full
;
5696 spd_adv
|= ADVERTISED_10baseT_Half
| ADVERTISED_10baseT_Full
;
5699 spd_sup
= SUPPORTED_10baseT_Half
| SUPPORTED_10baseT_Full
;
5700 spd_adv
= ADVERTISED_10baseT_Half
| ADVERTISED_10baseT_Full
;
5703 ecmd
->advertising
= ADVERTISED_Autoneg
| port_adv
| spd_adv
;
5704 ecmd
->supported
= SUPPORTED_Autoneg
| port_sup
| spd_sup
;
5707 int qeth_core_ethtool_get_settings(struct net_device
*netdev
,
5708 struct ethtool_cmd
*ecmd
)
5710 struct qeth_card
*card
= netdev
->ml_priv
;
5711 enum qeth_link_types link_type
;
5712 struct carrier_info carrier_info
;
5714 if ((card
->info
.type
== QETH_CARD_TYPE_IQD
) || (card
->info
.guestlan
))
5715 link_type
= QETH_LINK_TYPE_10GBIT_ETH
;
5717 link_type
= card
->info
.link_type
;
5719 ecmd
->transceiver
= XCVR_INTERNAL
;
5720 ecmd
->duplex
= DUPLEX_FULL
;
5721 ecmd
->autoneg
= AUTONEG_ENABLE
;
5723 switch (link_type
) {
5724 case QETH_LINK_TYPE_FAST_ETH
:
5725 case QETH_LINK_TYPE_LANE_ETH100
:
5726 qeth_set_ecmd_adv_sup(ecmd
, SPEED_100
, PORT_TP
);
5727 ecmd
->speed
= SPEED_100
;
5728 ecmd
->port
= PORT_TP
;
5731 case QETH_LINK_TYPE_GBIT_ETH
:
5732 case QETH_LINK_TYPE_LANE_ETH1000
:
5733 qeth_set_ecmd_adv_sup(ecmd
, SPEED_1000
, PORT_FIBRE
);
5734 ecmd
->speed
= SPEED_1000
;
5735 ecmd
->port
= PORT_FIBRE
;
5738 case QETH_LINK_TYPE_10GBIT_ETH
:
5739 qeth_set_ecmd_adv_sup(ecmd
, SPEED_10000
, PORT_FIBRE
);
5740 ecmd
->speed
= SPEED_10000
;
5741 ecmd
->port
= PORT_FIBRE
;
5745 qeth_set_ecmd_adv_sup(ecmd
, SPEED_10
, PORT_TP
);
5746 ecmd
->speed
= SPEED_10
;
5747 ecmd
->port
= PORT_TP
;
5750 /* Check if we can obtain more accurate information. */
5751 /* If QUERY_CARD_INFO command is not supported or fails, */
5752 /* just return the heuristics that was filled above. */
5753 if (qeth_query_card_info(card
, &carrier_info
) != 0)
5757 "card info: card_type=0x%02x, port_mode=0x%04x, port_speed=0x%08x\n",
5758 carrier_info
.card_type
,
5759 carrier_info
.port_mode
,
5760 carrier_info
.port_speed
);
5762 /* Update attributes for which we've obtained more authoritative */
5763 /* information, leave the rest the way they where filled above. */
5764 switch (carrier_info
.card_type
) {
5765 case CARD_INFO_TYPE_1G_COPPER_A
:
5766 case CARD_INFO_TYPE_1G_COPPER_B
:
5767 qeth_set_ecmd_adv_sup(ecmd
, SPEED_1000
, PORT_TP
);
5768 ecmd
->port
= PORT_TP
;
5770 case CARD_INFO_TYPE_1G_FIBRE_A
:
5771 case CARD_INFO_TYPE_1G_FIBRE_B
:
5772 qeth_set_ecmd_adv_sup(ecmd
, SPEED_1000
, PORT_FIBRE
);
5773 ecmd
->port
= PORT_FIBRE
;
5775 case CARD_INFO_TYPE_10G_FIBRE_A
:
5776 case CARD_INFO_TYPE_10G_FIBRE_B
:
5777 qeth_set_ecmd_adv_sup(ecmd
, SPEED_10000
, PORT_FIBRE
);
5778 ecmd
->port
= PORT_FIBRE
;
5782 switch (carrier_info
.port_mode
) {
5783 case CARD_INFO_PORTM_FULLDUPLEX
:
5784 ecmd
->duplex
= DUPLEX_FULL
;
5786 case CARD_INFO_PORTM_HALFDUPLEX
:
5787 ecmd
->duplex
= DUPLEX_HALF
;
5791 switch (carrier_info
.port_speed
) {
5792 case CARD_INFO_PORTS_10M
:
5793 ecmd
->speed
= SPEED_10
;
5795 case CARD_INFO_PORTS_100M
:
5796 ecmd
->speed
= SPEED_100
;
5798 case CARD_INFO_PORTS_1G
:
5799 ecmd
->speed
= SPEED_1000
;
5801 case CARD_INFO_PORTS_10G
:
5802 ecmd
->speed
= SPEED_10000
;
5808 EXPORT_SYMBOL_GPL(qeth_core_ethtool_get_settings
);
5810 static int __init
qeth_core_init(void)
5814 pr_info("loading core functions\n");
5815 INIT_LIST_HEAD(&qeth_core_card_list
.list
);
5816 INIT_LIST_HEAD(&qeth_dbf_list
);
5817 rwlock_init(&qeth_core_card_list
.rwlock
);
5818 mutex_init(&qeth_mod_mutex
);
5820 qeth_wq
= create_singlethread_workqueue("qeth_wq");
5822 rc
= qeth_register_dbf_views();
5825 qeth_core_root_dev
= root_device_register("qeth");
5826 rc
= PTR_RET(qeth_core_root_dev
);
5829 qeth_core_header_cache
= kmem_cache_create("qeth_hdr",
5830 sizeof(struct qeth_hdr
) + ETH_HLEN
, 64, 0, NULL
);
5831 if (!qeth_core_header_cache
) {
5835 qeth_qdio_outbuf_cache
= kmem_cache_create("qeth_buf",
5836 sizeof(struct qeth_qdio_out_buffer
), 0, 0, NULL
);
5837 if (!qeth_qdio_outbuf_cache
) {
5841 rc
= ccw_driver_register(&qeth_ccw_driver
);
5844 qeth_core_ccwgroup_driver
.driver
.groups
= qeth_drv_attr_groups
;
5845 rc
= ccwgroup_driver_register(&qeth_core_ccwgroup_driver
);
5852 ccw_driver_unregister(&qeth_ccw_driver
);
5854 kmem_cache_destroy(qeth_qdio_outbuf_cache
);
5856 kmem_cache_destroy(qeth_core_header_cache
);
5858 root_device_unregister(qeth_core_root_dev
);
5860 qeth_unregister_dbf_views();
5862 pr_err("Initializing the qeth device driver failed\n");
5866 static void __exit
qeth_core_exit(void)
5868 qeth_clear_dbf_list();
5869 destroy_workqueue(qeth_wq
);
5870 ccwgroup_driver_unregister(&qeth_core_ccwgroup_driver
);
5871 ccw_driver_unregister(&qeth_ccw_driver
);
5872 kmem_cache_destroy(qeth_qdio_outbuf_cache
);
5873 kmem_cache_destroy(qeth_core_header_cache
);
5874 root_device_unregister(qeth_core_root_dev
);
5875 qeth_unregister_dbf_views();
5876 pr_info("core functions removed\n");
5879 module_init(qeth_core_init
);
5880 module_exit(qeth_core_exit
);
5881 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
5882 MODULE_DESCRIPTION("qeth core functions");
5883 MODULE_LICENSE("GPL");