1 /* Copyright (c) 2012 - 2015 UNISYS CORPORATION
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for more
15 /* This driver lives in a spar partition, and registers to ethernet io
16 * channels from the visorbus driver. It creates netdev devices and
17 * forwards transmit to the IO channel and accepts rcvs from the IO
18 * Partition via the IO channel.
21 #include <linux/debugfs.h>
22 #include <linux/etherdevice.h>
23 #include <linux/module.h>
24 #include <linux/netdevice.h>
25 #include <linux/kthread.h>
26 #include <linux/skbuff.h>
27 #include <linux/rtnetlink.h>
30 #include "iochannel.h"
32 #define VISORNIC_INFINITE_RSP_WAIT 0
34 /* MAX_BUF = 64 lines x 32 MAXVNIC x 80 characters
37 #define MAX_BUF 163840
38 #define NAPI_WEIGHT 64
40 /* GUIDS for director channel type supported by this driver. */
41 /* {8cd5994d-c58e-11da-95a9-00e08161165f} */
42 #define VISOR_VNIC_CHANNEL_GUID \
43 GUID_INIT(0x8cd5994d, 0xc58e, 0x11da, \
44 0x95, 0xa9, 0x0, 0xe0, 0x81, 0x61, 0x16, 0x5f)
45 #define VISOR_VNIC_CHANNEL_GUID_STR \
46 "8cd5994d-c58e-11da-95a9-00e08161165f"
48 static struct visor_channeltype_descriptor visornic_channel_types
[] = {
49 /* Note that the only channel type we expect to be reported by the
50 * bus driver is the VISOR_VNIC channel.
52 { VISOR_VNIC_CHANNEL_GUID
, "ultravnic", sizeof(struct channel_header
),
53 VISOR_VNIC_CHANNEL_VERSIONID
},
56 MODULE_DEVICE_TABLE(visorbus
, visornic_channel_types
);
57 /* FIXME XXX: This next line of code must be fixed and removed before
58 * acceptance into the 'normal' part of the kernel. It is only here as a place
59 * holder to get module autoloading functionality working for visorbus. Code
60 * must be added to scripts/mode/file2alias.c, etc., to get this working
63 MODULE_ALIAS("visorbus:" VISOR_VNIC_CHANNEL_GUID_STR
);
66 unsigned long got_rcv
;
67 unsigned long got_enbdisack
;
68 unsigned long got_xmit_done
;
69 unsigned long xmit_fail
;
70 unsigned long sent_enbdis
;
71 unsigned long sent_promisc
;
72 unsigned long sent_post
;
73 unsigned long sent_post_failed
;
74 unsigned long sent_xmit
;
75 unsigned long reject_count
;
76 unsigned long extra_rcvbufs_sent
;
79 /* struct visornic_devdata
80 * @enabled: 0 disabled 1 enabled to receive.
81 * @enab_dis_acked: NET_RCV_ENABLE/DISABLE acked by IOPART.
88 * @incarnation_id: incarnation_id lets IOPART know about
90 * @old_flags: flags as they were prior to
92 * @usage: count of users.
93 * @num_rcv_bufs: number of rcv buffers the vnic will post.
94 * @num_rcv_bufs_could_not_alloc:
95 * @num_rcvbuf_in_iovm:
96 * @alloc_failed_in_if_needed_cnt:
97 * @alloc_failed_in_repost_rtn_cnt:
98 * @max_outstanding_net_xmits: absolute max number of outstanding xmits
99 * - should never hit this.
100 * @upper_threshold_net_xmits: high water mark for calling
101 * netif_stop_queue().
102 * @lower_threshold_net_xmits: high water mark for calling
103 * netif_wake_queue().
104 * @struct xmitbufhead: xmitbufhead - head of the xmit buffer list
105 * sent to the IOPART end.
106 * @server_down_complete_func:
107 * @struct timeout_reset:
108 * @struct *cmdrsp_rcv: cmdrsp_rcv is used for posting/unposting rcv
110 * @struct *xmit_cmdrsp: xmit_cmdrsp - issues NET_XMIT - only one
111 * active xmit at a time.
112 * @server_down: IOPART is down.
113 * @server_change_state: Processing SERVER_CHANGESTATE msg.
114 * @going_away: device is being torn down.
115 * @struct *eth_debugfs_dir:
118 * @interrupts_disabled:
120 * @priv_lock: spinlock to access devdata structures.
121 * @flow_control_upper_hits:
122 * @flow_control_lower_hits:
123 * @n_rcv0: # rcvs of 0 buffers.
124 * @n_rcv1: # rcvs of 1 buffers.
125 * @n_rcv2: # rcvs of 2 buffers.
126 * @n_rcvx: # rcvs of >2 buffers.
127 * @found_repost_rcvbuf_cnt: # repost_rcvbuf_cnt.
128 * @repost_found_skb_cnt: # of found the skb.
129 * @n_repost_deficit: # of lost rcv buffers.
130 * @bad_rcv_buf: # of unknown rcv skb not freed.
131 * @n_rcv_packets_not_accepted: # bogs rcv packets.
132 * @queuefullmsg_logged:
134 * @struct irq_poll_timer:
138 struct visornic_devdata
{
139 unsigned short enabled
;
140 unsigned short enab_dis_acked
;
142 struct visor_device
*dev
;
143 struct net_device
*netdev
;
144 struct net_device_stats net_stats
;
145 atomic_t interrupt_rcvd
;
146 wait_queue_head_t rsp_queue
;
147 struct sk_buff
**rcvbuf
;
149 unsigned short old_flags
;
153 int num_rcv_bufs_could_not_alloc
;
154 atomic_t num_rcvbuf_in_iovm
;
155 unsigned long alloc_failed_in_if_needed_cnt
;
156 unsigned long alloc_failed_in_repost_rtn_cnt
;
158 unsigned long max_outstanding_net_xmits
;
159 unsigned long upper_threshold_net_xmits
;
160 unsigned long lower_threshold_net_xmits
;
161 struct sk_buff_head xmitbufhead
;
163 visorbus_state_complete_func server_down_complete_func
;
164 struct work_struct timeout_reset
;
165 struct uiscmdrsp
*cmdrsp_rcv
;
166 struct uiscmdrsp
*xmit_cmdrsp
;
168 bool server_change_state
;
170 struct dentry
*eth_debugfs_dir
;
172 u64 interrupts_notme
;
173 u64 interrupts_disabled
;
175 /* spinlock to access devdata structures. */
176 spinlock_t priv_lock
;
178 /* flow control counter */
179 u64 flow_control_upper_hits
;
180 u64 flow_control_lower_hits
;
183 unsigned long n_rcv0
;
184 unsigned long n_rcv1
;
185 unsigned long n_rcv2
;
186 unsigned long n_rcvx
;
187 unsigned long found_repost_rcvbuf_cnt
;
188 unsigned long repost_found_skb_cnt
;
189 unsigned long n_repost_deficit
;
190 unsigned long bad_rcv_buf
;
191 unsigned long n_rcv_packets_not_accepted
;
193 int queuefullmsg_logged
;
194 struct chanstat chstat
;
195 struct timer_list irq_poll_timer
;
196 struct napi_struct napi
;
197 struct uiscmdrsp cmdrsp
[SIZEOF_CMDRSP
];
200 /* Returns next non-zero index on success or 0 on failure (i.e. out of room). */
201 static u16
add_physinfo_entries(u64 inp_pfn
, u16 inp_off
, u16 inp_len
,
202 u16 index
, u16 max_pi_arr_entries
,
203 struct phys_info pi_arr
[])
205 u16 i
, len
, firstlen
;
207 firstlen
= PI_PAGE_SIZE
- inp_off
;
208 if (inp_len
<= firstlen
) {
209 /* The input entry spans only one page - add as is. */
210 if (index
>= max_pi_arr_entries
)
212 pi_arr
[index
].pi_pfn
= inp_pfn
;
213 pi_arr
[index
].pi_off
= (u16
)inp_off
;
214 pi_arr
[index
].pi_len
= (u16
)inp_len
;
218 /* This entry spans multiple pages. */
219 for (len
= inp_len
, i
= 0; len
;
220 len
-= pi_arr
[index
+ i
].pi_len
, i
++) {
221 if (index
+ i
>= max_pi_arr_entries
)
223 pi_arr
[index
+ i
].pi_pfn
= inp_pfn
+ i
;
225 pi_arr
[index
].pi_off
= inp_off
;
226 pi_arr
[index
].pi_len
= firstlen
;
228 pi_arr
[index
+ i
].pi_off
= 0;
229 pi_arr
[index
+ i
].pi_len
= min_t(u16
, len
,
236 /* visor_copy_fragsinfo_from_skb - copy fragment list in the SKB to a phys_info
237 * array that the IOPART understands
238 * @skb: Skbuff that we are pulling the frags from.
239 * @firstfraglen: Length of first fragment in skb.
240 * @frags_max: Max len of frags array.
241 * @frags: Frags array filled in on output.
243 * Return: Positive integer indicating number of entries filled in frags on
244 * success, negative integer on error.
246 static int visor_copy_fragsinfo_from_skb(struct sk_buff
*skb
,
247 unsigned int firstfraglen
,
248 unsigned int frags_max
,
249 struct phys_info frags
[])
251 unsigned int count
= 0, frag
, size
, offset
= 0, numfrags
;
252 unsigned int total_count
;
254 numfrags
= skb_shinfo(skb
)->nr_frags
;
256 /* Compute the number of fragments this skb has, and if its more than
257 * frag array can hold, linearize the skb
259 total_count
= numfrags
+ (firstfraglen
/ PI_PAGE_SIZE
);
260 if (firstfraglen
% PI_PAGE_SIZE
)
263 if (total_count
> frags_max
) {
264 if (skb_linearize(skb
))
266 numfrags
= skb_shinfo(skb
)->nr_frags
;
270 while (firstfraglen
) {
271 if (count
== frags_max
)
274 frags
[count
].pi_pfn
=
275 page_to_pfn(virt_to_page(skb
->data
+ offset
));
276 frags
[count
].pi_off
=
277 (unsigned long)(skb
->data
+ offset
) & PI_PAGE_MASK
;
278 size
= min_t(unsigned int, firstfraglen
,
279 PI_PAGE_SIZE
- frags
[count
].pi_off
);
281 /* can take smallest of firstfraglen (what's left) OR
282 * bytes left in the page
284 frags
[count
].pi_len
= size
;
285 firstfraglen
-= size
;
290 if ((count
+ numfrags
) > frags_max
)
293 for (frag
= 0; frag
< numfrags
; frag
++) {
294 count
= add_physinfo_entries(page_to_pfn(
295 skb_frag_page(&skb_shinfo(skb
)->frags
[frag
])),
296 skb_shinfo(skb
)->frags
[frag
].page_offset
,
297 skb_shinfo(skb
)->frags
[frag
].size
, count
,
299 /* add_physinfo_entries only returns
300 * zero if the frags array is out of room
301 * That should never happen because we
302 * fail above, if count+numfrags > frags_max.
308 if (skb_shinfo(skb
)->frag_list
) {
309 struct sk_buff
*skbinlist
;
312 for (skbinlist
= skb_shinfo(skb
)->frag_list
; skbinlist
;
313 skbinlist
= skbinlist
->next
) {
314 c
= visor_copy_fragsinfo_from_skb(skbinlist
,
327 static ssize_t
enable_ints_write(struct file
*file
,
328 const char __user
*buffer
,
329 size_t count
, loff_t
*ppos
)
331 /* Don't want to break ABI here by having a debugfs
332 * file that no longer exists or is writable, so
333 * lets just make this a vestigual function
338 static const struct file_operations debugfs_enable_ints_fops
= {
339 .write
= enable_ints_write
,
342 /* visornic_serverdown_complete - pause device following IOPART going down
343 * @devdata: Device managed by IOPART.
345 * The IO partition has gone down, and we need to do some cleanup for when it
346 * comes back. Treat the IO partition as the link being down.
348 static void visornic_serverdown_complete(struct visornic_devdata
*devdata
)
350 struct net_device
*netdev
= devdata
->netdev
;
352 /* Stop polling for interrupts */
353 del_timer_sync(&devdata
->irq_poll_timer
);
359 atomic_set(&devdata
->num_rcvbuf_in_iovm
, 0);
360 devdata
->chstat
.sent_xmit
= 0;
361 devdata
->chstat
.got_xmit_done
= 0;
363 if (devdata
->server_down_complete_func
)
364 (*devdata
->server_down_complete_func
)(devdata
->dev
, 0);
366 devdata
->server_down
= true;
367 devdata
->server_change_state
= false;
368 devdata
->server_down_complete_func
= NULL
;
371 /* visornic_serverdown - Command has notified us that IOPART is down
372 * @devdata: Device managed by IOPART.
373 * @complete_func: Function to call when finished.
375 * Schedule the work needed to handle the server down request. Make sure we
376 * haven't already handled the server change state event.
378 * Return: 0 if we scheduled the work, negative integer on error.
380 static int visornic_serverdown(struct visornic_devdata
*devdata
,
381 visorbus_state_complete_func complete_func
)
386 spin_lock_irqsave(&devdata
->priv_lock
, flags
);
387 if (devdata
->server_change_state
) {
388 dev_dbg(&devdata
->dev
->device
, "%s changing state\n",
393 if (devdata
->server_down
) {
394 dev_dbg(&devdata
->dev
->device
, "%s already down\n",
399 if (devdata
->going_away
) {
400 dev_dbg(&devdata
->dev
->device
,
401 "%s aborting because device removal pending\n",
406 devdata
->server_change_state
= true;
407 devdata
->server_down_complete_func
= complete_func
;
408 spin_unlock_irqrestore(&devdata
->priv_lock
, flags
);
410 visornic_serverdown_complete(devdata
);
414 spin_unlock_irqrestore(&devdata
->priv_lock
, flags
);
418 /* alloc_rcv_buf - alloc rcv buffer to be given to the IO Partition
419 * @netdev: Network adapter the rcv bufs are attached too.
421 * Create an sk_buff (rcv_buf) that will be passed to the IO Partition
422 * so that it can write rcv data into our memory space.
424 * Return: Pointer to sk_buff.
426 static struct sk_buff
*alloc_rcv_buf(struct net_device
*netdev
)
430 /* NOTE: the first fragment in each rcv buffer is pointed to by
431 * rcvskb->data. For now all rcv buffers will be RCVPOST_BUF_SIZE
432 * in length, so the first frag is large enough to hold 1514.
434 skb
= alloc_skb(RCVPOST_BUF_SIZE
, GFP_ATOMIC
);
438 /* current value of mtu doesn't come into play here; large
439 * packets will just end up using multiple rcv buffers all of
442 skb
->len
= RCVPOST_BUF_SIZE
;
443 /* alloc_skb already zeroes it out for clarification. */
448 /* post_skb - post a skb to the IO Partition
449 * @cmdrsp: Cmdrsp packet to be send to the IO Partition.
450 * @devdata: visornic_devdata to post the skb to.
451 * @skb: Skb to give to the IO partition.
453 * Return: 0 on success, negative integer on error.
455 static int post_skb(struct uiscmdrsp
*cmdrsp
, struct visornic_devdata
*devdata
,
460 cmdrsp
->net
.buf
= skb
;
461 cmdrsp
->net
.rcvpost
.frag
.pi_pfn
= page_to_pfn(virt_to_page(skb
->data
));
462 cmdrsp
->net
.rcvpost
.frag
.pi_off
=
463 (unsigned long)skb
->data
& PI_PAGE_MASK
;
464 cmdrsp
->net
.rcvpost
.frag
.pi_len
= skb
->len
;
465 cmdrsp
->net
.rcvpost
.unique_num
= devdata
->incarnation_id
;
467 if ((cmdrsp
->net
.rcvpost
.frag
.pi_off
+ skb
->len
) > PI_PAGE_SIZE
)
470 cmdrsp
->net
.type
= NET_RCV_POST
;
471 cmdrsp
->cmdtype
= CMD_NET_TYPE
;
472 err
= visorchannel_signalinsert(devdata
->dev
->visorchannel
,
476 devdata
->chstat
.sent_post_failed
++;
480 atomic_inc(&devdata
->num_rcvbuf_in_iovm
);
481 devdata
->chstat
.sent_post
++;
485 /* send_enbdis - Send NET_RCV_ENBDIS to IO Partition
486 * @netdev: Netdevice we are enabling/disabling, used as context return value.
487 * @state: Enable = 1/disable = 0.
488 * @devdata: Visornic device we are enabling/disabling.
490 * Send the enable/disable message to the IO Partition.
492 * Return: 0 on success, negative integer on error.
494 static int send_enbdis(struct net_device
*netdev
, int state
,
495 struct visornic_devdata
*devdata
)
499 devdata
->cmdrsp_rcv
->net
.enbdis
.enable
= state
;
500 devdata
->cmdrsp_rcv
->net
.enbdis
.context
= netdev
;
501 devdata
->cmdrsp_rcv
->net
.type
= NET_RCV_ENBDIS
;
502 devdata
->cmdrsp_rcv
->cmdtype
= CMD_NET_TYPE
;
503 err
= visorchannel_signalinsert(devdata
->dev
->visorchannel
,
505 devdata
->cmdrsp_rcv
);
508 devdata
->chstat
.sent_enbdis
++;
512 /* visornic_disable_with_timeout - disable network adapter
513 * @netdev: netdevice to disable.
514 * @timeout: Timeout to wait for disable.
516 * Disable the network adapter and inform the IO Partition that we are disabled.
517 * Reclaim memory from rcv bufs.
519 * Return: 0 on success, negative integer on failure of IO Partition responding.
521 static int visornic_disable_with_timeout(struct net_device
*netdev
,
524 struct visornic_devdata
*devdata
= netdev_priv(netdev
);
530 /* send a msg telling the other end we are stopping incoming pkts */
531 spin_lock_irqsave(&devdata
->priv_lock
, flags
);
532 devdata
->enabled
= 0;
533 /* must wait for ack */
534 devdata
->enab_dis_acked
= 0;
535 spin_unlock_irqrestore(&devdata
->priv_lock
, flags
);
537 /* send disable and wait for ack -- don't hold lock when sending
538 * disable because if the queue is full, insert might sleep.
539 * If an error occurs, don't wait for the timeout.
541 err
= send_enbdis(netdev
, 0, devdata
);
545 /* wait for ack to arrive before we try to free rcv buffers
546 * NOTE: the other end automatically unposts the rcv buffers when
547 * when it gets a disable.
549 spin_lock_irqsave(&devdata
->priv_lock
, flags
);
550 while ((timeout
== VISORNIC_INFINITE_RSP_WAIT
) ||
552 if (devdata
->enab_dis_acked
)
554 if (devdata
->server_down
|| devdata
->server_change_state
) {
555 dev_dbg(&netdev
->dev
, "%s server went away\n",
559 set_current_state(TASK_INTERRUPTIBLE
);
560 spin_unlock_irqrestore(&devdata
->priv_lock
, flags
);
561 wait
+= schedule_timeout(msecs_to_jiffies(10));
562 spin_lock_irqsave(&devdata
->priv_lock
, flags
);
565 /* Wait for usage to go to 1 (no other users) before freeing
568 if (atomic_read(&devdata
->usage
) > 1) {
570 set_current_state(TASK_INTERRUPTIBLE
);
571 spin_unlock_irqrestore(&devdata
->priv_lock
, flags
);
572 schedule_timeout(msecs_to_jiffies(10));
573 spin_lock_irqsave(&devdata
->priv_lock
, flags
);
574 if (atomic_read(&devdata
->usage
))
578 /* we've set enabled to 0, so we can give up the lock. */
579 spin_unlock_irqrestore(&devdata
->priv_lock
, flags
);
581 /* stop the transmit queue so nothing more can be transmitted */
582 netif_stop_queue(netdev
);
584 napi_disable(&devdata
->napi
);
586 skb_queue_purge(&devdata
->xmitbufhead
);
588 /* Free rcv buffers - other end has automatically unposed them on
591 for (i
= 0; i
< devdata
->num_rcv_bufs
; i
++) {
592 if (devdata
->rcvbuf
[i
]) {
593 kfree_skb(devdata
->rcvbuf
[i
]);
594 devdata
->rcvbuf
[i
] = NULL
;
601 /* init_rcv_bufs - initialize receive buffs and send them to the IO Partition
602 * @netdev: struct netdevice.
603 * @devdata: visornic_devdata.
605 * Allocate rcv buffers and post them to the IO Partition.
607 * Return: 0 on success, negative integer on failure.
609 static int init_rcv_bufs(struct net_device
*netdev
,
610 struct visornic_devdata
*devdata
)
612 int i
, j
, count
, err
;
614 /* allocate fixed number of receive buffers to post to uisnic
615 * post receive buffers after we've allocated a required amount
617 for (i
= 0; i
< devdata
->num_rcv_bufs
; i
++) {
618 devdata
->rcvbuf
[i
] = alloc_rcv_buf(netdev
);
619 /* if we failed to allocate one let us stop */
620 if (!devdata
->rcvbuf
[i
])
623 /* couldn't even allocate one -- bail out */
628 /* Ensure we can alloc 2/3rd of the requested number of buffers.
629 * 2/3 is an arbitrary choice; used also in ndis init.c
631 if (count
< ((2 * devdata
->num_rcv_bufs
) / 3)) {
632 /* free receive buffers we did alloc and then bail out */
633 for (i
= 0; i
< count
; i
++) {
634 kfree_skb(devdata
->rcvbuf
[i
]);
635 devdata
->rcvbuf
[i
] = NULL
;
640 /* post receive buffers to receive incoming input - without holding
641 * lock - we've not enabled nor started the queue so there shouldn't
642 * be any rcv or xmit activity
644 for (i
= 0; i
< count
; i
++) {
645 err
= post_skb(devdata
->cmdrsp_rcv
, devdata
,
651 * If we posted at least one skb, we should return success,
652 * but need to free the resources that we have not successfully
655 for (j
= i
; j
< count
; j
++) {
656 kfree_skb(devdata
->rcvbuf
[j
]);
657 devdata
->rcvbuf
[j
] = NULL
;
667 /* visornic_enable_with_timeout - send enable to IO Partition
668 * @netdev: struct net_device.
669 * @timeout: Time to wait for the ACK from the enable.
671 * Sends enable to IOVM and inits, and posts receive buffers to IOVM. Timeout is
672 * defined in msecs (timeout of 0 specifies infinite wait).
674 * Return: 0 on success, negative integer on failure.
676 static int visornic_enable_with_timeout(struct net_device
*netdev
,
680 struct visornic_devdata
*devdata
= netdev_priv(netdev
);
684 napi_enable(&devdata
->napi
);
686 /* NOTE: the other end automatically unposts the rcv buffers when it
689 err
= init_rcv_bufs(netdev
, devdata
);
691 dev_err(&netdev
->dev
,
692 "%s failed to init rcv bufs\n", __func__
);
696 spin_lock_irqsave(&devdata
->priv_lock
, flags
);
697 devdata
->enabled
= 1;
698 devdata
->enab_dis_acked
= 0;
700 /* now we're ready, let's send an ENB to uisnic but until we get
701 * an ACK back from uisnic, we'll drop the packets
703 devdata
->n_rcv_packets_not_accepted
= 0;
704 spin_unlock_irqrestore(&devdata
->priv_lock
, flags
);
706 /* send enable and wait for ack -- don't hold lock when sending enable
707 * because if the queue is full, insert might sleep. If an error
710 err
= send_enbdis(netdev
, 1, devdata
);
714 spin_lock_irqsave(&devdata
->priv_lock
, flags
);
715 while ((timeout
== VISORNIC_INFINITE_RSP_WAIT
) ||
717 if (devdata
->enab_dis_acked
)
719 if (devdata
->server_down
|| devdata
->server_change_state
) {
720 dev_dbg(&netdev
->dev
, "%s server went away\n",
724 set_current_state(TASK_INTERRUPTIBLE
);
725 spin_unlock_irqrestore(&devdata
->priv_lock
, flags
);
726 wait
+= schedule_timeout(msecs_to_jiffies(10));
727 spin_lock_irqsave(&devdata
->priv_lock
, flags
);
730 spin_unlock_irqrestore(&devdata
->priv_lock
, flags
);
732 if (!devdata
->enab_dis_acked
) {
733 dev_err(&netdev
->dev
, "%s missing ACK\n", __func__
);
737 netif_start_queue(netdev
);
741 /* visornic_timeout_reset - handle xmit timeout resets
742 * @work: Work item that scheduled the work.
744 * Transmit timeouts are typically handled by resetting the device for our
745 * virtual NIC; we will send a disable and enable to the IOVM. If it doesn't
746 * respond, we will trigger a serverdown.
748 static void visornic_timeout_reset(struct work_struct
*work
)
750 struct visornic_devdata
*devdata
;
751 struct net_device
*netdev
;
754 devdata
= container_of(work
, struct visornic_devdata
, timeout_reset
);
755 netdev
= devdata
->netdev
;
758 if (!netif_running(netdev
)) {
763 response
= visornic_disable_with_timeout(netdev
,
764 VISORNIC_INFINITE_RSP_WAIT
);
766 goto call_serverdown
;
768 response
= visornic_enable_with_timeout(netdev
,
769 VISORNIC_INFINITE_RSP_WAIT
);
771 goto call_serverdown
;
778 visornic_serverdown(devdata
, NULL
);
782 /* visornic_open - enable the visornic device and mark the queue started
783 * @netdev: netdevice to start.
785 * Enable the device and start the transmit queue.
787 * Return: 0 on success.
789 static int visornic_open(struct net_device
*netdev
)
791 visornic_enable_with_timeout(netdev
, VISORNIC_INFINITE_RSP_WAIT
);
795 /* visornic_close - disables the visornic device and stops the queues
796 * @netdev: netdevice to stop.
798 * Disable the device and stop the transmit queue.
800 * Return 0 on success.
802 static int visornic_close(struct net_device
*netdev
)
804 visornic_disable_with_timeout(netdev
, VISORNIC_INFINITE_RSP_WAIT
);
808 /* devdata_xmits_outstanding - compute outstanding xmits
809 * @devdata: visornic_devdata for device
811 * Return: Long integer representing the number of outstanding xmits.
813 static unsigned long devdata_xmits_outstanding(struct visornic_devdata
*devdata
)
815 if (devdata
->chstat
.sent_xmit
>= devdata
->chstat
.got_xmit_done
)
816 return devdata
->chstat
.sent_xmit
-
817 devdata
->chstat
.got_xmit_done
;
818 return (ULONG_MAX
- devdata
->chstat
.got_xmit_done
819 + devdata
->chstat
.sent_xmit
+ 1);
822 /* vnic_hit_high_watermark
823 * @devdata: Indicates visornic device we are checking.
824 * @high_watermark: Max num of unacked xmits we will tolerate before we will
827 * Return: True iff the number of unacked xmits sent to the IO Partition is >=
828 * high_watermark. False otherwise.
830 static bool vnic_hit_high_watermark(struct visornic_devdata
*devdata
,
831 ulong high_watermark
)
833 return (devdata_xmits_outstanding(devdata
) >= high_watermark
);
836 /* vnic_hit_low_watermark
837 * @devdata: Indicates visornic device we are checking.
838 * @low_watermark: We will wait until the num of unacked xmits drops to this
839 * value or lower before we start transmitting again.
841 * Return: True iff the number of unacked xmits sent to the IO Partition is <=
844 static bool vnic_hit_low_watermark(struct visornic_devdata
*devdata
,
847 return (devdata_xmits_outstanding(devdata
) <= low_watermark
);
850 /* visornic_xmit - send a packet to the IO Partition
851 * @skb: Packet to be sent.
852 * @netdev: Net device the packet is being sent from.
854 * Convert the skb to a cmdrsp so the IO Partition can understand it, and send
855 * the XMIT command to the IO Partition for processing. This function is
856 * protected from concurrent calls by a spinlock xmit_lock in the net_device
857 * struct. As soon as the function returns, it can be called again.
859 * Return: NETDEV_TX_OK.
861 static int visornic_xmit(struct sk_buff
*skb
, struct net_device
*netdev
)
863 struct visornic_devdata
*devdata
;
864 int len
, firstfraglen
, padlen
;
865 struct uiscmdrsp
*cmdrsp
= NULL
;
869 devdata
= netdev_priv(netdev
);
870 spin_lock_irqsave(&devdata
->priv_lock
, flags
);
872 if (netif_queue_stopped(netdev
) || devdata
->server_down
||
873 devdata
->server_change_state
) {
874 spin_unlock_irqrestore(&devdata
->priv_lock
, flags
);
876 dev_dbg(&netdev
->dev
,
877 "%s busy - queue stopped\n", __func__
);
882 /* sk_buff struct is used to host network data throughout all the
883 * linux network subsystems
887 /* skb->len is the FULL length of data (including fragmentary portion)
888 * skb->data_len is the length of the fragment portion in frags
889 * skb->len - skb->data_len is size of the 1st fragment in skb->data
890 * calculate the length of the first fragment that skb->data is
893 firstfraglen
= skb
->len
- skb
->data_len
;
894 if (firstfraglen
< ETH_HLEN
) {
895 spin_unlock_irqrestore(&devdata
->priv_lock
, flags
);
897 dev_err(&netdev
->dev
,
898 "%s busy - first frag too small (%d)\n",
899 __func__
, firstfraglen
);
904 if (len
< ETH_MIN_PACKET_SIZE
&&
905 ((skb_end_pointer(skb
) - skb
->data
) >= ETH_MIN_PACKET_SIZE
)) {
906 /* pad the packet out to minimum size */
907 padlen
= ETH_MIN_PACKET_SIZE
- len
;
908 memset(&skb
->data
[len
], 0, padlen
);
912 firstfraglen
+= padlen
;
915 cmdrsp
= devdata
->xmit_cmdrsp
;
917 memset(cmdrsp
, 0, SIZEOF_CMDRSP
);
918 cmdrsp
->net
.type
= NET_XMIT
;
919 cmdrsp
->cmdtype
= CMD_NET_TYPE
;
921 /* save the pointer to skb -- we'll need it for completion */
922 cmdrsp
->net
.buf
= skb
;
924 if (vnic_hit_high_watermark(devdata
,
925 devdata
->max_outstanding_net_xmits
)) {
926 /* extra NET_XMITs queued over to IOVM - need to wait */
927 devdata
->chstat
.reject_count
++;
928 if (!devdata
->queuefullmsg_logged
&&
929 ((devdata
->chstat
.reject_count
& 0x3ff) == 1))
930 devdata
->queuefullmsg_logged
= 1;
931 netif_stop_queue(netdev
);
932 spin_unlock_irqrestore(&devdata
->priv_lock
, flags
);
934 dev_dbg(&netdev
->dev
,
935 "%s busy - waiting for iovm to catch up\n",
940 if (devdata
->queuefullmsg_logged
)
941 devdata
->queuefullmsg_logged
= 0;
943 if (skb
->ip_summed
== CHECKSUM_UNNECESSARY
) {
944 cmdrsp
->net
.xmt
.lincsum
.valid
= 1;
945 cmdrsp
->net
.xmt
.lincsum
.protocol
= skb
->protocol
;
946 if (skb_transport_header(skb
) > skb
->data
) {
947 cmdrsp
->net
.xmt
.lincsum
.hrawoff
=
948 skb_transport_header(skb
) - skb
->data
;
949 cmdrsp
->net
.xmt
.lincsum
.hrawoff
= 1;
951 if (skb_network_header(skb
) > skb
->data
) {
952 cmdrsp
->net
.xmt
.lincsum
.nhrawoff
=
953 skb_network_header(skb
) - skb
->data
;
954 cmdrsp
->net
.xmt
.lincsum
.nhrawoffv
= 1;
956 cmdrsp
->net
.xmt
.lincsum
.csum
= skb
->csum
;
958 cmdrsp
->net
.xmt
.lincsum
.valid
= 0;
961 /* save off the length of the entire data packet */
962 cmdrsp
->net
.xmt
.len
= len
;
964 /* copy ethernet header from first frag into ocmdrsp
965 * - everything else will be pass in frags & DMA'ed
967 memcpy(cmdrsp
->net
.xmt
.ethhdr
, skb
->data
, ETH_HLEN
);
969 /* copy frags info - from skb->data we need to only provide access
972 cmdrsp
->net
.xmt
.num_frags
=
973 visor_copy_fragsinfo_from_skb(skb
, firstfraglen
,
975 cmdrsp
->net
.xmt
.frags
);
976 if (cmdrsp
->net
.xmt
.num_frags
< 0) {
977 spin_unlock_irqrestore(&devdata
->priv_lock
, flags
);
979 dev_err(&netdev
->dev
,
980 "%s busy - copy frags failed\n", __func__
);
985 err
= visorchannel_signalinsert(devdata
->dev
->visorchannel
,
986 IOCHAN_TO_IOPART
, cmdrsp
);
988 netif_stop_queue(netdev
);
989 spin_unlock_irqrestore(&devdata
->priv_lock
, flags
);
991 dev_dbg(&netdev
->dev
,
992 "%s busy - signalinsert failed\n", __func__
);
997 /* Track the skbs that have been sent to the IOVM for XMIT */
998 skb_queue_head(&devdata
->xmitbufhead
, skb
);
1000 /* update xmt stats */
1001 devdata
->net_stats
.tx_packets
++;
1002 devdata
->net_stats
.tx_bytes
+= skb
->len
;
1003 devdata
->chstat
.sent_xmit
++;
1005 /* check if we have hit the high watermark for netif_stop_queue() */
1006 if (vnic_hit_high_watermark(devdata
,
1007 devdata
->upper_threshold_net_xmits
)) {
1008 /* extra NET_XMITs queued over to IOVM - need to wait */
1009 /* stop queue - call netif_wake_queue() after lower threshold */
1010 netif_stop_queue(netdev
);
1011 dev_dbg(&netdev
->dev
,
1012 "%s busy - invoking iovm flow control\n",
1014 devdata
->flow_control_upper_hits
++;
1016 spin_unlock_irqrestore(&devdata
->priv_lock
, flags
);
1018 /* skb will be freed when we get back NET_XMIT_DONE */
1019 return NETDEV_TX_OK
;
1022 /* visornic_get_stats - returns net_stats of the visornic device
1023 * @netdev: netdevice.
1025 * Return: Pointer to the net_device_stats struct for the device.
1027 static struct net_device_stats
*visornic_get_stats(struct net_device
*netdev
)
1029 struct visornic_devdata
*devdata
= netdev_priv(netdev
);
1031 return &devdata
->net_stats
;
1034 /* visornic_change_mtu - changes mtu of device
1035 * @netdev: netdevice.
1036 * @new_mtu: Value of new mtu.
1038 * The device's MTU cannot be changed by system; it must be changed via a
1039 * CONTROLVM message. All vnics and pnics in a switch have to have the same MTU
1040 * for everything to work. Currently not supported.
1044 static int visornic_change_mtu(struct net_device
*netdev
, int new_mtu
)
1049 /* visornic_set_multi - set visornic device flags
1050 * @netdev: netdevice.
1052 * The only flag we currently support is IFF_PROMISC.
1054 static void visornic_set_multi(struct net_device
*netdev
)
1056 struct uiscmdrsp
*cmdrsp
;
1057 struct visornic_devdata
*devdata
= netdev_priv(netdev
);
1060 if (devdata
->old_flags
== netdev
->flags
)
1063 if ((netdev
->flags
& IFF_PROMISC
) ==
1064 (devdata
->old_flags
& IFF_PROMISC
))
1065 goto out_save_flags
;
1067 cmdrsp
= kmalloc(SIZEOF_CMDRSP
, GFP_ATOMIC
);
1070 cmdrsp
->cmdtype
= CMD_NET_TYPE
;
1071 cmdrsp
->net
.type
= NET_RCV_PROMISC
;
1072 cmdrsp
->net
.enbdis
.context
= netdev
;
1073 cmdrsp
->net
.enbdis
.enable
=
1074 netdev
->flags
& IFF_PROMISC
;
1075 err
= visorchannel_signalinsert(devdata
->dev
->visorchannel
,
1083 devdata
->old_flags
= netdev
->flags
;
1086 /* visornic_xmit_timeout - request to timeout the xmit
1087 * @netdev: netdevice.
1089 * Queue the work and return. Make sure we have not already been informed that
1090 * the IO Partition is gone; if so, we will have already timed-out the xmits.
1092 static void visornic_xmit_timeout(struct net_device
*netdev
)
1094 struct visornic_devdata
*devdata
= netdev_priv(netdev
);
1095 unsigned long flags
;
1097 spin_lock_irqsave(&devdata
->priv_lock
, flags
);
1098 if (devdata
->going_away
) {
1099 spin_unlock_irqrestore(&devdata
->priv_lock
, flags
);
1100 dev_dbg(&devdata
->dev
->device
,
1101 "%s aborting because device removal pending\n",
1106 /* Ensure that a ServerDown message hasn't been received */
1107 if (!devdata
->enabled
||
1108 (devdata
->server_down
&& !devdata
->server_change_state
)) {
1109 dev_dbg(&netdev
->dev
, "%s no processing\n",
1111 spin_unlock_irqrestore(&devdata
->priv_lock
, flags
);
1114 schedule_work(&devdata
->timeout_reset
);
1115 spin_unlock_irqrestore(&devdata
->priv_lock
, flags
);
1118 /* repost_return - repost rcv bufs that have come back
1119 * @cmdrsp: IO channel command struct to post.
1120 * @devdata: Visornic devdata for the device.
1121 * @skb: Socket buffer.
1122 * @netdev: netdevice.
1124 * Repost rcv buffers that have been returned to us when we are finished
1127 * Return: 0 for success, negative integer on error.
1129 static int repost_return(struct uiscmdrsp
*cmdrsp
,
1130 struct visornic_devdata
*devdata
,
1131 struct sk_buff
*skb
, struct net_device
*netdev
)
1133 struct net_pkt_rcv copy
;
1134 int i
= 0, cc
, numreposted
;
1138 copy
= cmdrsp
->net
.rcv
;
1139 switch (copy
.numrcvbufs
) {
1153 for (cc
= 0, numreposted
= 0; cc
< copy
.numrcvbufs
; cc
++) {
1154 for (i
= 0; i
< devdata
->num_rcv_bufs
; i
++) {
1155 if (devdata
->rcvbuf
[i
] != copy
.rcvbuf
[cc
])
1158 if ((skb
) && devdata
->rcvbuf
[i
] == skb
) {
1159 devdata
->found_repost_rcvbuf_cnt
++;
1161 devdata
->repost_found_skb_cnt
++;
1163 devdata
->rcvbuf
[i
] = alloc_rcv_buf(netdev
);
1164 if (!devdata
->rcvbuf
[i
]) {
1165 devdata
->num_rcv_bufs_could_not_alloc
++;
1166 devdata
->alloc_failed_in_repost_rtn_cnt
++;
1170 status
= post_skb(cmdrsp
, devdata
, devdata
->rcvbuf
[i
]);
1172 kfree_skb(devdata
->rcvbuf
[i
]);
1173 devdata
->rcvbuf
[i
] = NULL
;
1180 if (numreposted
!= copy
.numrcvbufs
) {
1181 devdata
->n_repost_deficit
++;
1189 devdata
->bad_rcv_buf
++;
1195 /* visornic_rx - handle receive packets coming back from IO Partition
1196 * @cmdrsp: Receive packet returned from IO Partition.
1198 * Got a receive packet back from the IO Partition; handle it and send it up
1201 * Return: 1 iff an skb was received, otherwise 0.
1203 static int visornic_rx(struct uiscmdrsp
*cmdrsp
)
1205 struct visornic_devdata
*devdata
;
1206 struct sk_buff
*skb
, *prev
, *curr
;
1207 struct net_device
*netdev
;
1208 int cc
, currsize
, off
;
1210 unsigned long flags
;
1212 /* post new rcv buf to the other end using the cmdrsp we have at hand
1213 * post it without holding lock - but we'll use the signal lock to
1214 * synchronize the queue insert the cmdrsp that contains the net.rcv
1215 * is the one we are using to repost, so copy the info we need from it.
1217 skb
= cmdrsp
->net
.buf
;
1220 devdata
= netdev_priv(netdev
);
1222 spin_lock_irqsave(&devdata
->priv_lock
, flags
);
1223 atomic_dec(&devdata
->num_rcvbuf_in_iovm
);
1225 /* set length to how much was ACTUALLY received -
1226 * NOTE: rcv_done_len includes actual length of data rcvd
1229 skb
->len
= cmdrsp
->net
.rcv
.rcv_done_len
;
1231 /* update rcv stats - call it with priv_lock held */
1232 devdata
->net_stats
.rx_packets
++;
1233 devdata
->net_stats
.rx_bytes
+= skb
->len
;
1235 /* test enabled while holding lock */
1236 if (!(devdata
->enabled
&& devdata
->enab_dis_acked
)) {
1237 /* don't process it unless we're in enable mode and until
1238 * we've gotten an ACK saying the other end got our RCV enable
1240 spin_unlock_irqrestore(&devdata
->priv_lock
, flags
);
1241 repost_return(cmdrsp
, devdata
, skb
, netdev
);
1245 spin_unlock_irqrestore(&devdata
->priv_lock
, flags
);
1247 /* when skb was allocated, skb->dev, skb->data, skb->len and
1248 * skb->data_len were setup. AND, data has already put into the
1249 * skb (both first frag and in frags pages)
1250 * NOTE: firstfragslen is the amount of data in skb->data and that
1251 * which is not in nr_frags or frag_list. This is now simply
1252 * RCVPOST_BUF_SIZE. bump tail to show how much data is in
1253 * firstfrag & set data_len to show rest see if we have to chain
1256 /* do PRECAUTIONARY check */
1257 if (skb
->len
> RCVPOST_BUF_SIZE
) {
1258 if (cmdrsp
->net
.rcv
.numrcvbufs
< 2) {
1259 if (repost_return(cmdrsp
, devdata
, skb
, netdev
) < 0)
1260 dev_err(&devdata
->netdev
->dev
,
1261 "repost_return failed");
1264 /* length rcvd is greater than firstfrag in this skb rcv buf */
1265 /* amount in skb->data */
1266 skb
->tail
+= RCVPOST_BUF_SIZE
;
1267 /* amount that will be in frag_list */
1268 skb
->data_len
= skb
->len
- RCVPOST_BUF_SIZE
;
1270 /* data fits in this skb - no chaining - do
1271 * PRECAUTIONARY check
1274 if (cmdrsp
->net
.rcv
.numrcvbufs
!= 1) {
1275 if (repost_return(cmdrsp
, devdata
, skb
, netdev
) < 0)
1276 dev_err(&devdata
->netdev
->dev
,
1277 "repost_return failed");
1280 skb
->tail
+= skb
->len
;
1281 /* nothing rcvd in frag_list */
1284 off
= skb_tail_pointer(skb
) - skb
->data
;
1286 /* amount we bumped tail by in the head skb
1287 * it is used to calculate the size of each chained skb below
1288 * it is also used to index into bufline to continue the copy
1289 * (for chansocktwopc)
1290 * if necessary chain the rcv skbs together.
1291 * NOTE: index 0 has the same as cmdrsp->net.rcv.skb; we need to
1292 * chain the rest to that one.
1293 * - do PRECAUTIONARY check
1295 if (cmdrsp
->net
.rcv
.rcvbuf
[0] != skb
) {
1296 if (repost_return(cmdrsp
, devdata
, skb
, netdev
) < 0)
1297 dev_err(&devdata
->netdev
->dev
, "repost_return failed");
1301 if (cmdrsp
->net
.rcv
.numrcvbufs
> 1) {
1302 /* chain the various rcv buffers into the skb's frag_list. */
1303 /* Note: off was initialized above */
1304 for (cc
= 1, prev
= NULL
;
1305 cc
< cmdrsp
->net
.rcv
.numrcvbufs
; cc
++) {
1306 curr
= (struct sk_buff
*)cmdrsp
->net
.rcv
.rcvbuf
[cc
];
1308 /* start of list- set head */
1310 skb_shinfo(skb
)->frag_list
= curr
;
1315 /* should we set skb->len and skb->data_len for each
1316 * buffer being chained??? can't hurt!
1318 currsize
= min(skb
->len
- off
,
1319 (unsigned int)RCVPOST_BUF_SIZE
);
1320 curr
->len
= currsize
;
1321 curr
->tail
+= currsize
;
1325 /* assert skb->len == off */
1326 if (skb
->len
!= off
) {
1327 netdev_err(devdata
->netdev
,
1328 "something wrong; skb->len:%d != off:%d\n",
1333 /* set up packet's protocol type using ethernet header - this
1334 * sets up skb->pkt_type & it also PULLS out the eth header
1336 skb
->protocol
= eth_type_trans(skb
, netdev
);
1339 skb
->ip_summed
= CHECKSUM_NONE
;
1342 /* accept all packets */
1343 if (netdev
->flags
& IFF_PROMISC
)
1345 if (skb
->pkt_type
== PACKET_BROADCAST
) {
1346 /* accept all broadcast packets */
1347 if (netdev
->flags
& IFF_BROADCAST
)
1349 } else if (skb
->pkt_type
== PACKET_MULTICAST
) {
1350 if ((netdev
->flags
& IFF_MULTICAST
) &&
1351 (netdev_mc_count(netdev
))) {
1352 struct netdev_hw_addr
*ha
;
1355 /* only accept multicast packets that we can
1356 * find in our multicast address list
1358 netdev_for_each_mc_addr(ha
, netdev
) {
1359 if (ether_addr_equal(eth
->h_dest
,
1365 /* accept pkt, dest matches a multicast addr */
1369 /* accept packet, h_dest must match vnic mac address */
1370 } else if (skb
->pkt_type
== PACKET_HOST
) {
1372 } else if (skb
->pkt_type
== PACKET_OTHERHOST
) {
1373 /* something is not right */
1374 dev_err(&devdata
->netdev
->dev
,
1375 "**** FAILED to deliver rcv packet to OS; name:%s Dest:%pM VNIC:%pM\n",
1376 netdev
->name
, eth
->h_dest
, netdev
->dev_addr
);
1378 /* drop packet - don't forward it up to OS */
1379 devdata
->n_rcv_packets_not_accepted
++;
1380 repost_return(cmdrsp
, devdata
, skb
, netdev
);
1384 netif_receive_skb(skb
);
1385 /* netif_rx returns various values, but "in practice most drivers
1386 * ignore the return value
1390 /* whether the packet got dropped or handled, the skb is freed by
1391 * kernel code, so we shouldn't free it. but we should repost a
1394 repost_return(cmdrsp
, devdata
, skb
, netdev
);
1398 /* devdata_initialize - initialize devdata structure
1399 * @devdata: visornic_devdata structure to initialize.
1400 * @dev: visorbus_device it belongs to.
1402 * Setup initial values for the visornic, based on channel and default values.
1404 * Return: A pointer to the devdata structure.
1406 static struct visornic_devdata
*devdata_initialize(
1407 struct visornic_devdata
*devdata
,
1408 struct visor_device
*dev
)
1411 devdata
->incarnation_id
= get_jiffies_64();
1415 /* devdata_release - free up references in devdata
1416 * @devdata: Struct to clean up.
1418 static void devdata_release(struct visornic_devdata
*devdata
)
1420 kfree(devdata
->rcvbuf
);
1421 kfree(devdata
->cmdrsp_rcv
);
1422 kfree(devdata
->xmit_cmdrsp
);
1425 static const struct net_device_ops visornic_dev_ops
= {
1426 .ndo_open
= visornic_open
,
1427 .ndo_stop
= visornic_close
,
1428 .ndo_start_xmit
= visornic_xmit
,
1429 .ndo_get_stats
= visornic_get_stats
,
1430 .ndo_change_mtu
= visornic_change_mtu
,
1431 .ndo_tx_timeout
= visornic_xmit_timeout
,
1432 .ndo_set_rx_mode
= visornic_set_multi
,
1436 static ssize_t
info_debugfs_read(struct file
*file
, char __user
*buf
,
1437 size_t len
, loff_t
*offset
)
1439 ssize_t bytes_read
= 0;
1441 struct visornic_devdata
*devdata
;
1442 struct net_device
*dev
;
1447 vbuf
= kzalloc(len
, GFP_KERNEL
);
1451 /* for each vnic channel dump out channel specific data */
1453 for_each_netdev_rcu(current
->nsproxy
->net_ns
, dev
) {
1454 /* Only consider netdevs that are visornic, and are open */
1455 if (dev
->netdev_ops
!= &visornic_dev_ops
||
1456 (!netif_queue_stopped(dev
)))
1459 devdata
= netdev_priv(dev
);
1460 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1461 "netdev = %s (0x%p), MAC Addr %pM\n",
1465 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1466 "VisorNic Dev Info = 0x%p\n", devdata
);
1467 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1468 " num_rcv_bufs = %d\n",
1469 devdata
->num_rcv_bufs
);
1470 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1471 " max_outstanding_next_xmits = %lu\n",
1472 devdata
->max_outstanding_net_xmits
);
1473 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1474 " upper_threshold_net_xmits = %lu\n",
1475 devdata
->upper_threshold_net_xmits
);
1476 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1477 " lower_threshold_net_xmits = %lu\n",
1478 devdata
->lower_threshold_net_xmits
);
1479 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1480 " queuefullmsg_logged = %d\n",
1481 devdata
->queuefullmsg_logged
);
1482 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1483 " chstat.got_rcv = %lu\n",
1484 devdata
->chstat
.got_rcv
);
1485 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1486 " chstat.got_enbdisack = %lu\n",
1487 devdata
->chstat
.got_enbdisack
);
1488 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1489 " chstat.got_xmit_done = %lu\n",
1490 devdata
->chstat
.got_xmit_done
);
1491 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1492 " chstat.xmit_fail = %lu\n",
1493 devdata
->chstat
.xmit_fail
);
1494 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1495 " chstat.sent_enbdis = %lu\n",
1496 devdata
->chstat
.sent_enbdis
);
1497 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1498 " chstat.sent_promisc = %lu\n",
1499 devdata
->chstat
.sent_promisc
);
1500 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1501 " chstat.sent_post = %lu\n",
1502 devdata
->chstat
.sent_post
);
1503 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1504 " chstat.sent_post_failed = %lu\n",
1505 devdata
->chstat
.sent_post_failed
);
1506 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1507 " chstat.sent_xmit = %lu\n",
1508 devdata
->chstat
.sent_xmit
);
1509 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1510 " chstat.reject_count = %lu\n",
1511 devdata
->chstat
.reject_count
);
1512 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1513 " chstat.extra_rcvbufs_sent = %lu\n",
1514 devdata
->chstat
.extra_rcvbufs_sent
);
1515 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1516 " n_rcv0 = %lu\n", devdata
->n_rcv0
);
1517 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1518 " n_rcv1 = %lu\n", devdata
->n_rcv1
);
1519 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1520 " n_rcv2 = %lu\n", devdata
->n_rcv2
);
1521 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1522 " n_rcvx = %lu\n", devdata
->n_rcvx
);
1523 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1524 " num_rcvbuf_in_iovm = %d\n",
1525 atomic_read(&devdata
->num_rcvbuf_in_iovm
));
1526 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1527 " alloc_failed_in_if_needed_cnt = %lu\n",
1528 devdata
->alloc_failed_in_if_needed_cnt
);
1529 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1530 " alloc_failed_in_repost_rtn_cnt = %lu\n",
1531 devdata
->alloc_failed_in_repost_rtn_cnt
);
1532 /* str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1533 * " inner_loop_limit_reached_cnt = %lu\n",
1534 * devdata->inner_loop_limit_reached_cnt);
1536 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1537 " found_repost_rcvbuf_cnt = %lu\n",
1538 devdata
->found_repost_rcvbuf_cnt
);
1539 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1540 " repost_found_skb_cnt = %lu\n",
1541 devdata
->repost_found_skb_cnt
);
1542 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1543 " n_repost_deficit = %lu\n",
1544 devdata
->n_repost_deficit
);
1545 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1546 " bad_rcv_buf = %lu\n",
1547 devdata
->bad_rcv_buf
);
1548 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1549 " n_rcv_packets_not_accepted = %lu\n",
1550 devdata
->n_rcv_packets_not_accepted
);
1551 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1552 " interrupts_rcvd = %llu\n",
1553 devdata
->interrupts_rcvd
);
1554 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1555 " interrupts_notme = %llu\n",
1556 devdata
->interrupts_notme
);
1557 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1558 " interrupts_disabled = %llu\n",
1559 devdata
->interrupts_disabled
);
1560 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1561 " busy_cnt = %llu\n",
1563 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1564 " flow_control_upper_hits = %llu\n",
1565 devdata
->flow_control_upper_hits
);
1566 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1567 " flow_control_lower_hits = %llu\n",
1568 devdata
->flow_control_lower_hits
);
1569 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1570 " netif_queue = %s\n",
1571 netif_queue_stopped(devdata
->netdev
) ?
1572 "stopped" : "running");
1573 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1574 " xmits_outstanding = %lu\n",
1575 devdata_xmits_outstanding(devdata
));
1578 bytes_read
= simple_read_from_buffer(buf
, len
, offset
, vbuf
, str_pos
);
1583 static struct dentry
*visornic_debugfs_dir
;
1584 static const struct file_operations debugfs_info_fops
= {
1585 .read
= info_debugfs_read
,
1588 /* send_rcv_posts_if_needed - send receive buffers to the IO Partition.
1589 * @devdata: Visornic device.
1591 static void send_rcv_posts_if_needed(struct visornic_devdata
*devdata
)
1594 struct net_device
*netdev
;
1595 struct uiscmdrsp
*cmdrsp
= devdata
->cmdrsp_rcv
;
1596 int cur_num_rcv_bufs_to_alloc
, rcv_bufs_allocated
;
1599 /* don't do this until vnic is marked ready */
1600 if (!(devdata
->enabled
&& devdata
->enab_dis_acked
))
1603 netdev
= devdata
->netdev
;
1604 rcv_bufs_allocated
= 0;
1605 /* this code is trying to prevent getting stuck here forever,
1606 * but still retry it if you cant allocate them all this time.
1608 cur_num_rcv_bufs_to_alloc
= devdata
->num_rcv_bufs_could_not_alloc
;
1609 while (cur_num_rcv_bufs_to_alloc
> 0) {
1610 cur_num_rcv_bufs_to_alloc
--;
1611 for (i
= 0; i
< devdata
->num_rcv_bufs
; i
++) {
1612 if (devdata
->rcvbuf
[i
])
1614 devdata
->rcvbuf
[i
] = alloc_rcv_buf(netdev
);
1615 if (!devdata
->rcvbuf
[i
]) {
1616 devdata
->alloc_failed_in_if_needed_cnt
++;
1619 rcv_bufs_allocated
++;
1620 err
= post_skb(cmdrsp
, devdata
, devdata
->rcvbuf
[i
]);
1622 kfree_skb(devdata
->rcvbuf
[i
]);
1623 devdata
->rcvbuf
[i
] = NULL
;
1626 devdata
->chstat
.extra_rcvbufs_sent
++;
1629 devdata
->num_rcv_bufs_could_not_alloc
-= rcv_bufs_allocated
;
1632 /* drain_resp_queue - drains and ignores all messages from the resp queue
1633 * @cmdrsp: IO channel command response message.
1634 * @devdata: Visornic device to drain.
1636 static void drain_resp_queue(struct uiscmdrsp
*cmdrsp
,
1637 struct visornic_devdata
*devdata
)
1639 while (!visorchannel_signalremove(devdata
->dev
->visorchannel
,
1645 /* service_resp_queue - drain the response queue
1646 * @cmdrsp: IO channel command response message.
1647 * @devdata: Visornic device to drain.
1651 * Drain the response queue of any responses from the IO Partition. Process the
1652 * responses as we get them.
1654 static void service_resp_queue(struct uiscmdrsp
*cmdrsp
,
1655 struct visornic_devdata
*devdata
,
1656 int *rx_work_done
, int budget
)
1658 unsigned long flags
;
1659 struct net_device
*netdev
;
1661 while (*rx_work_done
< budget
) {
1662 /* TODO: CLIENT ACQUIRE -- Don't really need this at the
1666 if (visorchannel_signalremove(devdata
->dev
->visorchannel
,
1671 switch (cmdrsp
->net
.type
) {
1673 devdata
->chstat
.got_rcv
++;
1674 /* process incoming packet */
1675 *rx_work_done
+= visornic_rx(cmdrsp
);
1678 spin_lock_irqsave(&devdata
->priv_lock
, flags
);
1679 devdata
->chstat
.got_xmit_done
++;
1680 if (cmdrsp
->net
.xmtdone
.xmt_done_result
)
1681 devdata
->chstat
.xmit_fail
++;
1682 /* only call queue wake if we stopped it */
1683 netdev
= ((struct sk_buff
*)cmdrsp
->net
.buf
)->dev
;
1684 /* ASSERT netdev == vnicinfo->netdev; */
1685 if (netdev
== devdata
->netdev
&&
1686 netif_queue_stopped(netdev
)) {
1687 /* check if we have crossed the lower watermark
1688 * for netif_wake_queue()
1690 if (vnic_hit_low_watermark
1692 devdata
->lower_threshold_net_xmits
)) {
1693 /* enough NET_XMITs completed
1694 * so can restart netif queue
1696 netif_wake_queue(netdev
);
1697 devdata
->flow_control_lower_hits
++;
1700 skb_unlink(cmdrsp
->net
.buf
, &devdata
->xmitbufhead
);
1701 spin_unlock_irqrestore(&devdata
->priv_lock
, flags
);
1702 kfree_skb(cmdrsp
->net
.buf
);
1704 case NET_RCV_ENBDIS_ACK
:
1705 devdata
->chstat
.got_enbdisack
++;
1706 netdev
= (struct net_device
*)
1707 cmdrsp
->net
.enbdis
.context
;
1708 spin_lock_irqsave(&devdata
->priv_lock
, flags
);
1709 devdata
->enab_dis_acked
= 1;
1710 spin_unlock_irqrestore(&devdata
->priv_lock
, flags
);
1712 if (devdata
->server_down
&&
1713 devdata
->server_change_state
) {
1714 /* Inform Linux that the link is up */
1715 devdata
->server_down
= false;
1716 devdata
->server_change_state
= false;
1717 netif_wake_queue(netdev
);
1718 netif_carrier_on(netdev
);
1721 case NET_CONNECT_STATUS
:
1722 netdev
= devdata
->netdev
;
1723 if (cmdrsp
->net
.enbdis
.enable
== 1) {
1724 spin_lock_irqsave(&devdata
->priv_lock
, flags
);
1725 devdata
->enabled
= cmdrsp
->net
.enbdis
.enable
;
1726 spin_unlock_irqrestore(&devdata
->priv_lock
,
1728 netif_wake_queue(netdev
);
1729 netif_carrier_on(netdev
);
1731 netif_stop_queue(netdev
);
1732 netif_carrier_off(netdev
);
1733 spin_lock_irqsave(&devdata
->priv_lock
, flags
);
1734 devdata
->enabled
= cmdrsp
->net
.enbdis
.enable
;
1735 spin_unlock_irqrestore(&devdata
->priv_lock
,
1742 /* cmdrsp is now available for reuse */
1746 static int visornic_poll(struct napi_struct
*napi
, int budget
)
1748 struct visornic_devdata
*devdata
= container_of(napi
,
1749 struct visornic_devdata
,
1753 send_rcv_posts_if_needed(devdata
);
1754 service_resp_queue(devdata
->cmdrsp
, devdata
, &rx_count
, budget
);
1756 /* If there aren't any more packets to receive stop the poll */
1757 if (rx_count
< budget
)
1758 napi_complete_done(napi
, rx_count
);
1763 /* poll_for_irq - checks the status of the response queue
1764 * @v: Void pointer to the visronic devdata struct.
1766 * Main function of the vnic_incoming thread. Periodically check the response
1767 * queue and drain it if needed.
1769 static void poll_for_irq(unsigned long v
)
1771 struct visornic_devdata
*devdata
= (struct visornic_devdata
*)v
;
1773 if (!visorchannel_signalempty(
1774 devdata
->dev
->visorchannel
,
1775 IOCHAN_FROM_IOPART
))
1776 napi_schedule(&devdata
->napi
);
1778 atomic_set(&devdata
->interrupt_rcvd
, 0);
1780 mod_timer(&devdata
->irq_poll_timer
, msecs_to_jiffies(2));
1783 /* visornic_probe - probe function for visornic devices
1784 * @dev: The visor device discovered.
1786 * Called when visorbus discovers a visornic device on its bus. It creates a new
1787 * visornic ethernet adapter.
1789 * Return: 0 on success, or negative integer on error.
1791 static int visornic_probe(struct visor_device
*dev
)
1793 struct visornic_devdata
*devdata
= NULL
;
1794 struct net_device
*netdev
= NULL
;
1796 int channel_offset
= 0;
1799 netdev
= alloc_etherdev(sizeof(struct visornic_devdata
));
1801 dev_err(&dev
->device
,
1802 "%s alloc_etherdev failed\n", __func__
);
1806 netdev
->netdev_ops
= &visornic_dev_ops
;
1807 netdev
->watchdog_timeo
= 5 * HZ
;
1808 SET_NETDEV_DEV(netdev
, &dev
->device
);
1810 /* Get MAC address from channel and read it into the device. */
1811 netdev
->addr_len
= ETH_ALEN
;
1812 channel_offset
= offsetof(struct visor_io_channel
, vnic
.macaddr
);
1813 err
= visorbus_read_channel(dev
, channel_offset
, netdev
->dev_addr
,
1816 dev_err(&dev
->device
,
1817 "%s failed to get mac addr from chan (%d)\n",
1819 goto cleanup_netdev
;
1822 devdata
= devdata_initialize(netdev_priv(netdev
), dev
);
1824 dev_err(&dev
->device
,
1825 "%s devdata_initialize failed\n", __func__
);
1827 goto cleanup_netdev
;
1829 /* don't trust messages laying around in the channel */
1830 drain_resp_queue(devdata
->cmdrsp
, devdata
);
1832 devdata
->netdev
= netdev
;
1833 dev_set_drvdata(&dev
->device
, devdata
);
1834 init_waitqueue_head(&devdata
->rsp_queue
);
1835 spin_lock_init(&devdata
->priv_lock
);
1837 devdata
->enabled
= 0;
1838 atomic_set(&devdata
->usage
, 1);
1840 /* Setup rcv bufs */
1841 channel_offset
= offsetof(struct visor_io_channel
, vnic
.num_rcv_bufs
);
1842 err
= visorbus_read_channel(dev
, channel_offset
,
1843 &devdata
->num_rcv_bufs
, 4);
1845 dev_err(&dev
->device
,
1846 "%s failed to get #rcv bufs from chan (%d)\n",
1848 goto cleanup_netdev
;
1851 devdata
->rcvbuf
= kcalloc(devdata
->num_rcv_bufs
,
1852 sizeof(struct sk_buff
*), GFP_KERNEL
);
1853 if (!devdata
->rcvbuf
) {
1855 goto cleanup_netdev
;
1858 /* set the net_xmit outstanding threshold
1859 * always leave two slots open but you should have 3 at a minimum
1860 * note that max_outstanding_net_xmits must be > 0
1862 devdata
->max_outstanding_net_xmits
=
1863 max_t(unsigned long, 3, ((devdata
->num_rcv_bufs
/ 3) - 2));
1864 devdata
->upper_threshold_net_xmits
=
1865 max_t(unsigned long,
1866 2, (devdata
->max_outstanding_net_xmits
- 1));
1867 devdata
->lower_threshold_net_xmits
=
1868 max_t(unsigned long,
1869 1, (devdata
->max_outstanding_net_xmits
/ 2));
1871 skb_queue_head_init(&devdata
->xmitbufhead
);
1873 /* create a cmdrsp we can use to post and unpost rcv buffers */
1874 devdata
->cmdrsp_rcv
= kmalloc(SIZEOF_CMDRSP
, GFP_ATOMIC
);
1875 if (!devdata
->cmdrsp_rcv
) {
1877 goto cleanup_rcvbuf
;
1879 devdata
->xmit_cmdrsp
= kmalloc(SIZEOF_CMDRSP
, GFP_ATOMIC
);
1880 if (!devdata
->xmit_cmdrsp
) {
1882 goto cleanup_cmdrsp_rcv
;
1884 INIT_WORK(&devdata
->timeout_reset
, visornic_timeout_reset
);
1885 devdata
->server_down
= false;
1886 devdata
->server_change_state
= false;
1888 /*set the default mtu */
1889 channel_offset
= offsetof(struct visor_io_channel
, vnic
.mtu
);
1890 err
= visorbus_read_channel(dev
, channel_offset
, &netdev
->mtu
, 4);
1892 dev_err(&dev
->device
,
1893 "%s failed to get mtu from chan (%d)\n",
1895 goto cleanup_xmit_cmdrsp
;
1898 /* TODO: Setup Interrupt information */
1899 /* Let's start our threads to get responses */
1900 netif_napi_add(netdev
, &devdata
->napi
, visornic_poll
, NAPI_WEIGHT
);
1902 setup_timer(&devdata
->irq_poll_timer
, poll_for_irq
,
1903 (unsigned long)devdata
);
1904 /* Note: This time has to start running before the while
1905 * loop below because the napi routine is responsible for
1906 * setting enab_dis_acked
1908 mod_timer(&devdata
->irq_poll_timer
, msecs_to_jiffies(2));
1910 channel_offset
= offsetof(struct visor_io_channel
,
1911 channel_header
.features
);
1912 err
= visorbus_read_channel(dev
, channel_offset
, &features
, 8);
1914 dev_err(&dev
->device
,
1915 "%s failed to get features from chan (%d)\n",
1917 goto cleanup_napi_add
;
1920 features
|= VISOR_CHANNEL_IS_POLLING
;
1921 features
|= VISOR_DRIVER_ENHANCED_RCVBUF_CHECKING
;
1922 err
= visorbus_write_channel(dev
, channel_offset
, &features
, 8);
1924 dev_err(&dev
->device
,
1925 "%s failed to set features in chan (%d)\n",
1927 goto cleanup_napi_add
;
1930 /* Note: Interrupts have to be enable before the while
1931 * loop below because the napi routine is responsible for
1932 * setting enab_dis_acked
1934 visorbus_enable_channel_interrupts(dev
);
1936 err
= register_netdev(netdev
);
1938 dev_err(&dev
->device
,
1939 "%s register_netdev failed (%d)\n", __func__
, err
);
1940 goto cleanup_napi_add
;
1943 /* create debug/sysfs directories */
1944 devdata
->eth_debugfs_dir
= debugfs_create_dir(netdev
->name
,
1945 visornic_debugfs_dir
);
1946 if (!devdata
->eth_debugfs_dir
) {
1947 dev_err(&dev
->device
,
1948 "%s debugfs_create_dir %s failed\n",
1949 __func__
, netdev
->name
);
1951 goto cleanup_register_netdev
;
1954 dev_info(&dev
->device
, "%s success netdev=%s\n",
1955 __func__
, netdev
->name
);
1958 cleanup_register_netdev
:
1959 unregister_netdev(netdev
);
1962 del_timer_sync(&devdata
->irq_poll_timer
);
1963 netif_napi_del(&devdata
->napi
);
1965 cleanup_xmit_cmdrsp
:
1966 kfree(devdata
->xmit_cmdrsp
);
1969 kfree(devdata
->cmdrsp_rcv
);
1972 kfree(devdata
->rcvbuf
);
1975 free_netdev(netdev
);
1979 /* host_side_disappeared - IO Partition is gone
1980 * @devdata: Device object.
1982 * IO partition servicing this device is gone; do cleanup.
1984 static void host_side_disappeared(struct visornic_devdata
*devdata
)
1986 unsigned long flags
;
1988 spin_lock_irqsave(&devdata
->priv_lock
, flags
);
1989 /* indicate device destroyed */
1990 devdata
->dev
= NULL
;
1991 spin_unlock_irqrestore(&devdata
->priv_lock
, flags
);
1994 /* visornic_remove - called when visornic dev goes away
1995 * @dev: Visornic device that is being removed.
1997 * Called when DEVICE_DESTROY gets called to remove device.
1999 static void visornic_remove(struct visor_device
*dev
)
2001 struct visornic_devdata
*devdata
= dev_get_drvdata(&dev
->device
);
2002 struct net_device
*netdev
;
2003 unsigned long flags
;
2006 dev_err(&dev
->device
, "%s no devdata\n", __func__
);
2009 spin_lock_irqsave(&devdata
->priv_lock
, flags
);
2010 if (devdata
->going_away
) {
2011 spin_unlock_irqrestore(&devdata
->priv_lock
, flags
);
2012 dev_err(&dev
->device
, "%s already being removed\n", __func__
);
2015 devdata
->going_away
= true;
2016 spin_unlock_irqrestore(&devdata
->priv_lock
, flags
);
2017 netdev
= devdata
->netdev
;
2019 dev_err(&dev
->device
, "%s not net device\n", __func__
);
2023 /* going_away prevents new items being added to the workqueues */
2024 cancel_work_sync(&devdata
->timeout_reset
);
2026 debugfs_remove_recursive(devdata
->eth_debugfs_dir
);
2027 /* this will call visornic_close() */
2028 unregister_netdev(netdev
);
2030 del_timer_sync(&devdata
->irq_poll_timer
);
2031 netif_napi_del(&devdata
->napi
);
2033 dev_set_drvdata(&dev
->device
, NULL
);
2034 host_side_disappeared(devdata
);
2035 devdata_release(devdata
);
2036 free_netdev(netdev
);
2039 /* visornic_pause - called when IO Part disappears
2040 * @dev: Visornic device that is being serviced.
2041 * @complete_func: Call when finished.
2043 * Called when the IO Partition has gone down. Need to free up resources and
2044 * wait for IO partition to come back. Mark link as down and don't attempt any
2045 * DMA. When we have freed memory, call the complete_func so that Command knows
2046 * we are done. If we don't call complete_func, the IO Partition will never
2049 * Return: 0 on success.
2051 static int visornic_pause(struct visor_device
*dev
,
2052 visorbus_state_complete_func complete_func
)
2054 struct visornic_devdata
*devdata
= dev_get_drvdata(&dev
->device
);
2056 visornic_serverdown(devdata
, complete_func
);
2060 /* visornic_resume - called when IO Partition has recovered
2061 * @dev: Visornic device that is being serviced.
2062 * @compelte_func: Call when finished.
2064 * Called when the IO partition has recovered. Re-establish connection to the IO
2065 * Partition and set the link up. Okay to do DMA again.
2067 * Returns 0 for success, negative integer on error.
2069 static int visornic_resume(struct visor_device
*dev
,
2070 visorbus_state_complete_func complete_func
)
2072 struct visornic_devdata
*devdata
;
2073 struct net_device
*netdev
;
2074 unsigned long flags
;
2076 devdata
= dev_get_drvdata(&dev
->device
);
2078 dev_err(&dev
->device
, "%s no devdata\n", __func__
);
2082 netdev
= devdata
->netdev
;
2084 spin_lock_irqsave(&devdata
->priv_lock
, flags
);
2085 if (devdata
->server_change_state
) {
2086 spin_unlock_irqrestore(&devdata
->priv_lock
, flags
);
2087 dev_err(&dev
->device
, "%s server already changing state\n",
2091 if (!devdata
->server_down
) {
2092 spin_unlock_irqrestore(&devdata
->priv_lock
, flags
);
2093 dev_err(&dev
->device
, "%s server not down\n", __func__
);
2094 complete_func(dev
, 0);
2097 devdata
->server_change_state
= true;
2098 spin_unlock_irqrestore(&devdata
->priv_lock
, flags
);
2100 /* Must transition channel to ATTACHED state BEFORE
2101 * we can start using the device again.
2102 * TODO: State transitions
2104 mod_timer(&devdata
->irq_poll_timer
, msecs_to_jiffies(2));
2110 complete_func(dev
, 0);
2114 /* This is used to tell the visorbus driver which types of visor devices
2115 * we support, and what functions to call when a visor device that we support
2116 * is attached or removed.
2118 static struct visor_driver visornic_driver
= {
2120 .owner
= THIS_MODULE
,
2121 .channel_types
= visornic_channel_types
,
2122 .probe
= visornic_probe
,
2123 .remove
= visornic_remove
,
2124 .pause
= visornic_pause
,
2125 .resume
= visornic_resume
,
2126 .channel_interrupt
= NULL
,
2129 /* visornic_init - init function
2131 * Init function for the visornic driver. Do initial driver setup and wait
2134 * Return: 0 on success, negative integer on error.
2136 static int visornic_init(void)
2141 visornic_debugfs_dir
= debugfs_create_dir("visornic", NULL
);
2142 if (!visornic_debugfs_dir
)
2145 ret
= debugfs_create_file("info", 0400, visornic_debugfs_dir
, NULL
,
2146 &debugfs_info_fops
);
2148 goto cleanup_debugfs
;
2149 ret
= debugfs_create_file("enable_ints", 0200, visornic_debugfs_dir
,
2150 NULL
, &debugfs_enable_ints_fops
);
2152 goto cleanup_debugfs
;
2154 err
= visorbus_register_visor_driver(&visornic_driver
);
2156 goto cleanup_debugfs
;
2161 debugfs_remove_recursive(visornic_debugfs_dir
);
2165 /* visornic_cleanup - driver exit routine
2167 * Unregister driver from the bus and free up memory.
2169 static void visornic_cleanup(void)
2171 visorbus_unregister_visor_driver(&visornic_driver
);
2172 debugfs_remove_recursive(visornic_debugfs_dir
);
2175 module_init(visornic_init
);
2176 module_exit(visornic_cleanup
);
2178 MODULE_AUTHOR("Unisys");
2179 MODULE_LICENSE("GPL");
2180 MODULE_DESCRIPTION("s-Par NIC driver for virtual network devices");