2 * SGI UltraViolet TLB flush routines.
4 * (c) 2008-2014 Cliff Wickman <cpw@sgi.com>, SGI.
6 * This code is released under the GNU General Public License version 2 or
9 #include <linux/seq_file.h>
10 #include <linux/proc_fs.h>
11 #include <linux/debugfs.h>
12 #include <linux/kernel.h>
13 #include <linux/slab.h>
14 #include <linux/delay.h>
16 #include <asm/mmu_context.h>
17 #include <asm/uv/uv.h>
18 #include <asm/uv/uv_mmrs.h>
19 #include <asm/uv/uv_hub.h>
20 #include <asm/uv/uv_bau.h>
23 #include <asm/irq_vectors.h>
24 #include <asm/timer.h>
26 static struct bau_operations ops __ro_after_init
;
28 /* timeouts in nanoseconds (indexed by UVH_AGING_PRESCALE_SEL urgency7 30:28) */
29 static const int timeout_base_ns
[] = {
40 static int timeout_us
;
41 static bool nobau
= true;
42 static int nobau_perm
;
45 static int max_concurr
= MAX_BAU_CONCURRENT
;
46 static int max_concurr_const
= MAX_BAU_CONCURRENT
;
47 static int plugged_delay
= PLUGGED_DELAY
;
48 static int plugsb4reset
= PLUGSB4RESET
;
49 static int giveup_limit
= GIVEUP_LIMIT
;
50 static int timeoutsb4reset
= TIMEOUTSB4RESET
;
51 static int ipi_reset_limit
= IPI_RESET_LIMIT
;
52 static int complete_threshold
= COMPLETE_THRESHOLD
;
53 static int congested_respns_us
= CONGESTED_RESPONSE_US
;
54 static int congested_reps
= CONGESTED_REPS
;
55 static int disabled_period
= DISABLED_PERIOD
;
57 static struct tunables tunables
[] = {
58 {&max_concurr
, MAX_BAU_CONCURRENT
}, /* must be [0] */
59 {&plugged_delay
, PLUGGED_DELAY
},
60 {&plugsb4reset
, PLUGSB4RESET
},
61 {&timeoutsb4reset
, TIMEOUTSB4RESET
},
62 {&ipi_reset_limit
, IPI_RESET_LIMIT
},
63 {&complete_threshold
, COMPLETE_THRESHOLD
},
64 {&congested_respns_us
, CONGESTED_RESPONSE_US
},
65 {&congested_reps
, CONGESTED_REPS
},
66 {&disabled_period
, DISABLED_PERIOD
},
67 {&giveup_limit
, GIVEUP_LIMIT
}
70 static struct dentry
*tunables_dir
;
71 static struct dentry
*tunables_file
;
73 /* these correspond to the statistics printed by ptc_seq_show() */
74 static char *stat_description
[] = {
75 "sent: number of shootdown messages sent",
76 "stime: time spent sending messages",
77 "numuvhubs: number of hubs targeted with shootdown",
78 "numuvhubs16: number times 16 or more hubs targeted",
79 "numuvhubs8: number times 8 or more hubs targeted",
80 "numuvhubs4: number times 4 or more hubs targeted",
81 "numuvhubs2: number times 2 or more hubs targeted",
82 "numuvhubs1: number times 1 hub targeted",
83 "numcpus: number of cpus targeted with shootdown",
84 "dto: number of destination timeouts",
85 "retries: destination timeout retries sent",
86 "rok: : destination timeouts successfully retried",
87 "resetp: ipi-style resource resets for plugs",
88 "resett: ipi-style resource resets for timeouts",
89 "giveup: fall-backs to ipi-style shootdowns",
90 "sto: number of source timeouts",
91 "bz: number of stay-busy's",
92 "throt: number times spun in throttle",
93 "swack: image of UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE",
94 "recv: shootdown messages received",
95 "rtime: time spent processing messages",
96 "all: shootdown all-tlb messages",
97 "one: shootdown one-tlb messages",
98 "mult: interrupts that found multiple messages",
99 "none: interrupts that found no messages",
100 "retry: number of retry messages processed",
101 "canc: number messages canceled by retries",
102 "nocan: number retries that found nothing to cancel",
103 "reset: number of ipi-style reset requests processed",
104 "rcan: number messages canceled by reset requests",
105 "disable: number times use of the BAU was disabled",
106 "enable: number times use of the BAU was re-enabled"
109 static int __init
setup_bau(char *arg
)
116 result
= strtobool(arg
, &nobau
);
120 /* we need to flip the logic here, so that bau=y sets nobau to false */
124 pr_info("UV BAU Enabled\n");
126 pr_info("UV BAU Disabled\n");
130 early_param("bau", setup_bau
);
132 /* base pnode in this partition */
133 static int uv_base_pnode __read_mostly
;
135 static DEFINE_PER_CPU(struct ptc_stats
, ptcstats
);
136 static DEFINE_PER_CPU(struct bau_control
, bau_control
);
137 static DEFINE_PER_CPU(cpumask_var_t
, uv_flush_tlb_mask
);
143 struct bau_control
*bcp
;
146 pr_info("BAU not initialized; cannot be turned on\n");
150 for_each_present_cpu(cpu
) {
151 bcp
= &per_cpu(bau_control
, cpu
);
154 pr_info("BAU turned on\n");
162 struct bau_control
*bcp
;
165 for_each_present_cpu(cpu
) {
166 bcp
= &per_cpu(bau_control
, cpu
);
169 pr_info("BAU turned off\n");
174 * Determine the first node on a uvhub. 'Nodes' are used for kernel
177 static int __init
uvhub_to_first_node(int uvhub
)
181 for_each_online_node(node
) {
182 b
= uv_node_to_blade_id(node
);
190 * Determine the apicid of the first cpu on a uvhub.
192 static int __init
uvhub_to_first_apicid(int uvhub
)
196 for_each_present_cpu(cpu
)
197 if (uvhub
== uv_cpu_to_blade_id(cpu
))
198 return per_cpu(x86_cpu_to_apicid
, cpu
);
203 * Free a software acknowledge hardware resource by clearing its Pending
204 * bit. This will return a reply to the sender.
205 * If the message has timed out, a reply has already been sent by the
206 * hardware but the resource has not been released. In that case our
207 * clear of the Timeout bit (as well) will free the resource. No reply will
208 * be sent (the hardware will only do one reply per message).
210 static void reply_to_message(struct msg_desc
*mdp
, struct bau_control
*bcp
,
214 struct bau_pq_entry
*msg
;
217 if (!msg
->canceled
&& do_acknowledge
) {
218 dw
= (msg
->swack_vec
<< UV_SW_ACK_NPENDING
) | msg
->swack_vec
;
219 ops
.write_l_sw_ack(dw
);
226 * Process the receipt of a RETRY message
228 static void bau_process_retry_msg(struct msg_desc
*mdp
,
229 struct bau_control
*bcp
)
232 int cancel_count
= 0;
233 unsigned long msg_res
;
234 unsigned long mmr
= 0;
235 struct bau_pq_entry
*msg
= mdp
->msg
;
236 struct bau_pq_entry
*msg2
;
237 struct ptc_stats
*stat
= bcp
->statp
;
241 * cancel any message from msg+1 to the retry itself
243 for (msg2
= msg
+1, i
= 0; i
< DEST_Q_SIZE
; msg2
++, i
++) {
244 if (msg2
> mdp
->queue_last
)
245 msg2
= mdp
->queue_first
;
249 /* same conditions for cancellation as do_reset */
250 if ((msg2
->replied_to
== 0) && (msg2
->canceled
== 0) &&
251 (msg2
->swack_vec
) && ((msg2
->swack_vec
&
252 msg
->swack_vec
) == 0) &&
253 (msg2
->sending_cpu
== msg
->sending_cpu
) &&
254 (msg2
->msg_type
!= MSG_NOOP
)) {
255 mmr
= ops
.read_l_sw_ack();
256 msg_res
= msg2
->swack_vec
;
258 * This is a message retry; clear the resources held
259 * by the previous message only if they timed out.
260 * If it has not timed out we have an unexpected
261 * situation to report.
263 if (mmr
& (msg_res
<< UV_SW_ACK_NPENDING
)) {
266 * Is the resource timed out?
267 * Make everyone ignore the cancelled message.
272 mr
= (msg_res
<< UV_SW_ACK_NPENDING
) | msg_res
;
273 ops
.write_l_sw_ack(mr
);
278 stat
->d_nocanceled
++;
282 * Do all the things a cpu should do for a TLB shootdown message.
283 * Other cpu's may come here at the same time for this message.
285 static void bau_process_message(struct msg_desc
*mdp
, struct bau_control
*bcp
,
288 short socket_ack_count
= 0;
290 struct atomic_short
*asp
;
291 struct ptc_stats
*stat
= bcp
->statp
;
292 struct bau_pq_entry
*msg
= mdp
->msg
;
293 struct bau_control
*smaster
= bcp
->socket_master
;
296 * This must be a normal message, or retry of a normal message
298 if (msg
->address
== TLB_FLUSH_ALL
) {
302 __flush_tlb_single(msg
->address
);
308 * One cpu on each uvhub has the additional job on a RETRY
309 * of releasing the resource held by the message that is
310 * being retried. That message is identified by sending
313 if (msg
->msg_type
== MSG_RETRY
&& bcp
== bcp
->uvhub_master
)
314 bau_process_retry_msg(mdp
, bcp
);
317 * This is a swack message, so we have to reply to it.
318 * Count each responding cpu on the socket. This avoids
319 * pinging the count's cache line back and forth between
322 sp
= &smaster
->socket_acknowledge_count
[mdp
->msg_slot
];
323 asp
= (struct atomic_short
*)sp
;
324 socket_ack_count
= atom_asr(1, asp
);
325 if (socket_ack_count
== bcp
->cpus_in_socket
) {
328 * Both sockets dump their completed count total into
329 * the message's count.
332 asp
= (struct atomic_short
*)&msg
->acknowledge_count
;
333 msg_ack_count
= atom_asr(socket_ack_count
, asp
);
335 if (msg_ack_count
== bcp
->cpus_in_uvhub
) {
337 * All cpus in uvhub saw it; reply
338 * (unless we are in the UV2 workaround)
340 reply_to_message(mdp
, bcp
, do_acknowledge
);
348 * Determine the first cpu on a pnode.
350 static int pnode_to_first_cpu(int pnode
, struct bau_control
*smaster
)
353 struct hub_and_pnode
*hpp
;
355 for_each_present_cpu(cpu
) {
356 hpp
= &smaster
->thp
[cpu
];
357 if (pnode
== hpp
->pnode
)
364 * Last resort when we get a large number of destination timeouts is
365 * to clear resources held by a given cpu.
366 * Do this with IPI so that all messages in the BAU message queue
367 * can be identified by their nonzero swack_vec field.
369 * This is entered for a single cpu on the uvhub.
370 * The sender want's this uvhub to free a specific message's
373 static void do_reset(void *ptr
)
376 struct bau_control
*bcp
= &per_cpu(bau_control
, smp_processor_id());
377 struct reset_args
*rap
= (struct reset_args
*)ptr
;
378 struct bau_pq_entry
*msg
;
379 struct ptc_stats
*stat
= bcp
->statp
;
383 * We're looking for the given sender, and
384 * will free its swack resource.
385 * If all cpu's finally responded after the timeout, its
386 * message 'replied_to' was set.
388 for (msg
= bcp
->queue_first
, i
= 0; i
< DEST_Q_SIZE
; msg
++, i
++) {
389 unsigned long msg_res
;
390 /* do_reset: same conditions for cancellation as
391 bau_process_retry_msg() */
392 if ((msg
->replied_to
== 0) &&
393 (msg
->canceled
== 0) &&
394 (msg
->sending_cpu
== rap
->sender
) &&
396 (msg
->msg_type
!= MSG_NOOP
)) {
400 * make everyone else ignore this message
404 * only reset the resource if it is still pending
406 mmr
= ops
.read_l_sw_ack();
407 msg_res
= msg
->swack_vec
;
408 mr
= (msg_res
<< UV_SW_ACK_NPENDING
) | msg_res
;
411 ops
.write_l_sw_ack(mr
);
419 * Use IPI to get all target uvhubs to release resources held by
420 * a given sending cpu number.
422 static void reset_with_ipi(struct pnmask
*distribution
, struct bau_control
*bcp
)
427 int sender
= bcp
->cpu
;
428 cpumask_t
*mask
= bcp
->uvhub_master
->cpumask
;
429 struct bau_control
*smaster
= bcp
->socket_master
;
430 struct reset_args reset_args
;
432 reset_args
.sender
= sender
;
434 /* find a single cpu for each uvhub in this distribution mask */
435 maskbits
= sizeof(struct pnmask
) * BITSPERBYTE
;
436 /* each bit is a pnode relative to the partition base pnode */
437 for (pnode
= 0; pnode
< maskbits
; pnode
++) {
439 if (!bau_uvhub_isset(pnode
, distribution
))
441 apnode
= pnode
+ bcp
->partition_base_pnode
;
442 cpu
= pnode_to_first_cpu(apnode
, smaster
);
443 cpumask_set_cpu(cpu
, mask
);
446 /* IPI all cpus; preemption is already disabled */
447 smp_call_function_many(mask
, do_reset
, (void *)&reset_args
, 1);
452 * Not to be confused with cycles_2_ns() from tsc.c; this gives a relative
453 * number, not an absolute. It converts a duration in cycles to a duration in
456 static inline unsigned long long cycles_2_ns(unsigned long long cyc
)
458 struct cyc2ns_data data
;
459 unsigned long long ns
;
461 cyc2ns_read_begin(&data
);
462 ns
= mul_u64_u32_shr(cyc
, data
.cyc2ns_mul
, data
.cyc2ns_shift
);
469 * The reverse of the above; converts a duration in ns to a duration in cycles.
471 static inline unsigned long long ns_2_cycles(unsigned long long ns
)
473 struct cyc2ns_data data
;
474 unsigned long long cyc
;
476 cyc2ns_read_begin(&data
);
477 cyc
= (ns
<< data
.cyc2ns_shift
) / data
.cyc2ns_mul
;
483 static inline unsigned long cycles_2_us(unsigned long long cyc
)
485 return cycles_2_ns(cyc
) / NSEC_PER_USEC
;
488 static inline cycles_t
sec_2_cycles(unsigned long sec
)
490 return ns_2_cycles(sec
* NSEC_PER_SEC
);
493 static inline unsigned long long usec_2_cycles(unsigned long usec
)
495 return ns_2_cycles(usec
* NSEC_PER_USEC
);
499 * wait for all cpus on this hub to finish their sends and go quiet
500 * leaves uvhub_quiesce set so that no new broadcasts are started by
501 * bau_flush_send_and_wait()
503 static inline void quiesce_local_uvhub(struct bau_control
*hmaster
)
505 atom_asr(1, (struct atomic_short
*)&hmaster
->uvhub_quiesce
);
509 * mark this quiet-requestor as done
511 static inline void end_uvhub_quiesce(struct bau_control
*hmaster
)
513 atom_asr(-1, (struct atomic_short
*)&hmaster
->uvhub_quiesce
);
516 static unsigned long uv1_read_status(unsigned long mmr_offset
, int right_shift
)
518 unsigned long descriptor_status
;
520 descriptor_status
= uv_read_local_mmr(mmr_offset
);
521 descriptor_status
>>= right_shift
;
522 descriptor_status
&= UV_ACT_STATUS_MASK
;
523 return descriptor_status
;
527 * Wait for completion of a broadcast software ack message
528 * return COMPLETE, RETRY(PLUGGED or TIMEOUT) or GIVEUP
530 static int uv1_wait_completion(struct bau_desc
*bau_desc
,
531 struct bau_control
*bcp
, long try)
533 unsigned long descriptor_status
;
535 u64 mmr_offset
= bcp
->status_mmr
;
536 int right_shift
= bcp
->status_index
;
537 struct ptc_stats
*stat
= bcp
->statp
;
539 descriptor_status
= uv1_read_status(mmr_offset
, right_shift
);
540 /* spin on the status MMR, waiting for it to go idle */
541 while ((descriptor_status
!= DS_IDLE
)) {
543 * Our software ack messages may be blocked because
544 * there are no swack resources available. As long
545 * as none of them has timed out hardware will NACK
546 * our message and its state will stay IDLE.
548 if (descriptor_status
== DS_SOURCE_TIMEOUT
) {
551 } else if (descriptor_status
== DS_DESTINATION_TIMEOUT
) {
556 * Our retries may be blocked by all destination
557 * swack resources being consumed, and a timeout
558 * pending. In that case hardware returns the
559 * ERROR that looks like a destination timeout.
561 if (cycles_2_us(ttm
- bcp
->send_message
) < timeout_us
) {
562 bcp
->conseccompletes
= 0;
563 return FLUSH_RETRY_PLUGGED
;
566 bcp
->conseccompletes
= 0;
567 return FLUSH_RETRY_TIMEOUT
;
570 * descriptor_status is still BUSY
574 descriptor_status
= uv1_read_status(mmr_offset
, right_shift
);
576 bcp
->conseccompletes
++;
577 return FLUSH_COMPLETE
;
581 * UV2 could have an extra bit of status in the ACTIVATION_STATUS_2 register.
582 * But not currently used.
584 static unsigned long uv2_3_read_status(unsigned long offset
, int rshft
, int desc
)
586 return ((read_lmmr(offset
) >> rshft
) & UV_ACT_STATUS_MASK
) << 1;
590 * Entered when a bau descriptor has gone into a permanent busy wait because
592 * Workaround the bug.
594 static int handle_uv2_busy(struct bau_control
*bcp
)
596 struct ptc_stats
*stat
= bcp
->statp
;
603 static int uv2_3_wait_completion(struct bau_desc
*bau_desc
,
604 struct bau_control
*bcp
, long try)
606 unsigned long descriptor_stat
;
608 u64 mmr_offset
= bcp
->status_mmr
;
609 int right_shift
= bcp
->status_index
;
610 int desc
= bcp
->uvhub_cpu
;
612 struct ptc_stats
*stat
= bcp
->statp
;
614 descriptor_stat
= uv2_3_read_status(mmr_offset
, right_shift
, desc
);
616 /* spin on the status MMR, waiting for it to go idle */
617 while (descriptor_stat
!= UV2H_DESC_IDLE
) {
618 if ((descriptor_stat
== UV2H_DESC_SOURCE_TIMEOUT
)) {
620 * A h/w bug on the destination side may
621 * have prevented the message being marked
622 * pending, thus it doesn't get replied to
623 * and gets continually nacked until it times
624 * out with a SOURCE_TIMEOUT.
628 } else if (descriptor_stat
== UV2H_DESC_DEST_TIMEOUT
) {
632 * Our retries may be blocked by all destination
633 * swack resources being consumed, and a timeout
634 * pending. In that case hardware returns the
635 * ERROR that looks like a destination timeout.
636 * Without using the extended status we have to
637 * deduce from the short time that this was a
640 if (cycles_2_us(ttm
- bcp
->send_message
) < timeout_us
) {
641 bcp
->conseccompletes
= 0;
643 /* FLUSH_RETRY_PLUGGED causes hang on boot */
647 bcp
->conseccompletes
= 0;
648 /* FLUSH_RETRY_TIMEOUT causes hang on boot */
652 if (busy_reps
> 1000000) {
653 /* not to hammer on the clock */
656 if ((ttm
- bcp
->send_message
) > bcp
->timeout_interval
)
657 return handle_uv2_busy(bcp
);
660 * descriptor_stat is still BUSY
664 descriptor_stat
= uv2_3_read_status(mmr_offset
, right_shift
, desc
);
666 bcp
->conseccompletes
++;
667 return FLUSH_COMPLETE
;
671 * Returns the status of current BAU message for cpu desc as a bit field
674 static u64
read_status(u64 status_mmr
, int index
, int desc
)
678 stat
= ((read_lmmr(status_mmr
) >> index
) & UV_ACT_STATUS_MASK
) << 1;
679 stat
|= (read_lmmr(UVH_LB_BAU_SB_ACTIVATION_STATUS_2
) >> desc
) & 0x1;
684 static int uv4_wait_completion(struct bau_desc
*bau_desc
,
685 struct bau_control
*bcp
, long try)
687 struct ptc_stats
*stat
= bcp
->statp
;
689 u64 mmr
= bcp
->status_mmr
;
690 int index
= bcp
->status_index
;
691 int desc
= bcp
->uvhub_cpu
;
693 descriptor_stat
= read_status(mmr
, index
, desc
);
695 /* spin on the status MMR, waiting for it to go idle */
696 while (descriptor_stat
!= UV2H_DESC_IDLE
) {
697 switch (descriptor_stat
) {
698 case UV2H_DESC_SOURCE_TIMEOUT
:
702 case UV2H_DESC_DEST_TIMEOUT
:
704 bcp
->conseccompletes
= 0;
705 return FLUSH_RETRY_TIMEOUT
;
707 case UV2H_DESC_DEST_STRONG_NACK
:
709 bcp
->conseccompletes
= 0;
710 return FLUSH_RETRY_PLUGGED
;
712 case UV2H_DESC_DEST_PUT_ERR
:
713 bcp
->conseccompletes
= 0;
717 /* descriptor_stat is still BUSY */
720 descriptor_stat
= read_status(mmr
, index
, desc
);
722 bcp
->conseccompletes
++;
723 return FLUSH_COMPLETE
;
727 * Our retries are blocked by all destination sw ack resources being
728 * in use, and a timeout is pending. In that case hardware immediately
729 * returns the ERROR that looks like a destination timeout.
731 static void destination_plugged(struct bau_desc
*bau_desc
,
732 struct bau_control
*bcp
,
733 struct bau_control
*hmaster
, struct ptc_stats
*stat
)
735 udelay(bcp
->plugged_delay
);
736 bcp
->plugged_tries
++;
738 if (bcp
->plugged_tries
>= bcp
->plugsb4reset
) {
739 bcp
->plugged_tries
= 0;
741 quiesce_local_uvhub(hmaster
);
743 spin_lock(&hmaster
->queue_lock
);
744 reset_with_ipi(&bau_desc
->distribution
, bcp
);
745 spin_unlock(&hmaster
->queue_lock
);
747 end_uvhub_quiesce(hmaster
);
750 stat
->s_resets_plug
++;
754 static void destination_timeout(struct bau_desc
*bau_desc
,
755 struct bau_control
*bcp
, struct bau_control
*hmaster
,
756 struct ptc_stats
*stat
)
758 hmaster
->max_concurr
= 1;
759 bcp
->timeout_tries
++;
760 if (bcp
->timeout_tries
>= bcp
->timeoutsb4reset
) {
761 bcp
->timeout_tries
= 0;
763 quiesce_local_uvhub(hmaster
);
765 spin_lock(&hmaster
->queue_lock
);
766 reset_with_ipi(&bau_desc
->distribution
, bcp
);
767 spin_unlock(&hmaster
->queue_lock
);
769 end_uvhub_quiesce(hmaster
);
772 stat
->s_resets_timeout
++;
777 * Stop all cpus on a uvhub from using the BAU for a period of time.
778 * This is reversed by check_enable.
780 static void disable_for_period(struct bau_control
*bcp
, struct ptc_stats
*stat
)
783 struct bau_control
*tbcp
;
784 struct bau_control
*hmaster
;
787 hmaster
= bcp
->uvhub_master
;
788 spin_lock(&hmaster
->disable_lock
);
789 if (!bcp
->baudisabled
) {
790 stat
->s_bau_disabled
++;
792 for_each_present_cpu(tcpu
) {
793 tbcp
= &per_cpu(bau_control
, tcpu
);
794 if (tbcp
->uvhub_master
== hmaster
) {
795 tbcp
->baudisabled
= 1;
796 tbcp
->set_bau_on_time
=
797 tm1
+ bcp
->disabled_period
;
801 spin_unlock(&hmaster
->disable_lock
);
804 static void count_max_concurr(int stat
, struct bau_control
*bcp
,
805 struct bau_control
*hmaster
)
807 bcp
->plugged_tries
= 0;
808 bcp
->timeout_tries
= 0;
809 if (stat
!= FLUSH_COMPLETE
)
811 if (bcp
->conseccompletes
<= bcp
->complete_threshold
)
813 if (hmaster
->max_concurr
>= hmaster
->max_concurr_const
)
815 hmaster
->max_concurr
++;
818 static void record_send_stats(cycles_t time1
, cycles_t time2
,
819 struct bau_control
*bcp
, struct ptc_stats
*stat
,
820 int completion_status
, int try)
825 elapsed
= time2
- time1
;
826 stat
->s_time
+= elapsed
;
828 if ((completion_status
== FLUSH_COMPLETE
) && (try == 1)) {
829 bcp
->period_requests
++;
830 bcp
->period_time
+= elapsed
;
831 if ((elapsed
> usec_2_cycles(bcp
->cong_response_us
)) &&
832 (bcp
->period_requests
> bcp
->cong_reps
) &&
833 ((bcp
->period_time
/ bcp
->period_requests
) >
834 usec_2_cycles(bcp
->cong_response_us
))) {
836 disable_for_period(bcp
, stat
);
842 if (completion_status
== FLUSH_COMPLETE
&& try > 1)
844 else if (completion_status
== FLUSH_GIVEUP
) {
846 if (get_cycles() > bcp
->period_end
)
847 bcp
->period_giveups
= 0;
848 bcp
->period_giveups
++;
849 if (bcp
->period_giveups
== 1)
850 bcp
->period_end
= get_cycles() + bcp
->disabled_period
;
851 if (bcp
->period_giveups
> bcp
->giveup_limit
) {
852 disable_for_period(bcp
, stat
);
853 stat
->s_giveuplimit
++;
859 * Because of a uv1 hardware bug only a limited number of concurrent
860 * requests can be made.
862 static void uv1_throttle(struct bau_control
*hmaster
, struct ptc_stats
*stat
)
864 spinlock_t
*lock
= &hmaster
->uvhub_lock
;
867 v
= &hmaster
->active_descriptor_count
;
868 if (!atomic_inc_unless_ge(lock
, v
, hmaster
->max_concurr
)) {
872 } while (!atomic_inc_unless_ge(lock
, v
, hmaster
->max_concurr
));
877 * Handle the completion status of a message send.
879 static void handle_cmplt(int completion_status
, struct bau_desc
*bau_desc
,
880 struct bau_control
*bcp
, struct bau_control
*hmaster
,
881 struct ptc_stats
*stat
)
883 if (completion_status
== FLUSH_RETRY_PLUGGED
)
884 destination_plugged(bau_desc
, bcp
, hmaster
, stat
);
885 else if (completion_status
== FLUSH_RETRY_TIMEOUT
)
886 destination_timeout(bau_desc
, bcp
, hmaster
, stat
);
890 * Send a broadcast and wait for it to complete.
892 * The flush_mask contains the cpus the broadcast is to be sent to including
893 * cpus that are on the local uvhub.
895 * Returns 0 if all flushing represented in the mask was done.
896 * Returns 1 if it gives up entirely and the original cpu mask is to be
897 * returned to the kernel.
899 static int uv_flush_send_and_wait(struct cpumask
*flush_mask
,
900 struct bau_control
*bcp
,
901 struct bau_desc
*bau_desc
)
904 int completion_stat
= 0;
910 struct ptc_stats
*stat
= bcp
->statp
;
911 struct bau_control
*hmaster
= bcp
->uvhub_master
;
912 struct uv1_bau_msg_header
*uv1_hdr
= NULL
;
913 struct uv2_3_bau_msg_header
*uv2_3_hdr
= NULL
;
915 if (bcp
->uvhub_version
== UV_BAU_V1
) {
917 uv1_throttle(hmaster
, stat
);
920 while (hmaster
->uvhub_quiesce
)
923 time1
= get_cycles();
925 uv1_hdr
= &bau_desc
->header
.uv1_hdr
;
928 uv2_3_hdr
= &bau_desc
->header
.uv2_3_hdr
;
933 uv1_hdr
->msg_type
= MSG_REGULAR
;
935 uv2_3_hdr
->msg_type
= MSG_REGULAR
;
936 seq_number
= bcp
->message_number
++;
939 uv1_hdr
->msg_type
= MSG_RETRY
;
941 uv2_3_hdr
->msg_type
= MSG_RETRY
;
942 stat
->s_retry_messages
++;
946 uv1_hdr
->sequence
= seq_number
;
948 uv2_3_hdr
->sequence
= seq_number
;
949 index
= (1UL << AS_PUSH_SHIFT
) | bcp
->uvhub_cpu
;
950 bcp
->send_message
= get_cycles();
952 write_mmr_activation(index
);
955 completion_stat
= ops
.wait_completion(bau_desc
, bcp
, try);
957 handle_cmplt(completion_stat
, bau_desc
, bcp
, hmaster
, stat
);
959 if (bcp
->ipi_attempts
>= bcp
->ipi_reset_limit
) {
960 bcp
->ipi_attempts
= 0;
961 stat
->s_overipilimit
++;
962 completion_stat
= FLUSH_GIVEUP
;
966 } while ((completion_stat
== FLUSH_RETRY_PLUGGED
) ||
967 (completion_stat
== FLUSH_RETRY_TIMEOUT
));
969 time2
= get_cycles();
971 count_max_concurr(completion_stat
, bcp
, hmaster
);
973 while (hmaster
->uvhub_quiesce
)
976 atomic_dec(&hmaster
->active_descriptor_count
);
978 record_send_stats(time1
, time2
, bcp
, stat
, completion_stat
, try);
980 if (completion_stat
== FLUSH_GIVEUP
)
981 /* FLUSH_GIVEUP will fall back to using IPI's for tlb flush */
987 * The BAU is disabled for this uvhub. When the disabled time period has
988 * expired re-enable it.
989 * Return 0 if it is re-enabled for all cpus on this uvhub.
991 static int check_enable(struct bau_control
*bcp
, struct ptc_stats
*stat
)
994 struct bau_control
*tbcp
;
995 struct bau_control
*hmaster
;
997 hmaster
= bcp
->uvhub_master
;
998 spin_lock(&hmaster
->disable_lock
);
999 if (bcp
->baudisabled
&& (get_cycles() >= bcp
->set_bau_on_time
)) {
1000 stat
->s_bau_reenabled
++;
1001 for_each_present_cpu(tcpu
) {
1002 tbcp
= &per_cpu(bau_control
, tcpu
);
1003 if (tbcp
->uvhub_master
== hmaster
) {
1004 tbcp
->baudisabled
= 0;
1005 tbcp
->period_requests
= 0;
1006 tbcp
->period_time
= 0;
1007 tbcp
->period_giveups
= 0;
1010 spin_unlock(&hmaster
->disable_lock
);
1013 spin_unlock(&hmaster
->disable_lock
);
1017 static void record_send_statistics(struct ptc_stats
*stat
, int locals
, int hubs
,
1018 int remotes
, struct bau_desc
*bau_desc
)
1020 stat
->s_requestor
++;
1021 stat
->s_ntargcpu
+= remotes
+ locals
;
1022 stat
->s_ntargremotes
+= remotes
;
1023 stat
->s_ntarglocals
+= locals
;
1025 /* uvhub statistics */
1026 hubs
= bau_uvhub_weight(&bau_desc
->distribution
);
1028 stat
->s_ntarglocaluvhub
++;
1029 stat
->s_ntargremoteuvhub
+= (hubs
- 1);
1031 stat
->s_ntargremoteuvhub
+= hubs
;
1033 stat
->s_ntarguvhub
+= hubs
;
1036 stat
->s_ntarguvhub16
++;
1038 stat
->s_ntarguvhub8
++;
1040 stat
->s_ntarguvhub4
++;
1042 stat
->s_ntarguvhub2
++;
1044 stat
->s_ntarguvhub1
++;
1048 * Translate a cpu mask to the uvhub distribution mask in the BAU
1049 * activation descriptor.
1051 static int set_distrib_bits(struct cpumask
*flush_mask
, struct bau_control
*bcp
,
1052 struct bau_desc
*bau_desc
, int *localsp
, int *remotesp
)
1057 struct hub_and_pnode
*hpp
;
1059 for_each_cpu(cpu
, flush_mask
) {
1061 * The distribution vector is a bit map of pnodes, relative
1062 * to the partition base pnode (and the partition base nasid
1064 * Translate cpu to pnode and hub using a local memory array.
1066 hpp
= &bcp
->socket_master
->thp
[cpu
];
1067 pnode
= hpp
->pnode
- bcp
->partition_base_pnode
;
1068 bau_uvhub_set(pnode
, &bau_desc
->distribution
);
1070 if (hpp
->uvhub
== bcp
->uvhub
)
1081 * globally purge translation cache of a virtual address or all TLB's
1082 * @cpumask: mask of all cpu's in which the address is to be removed
1083 * @mm: mm_struct containing virtual address range
1084 * @start: start virtual address to be removed from TLB
1085 * @end: end virtual address to be remove from TLB
1086 * @cpu: the current cpu
1088 * This is the entry point for initiating any UV global TLB shootdown.
1090 * Purges the translation caches of all specified processors of the given
1091 * virtual address, or purges all TLB's on specified processors.
1093 * The caller has derived the cpumask from the mm_struct. This function
1094 * is called only if there are bits set in the mask. (e.g. flush_tlb_page())
1096 * The cpumask is converted into a uvhubmask of the uvhubs containing
1099 * Note that this function should be called with preemption disabled.
1101 * Returns NULL if all remote flushing was done.
1102 * Returns pointer to cpumask if some remote flushing remains to be
1103 * done. The returned pointer is valid till preemption is re-enabled.
1105 const struct cpumask
*uv_flush_tlb_others(const struct cpumask
*cpumask
,
1106 const struct flush_tlb_info
*info
)
1108 unsigned int cpu
= smp_processor_id();
1109 int locals
= 0, remotes
= 0, hubs
= 0;
1110 struct bau_desc
*bau_desc
;
1111 struct cpumask
*flush_mask
;
1112 struct ptc_stats
*stat
;
1113 struct bau_control
*bcp
;
1114 unsigned long descriptor_status
, status
, address
;
1116 bcp
= &per_cpu(bau_control
, cpu
);
1126 read_lmmr(UVH_LB_BAU_SB_ACTIVATION_STATUS_0
);
1127 status
= ((descriptor_status
>> (bcp
->uvhub_cpu
*
1128 UV_ACT_STATUS_SIZE
)) & UV_ACT_STATUS_MASK
) << 1;
1129 if (status
== UV2H_DESC_BUSY
)
1134 /* bau was disabled due to slow response */
1135 if (bcp
->baudisabled
) {
1136 if (check_enable(bcp
, stat
)) {
1137 stat
->s_ipifordisabled
++;
1143 * Each sending cpu has a per-cpu mask which it fills from the caller's
1144 * cpu mask. All cpus are converted to uvhubs and copied to the
1145 * activation descriptor.
1147 flush_mask
= (struct cpumask
*)per_cpu(uv_flush_tlb_mask
, cpu
);
1148 /* don't actually do a shootdown of the local cpu */
1149 cpumask_andnot(flush_mask
, cpumask
, cpumask_of(cpu
));
1151 if (cpumask_test_cpu(cpu
, cpumask
))
1152 stat
->s_ntargself
++;
1154 bau_desc
= bcp
->descriptor_base
;
1155 bau_desc
+= (ITEMS_PER_DESC
* bcp
->uvhub_cpu
);
1156 bau_uvhubs_clear(&bau_desc
->distribution
, UV_DISTRIBUTION_SIZE
);
1157 if (set_distrib_bits(flush_mask
, bcp
, bau_desc
, &locals
, &remotes
))
1160 record_send_statistics(stat
, locals
, hubs
, remotes
, bau_desc
);
1162 if (!info
->end
|| (info
->end
- info
->start
) <= PAGE_SIZE
)
1163 address
= info
->start
;
1165 address
= TLB_FLUSH_ALL
;
1167 switch (bcp
->uvhub_version
) {
1171 bau_desc
->payload
.uv1_2_3
.address
= address
;
1172 bau_desc
->payload
.uv1_2_3
.sending_cpu
= cpu
;
1175 bau_desc
->payload
.uv4
.address
= address
;
1176 bau_desc
->payload
.uv4
.sending_cpu
= cpu
;
1177 bau_desc
->payload
.uv4
.qualifier
= BAU_DESC_QUALIFIER
;
1182 * uv_flush_send_and_wait returns 0 if all cpu's were messaged,
1183 * or 1 if it gave up and the original cpumask should be returned.
1185 if (!uv_flush_send_and_wait(flush_mask
, bcp
, bau_desc
))
1192 * Search the message queue for any 'other' unprocessed message with the
1193 * same software acknowledge resource bit vector as the 'msg' message.
1195 static struct bau_pq_entry
*find_another_by_swack(struct bau_pq_entry
*msg
,
1196 struct bau_control
*bcp
)
1198 struct bau_pq_entry
*msg_next
= msg
+ 1;
1199 unsigned char swack_vec
= msg
->swack_vec
;
1201 if (msg_next
> bcp
->queue_last
)
1202 msg_next
= bcp
->queue_first
;
1203 while (msg_next
!= msg
) {
1204 if ((msg_next
->canceled
== 0) && (msg_next
->replied_to
== 0) &&
1205 (msg_next
->swack_vec
== swack_vec
))
1208 if (msg_next
> bcp
->queue_last
)
1209 msg_next
= bcp
->queue_first
;
1215 * UV2 needs to work around a bug in which an arriving message has not
1216 * set a bit in the UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE register.
1217 * Such a message must be ignored.
1219 static void process_uv2_message(struct msg_desc
*mdp
, struct bau_control
*bcp
)
1221 unsigned long mmr_image
;
1222 unsigned char swack_vec
;
1223 struct bau_pq_entry
*msg
= mdp
->msg
;
1224 struct bau_pq_entry
*other_msg
;
1226 mmr_image
= ops
.read_l_sw_ack();
1227 swack_vec
= msg
->swack_vec
;
1229 if ((swack_vec
& mmr_image
) == 0) {
1231 * This message was assigned a swack resource, but no
1232 * reserved acknowlegment is pending.
1233 * The bug has prevented this message from setting the MMR.
1236 * Some message has set the MMR 'pending' bit; it might have
1237 * been another message. Look for that message.
1239 other_msg
= find_another_by_swack(msg
, bcp
);
1242 * There is another. Process this one but do not
1245 bau_process_message(mdp
, bcp
, 0);
1247 * Let the natural processing of that other message
1248 * acknowledge it. Don't get the processing of sw_ack's
1256 * Either the MMR shows this one pending a reply or there is no
1257 * other message using this sw_ack, so it is safe to acknowledge it.
1259 bau_process_message(mdp
, bcp
, 1);
1265 * The BAU message interrupt comes here. (registered by set_intr_gate)
1268 * We received a broadcast assist message.
1270 * Interrupts are disabled; this interrupt could represent
1271 * the receipt of several messages.
1273 * All cores/threads on this hub get this interrupt.
1274 * The last one to see it does the software ack.
1275 * (the resource will not be freed until noninterruptable cpus see this
1276 * interrupt; hardware may timeout the s/w ack and reply ERROR)
1278 void uv_bau_message_interrupt(struct pt_regs
*regs
)
1281 cycles_t time_start
;
1282 struct bau_pq_entry
*msg
;
1283 struct bau_control
*bcp
;
1284 struct ptc_stats
*stat
;
1285 struct msg_desc msgdesc
;
1288 time_start
= get_cycles();
1290 bcp
= &per_cpu(bau_control
, smp_processor_id());
1293 msgdesc
.queue_first
= bcp
->queue_first
;
1294 msgdesc
.queue_last
= bcp
->queue_last
;
1296 msg
= bcp
->bau_msg_head
;
1297 while (msg
->swack_vec
) {
1300 msgdesc
.msg_slot
= msg
- msgdesc
.queue_first
;
1302 if (bcp
->uvhub_version
== UV_BAU_V2
)
1303 process_uv2_message(&msgdesc
, bcp
);
1305 /* no error workaround for uv1 or uv3 */
1306 bau_process_message(&msgdesc
, bcp
, 1);
1309 if (msg
> msgdesc
.queue_last
)
1310 msg
= msgdesc
.queue_first
;
1311 bcp
->bau_msg_head
= msg
;
1313 stat
->d_time
+= (get_cycles() - time_start
);
1321 * Each target uvhub (i.e. a uvhub that has cpu's) needs to have
1322 * shootdown message timeouts enabled. The timeout does not cause
1323 * an interrupt, but causes an error message to be returned to
1326 static void __init
enable_timeouts(void)
1331 unsigned long mmr_image
;
1333 nuvhubs
= uv_num_possible_blades();
1335 for (uvhub
= 0; uvhub
< nuvhubs
; uvhub
++) {
1336 if (!uv_blade_nr_possible_cpus(uvhub
))
1339 pnode
= uv_blade_to_pnode(uvhub
);
1340 mmr_image
= read_mmr_misc_control(pnode
);
1342 * Set the timeout period and then lock it in, in three
1343 * steps; captures and locks in the period.
1345 * To program the period, the SOFT_ACK_MODE must be off.
1347 mmr_image
&= ~(1L << SOFTACK_MSHIFT
);
1348 write_mmr_misc_control(pnode
, mmr_image
);
1350 * Set the 4-bit period.
1352 mmr_image
&= ~((unsigned long)0xf << SOFTACK_PSHIFT
);
1353 mmr_image
|= (SOFTACK_TIMEOUT_PERIOD
<< SOFTACK_PSHIFT
);
1354 write_mmr_misc_control(pnode
, mmr_image
);
1357 * Subsequent reversals of the timebase bit (3) cause an
1358 * immediate timeout of one or all INTD resources as
1359 * indicated in bits 2:0 (7 causes all of them to timeout).
1361 mmr_image
|= (1L << SOFTACK_MSHIFT
);
1363 /* do not touch the legacy mode bit */
1364 /* hw bug workaround; do not use extended status */
1365 mmr_image
&= ~(1L << UV2_EXT_SHFT
);
1366 } else if (is_uv3_hub()) {
1367 mmr_image
&= ~(1L << PREFETCH_HINT_SHFT
);
1368 mmr_image
|= (1L << SB_STATUS_SHFT
);
1370 write_mmr_misc_control(pnode
, mmr_image
);
1374 static void *ptc_seq_start(struct seq_file
*file
, loff_t
*offset
)
1376 if (*offset
< num_possible_cpus())
1381 static void *ptc_seq_next(struct seq_file
*file
, void *data
, loff_t
*offset
)
1384 if (*offset
< num_possible_cpus())
1389 static void ptc_seq_stop(struct seq_file
*file
, void *data
)
1394 * Display the statistics thru /proc/sgi_uv/ptc_statistics
1395 * 'data' points to the cpu number
1396 * Note: see the descriptions in stat_description[].
1398 static int ptc_seq_show(struct seq_file
*file
, void *data
)
1400 struct ptc_stats
*stat
;
1401 struct bau_control
*bcp
;
1404 cpu
= *(loff_t
*)data
;
1407 "# cpu bauoff sent stime self locals remotes ncpus localhub ");
1408 seq_puts(file
, "remotehub numuvhubs numuvhubs16 numuvhubs8 ");
1410 "numuvhubs4 numuvhubs2 numuvhubs1 dto snacks retries ");
1412 "rok resetp resett giveup sto bz throt disable ");
1414 "enable wars warshw warwaits enters ipidis plugged ");
1416 "ipiover glim cong swack recv rtime all one mult ");
1417 seq_puts(file
, "none retry canc nocan reset rcan\n");
1419 if (cpu
< num_possible_cpus() && cpu_online(cpu
)) {
1420 bcp
= &per_cpu(bau_control
, cpu
);
1422 seq_printf(file
, "cpu %d bau disabled\n", cpu
);
1426 /* source side statistics */
1428 "cpu %d %d %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ",
1429 cpu
, bcp
->nobau
, stat
->s_requestor
,
1430 cycles_2_us(stat
->s_time
),
1431 stat
->s_ntargself
, stat
->s_ntarglocals
,
1432 stat
->s_ntargremotes
, stat
->s_ntargcpu
,
1433 stat
->s_ntarglocaluvhub
, stat
->s_ntargremoteuvhub
,
1434 stat
->s_ntarguvhub
, stat
->s_ntarguvhub16
);
1435 seq_printf(file
, "%ld %ld %ld %ld %ld %ld ",
1436 stat
->s_ntarguvhub8
, stat
->s_ntarguvhub4
,
1437 stat
->s_ntarguvhub2
, stat
->s_ntarguvhub1
,
1438 stat
->s_dtimeout
, stat
->s_strongnacks
);
1439 seq_printf(file
, "%ld %ld %ld %ld %ld %ld %ld %ld ",
1440 stat
->s_retry_messages
, stat
->s_retriesok
,
1441 stat
->s_resets_plug
, stat
->s_resets_timeout
,
1442 stat
->s_giveup
, stat
->s_stimeout
,
1443 stat
->s_busy
, stat
->s_throttles
);
1444 seq_printf(file
, "%ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ",
1445 stat
->s_bau_disabled
, stat
->s_bau_reenabled
,
1446 stat
->s_uv2_wars
, stat
->s_uv2_wars_hw
,
1447 stat
->s_uv2_war_waits
, stat
->s_enters
,
1448 stat
->s_ipifordisabled
, stat
->s_plugged
,
1449 stat
->s_overipilimit
, stat
->s_giveuplimit
,
1452 /* destination side statistics */
1454 "%lx %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld\n",
1455 ops
.read_g_sw_ack(uv_cpu_to_pnode(cpu
)),
1456 stat
->d_requestee
, cycles_2_us(stat
->d_time
),
1457 stat
->d_alltlb
, stat
->d_onetlb
, stat
->d_multmsg
,
1458 stat
->d_nomsg
, stat
->d_retries
, stat
->d_canceled
,
1459 stat
->d_nocanceled
, stat
->d_resets
,
1466 * Display the tunables thru debugfs
1468 static ssize_t
tunables_read(struct file
*file
, char __user
*userbuf
,
1469 size_t count
, loff_t
*ppos
)
1474 buf
= kasprintf(GFP_KERNEL
, "%s %s %s\n%d %d %d %d %d %d %d %d %d %d\n",
1475 "max_concur plugged_delay plugsb4reset timeoutsb4reset",
1476 "ipi_reset_limit complete_threshold congested_response_us",
1477 "congested_reps disabled_period giveup_limit",
1478 max_concurr
, plugged_delay
, plugsb4reset
,
1479 timeoutsb4reset
, ipi_reset_limit
, complete_threshold
,
1480 congested_respns_us
, congested_reps
, disabled_period
,
1486 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, strlen(buf
));
1492 * handle a write to /proc/sgi_uv/ptc_statistics
1493 * -1: reset the statistics
1494 * 0: display meaning of the statistics
1496 static ssize_t
ptc_proc_write(struct file
*file
, const char __user
*user
,
1497 size_t count
, loff_t
*data
)
1504 struct ptc_stats
*stat
;
1506 if (count
== 0 || count
> sizeof(optstr
))
1508 if (copy_from_user(optstr
, user
, count
))
1510 optstr
[count
- 1] = '\0';
1512 if (!strcmp(optstr
, "on")) {
1515 } else if (!strcmp(optstr
, "off")) {
1520 if (kstrtol(optstr
, 10, &input_arg
) < 0) {
1521 pr_debug("%s is invalid\n", optstr
);
1525 if (input_arg
== 0) {
1526 elements
= ARRAY_SIZE(stat_description
);
1527 pr_debug("# cpu: cpu number\n");
1528 pr_debug("Sender statistics:\n");
1529 for (i
= 0; i
< elements
; i
++)
1530 pr_debug("%s\n", stat_description
[i
]);
1531 } else if (input_arg
== -1) {
1532 for_each_present_cpu(cpu
) {
1533 stat
= &per_cpu(ptcstats
, cpu
);
1534 memset(stat
, 0, sizeof(struct ptc_stats
));
1541 static int local_atoi(const char *name
)
1548 val
= 10*val
+(*name
-'0');
1557 * Parse the values written to /sys/kernel/debug/sgi_uv/bau_tunables.
1558 * Zero values reset them to defaults.
1560 static int parse_tunables_write(struct bau_control
*bcp
, char *instr
,
1567 int e
= ARRAY_SIZE(tunables
);
1569 p
= instr
+ strspn(instr
, WHITESPACE
);
1571 for (; *p
; p
= q
+ strspn(q
, WHITESPACE
)) {
1572 q
= p
+ strcspn(p
, WHITESPACE
);
1578 pr_info("bau tunable error: should be %d values\n", e
);
1582 p
= instr
+ strspn(instr
, WHITESPACE
);
1584 for (cnt
= 0; *p
; p
= q
+ strspn(q
, WHITESPACE
), cnt
++) {
1585 q
= p
+ strcspn(p
, WHITESPACE
);
1586 val
= local_atoi(p
);
1590 max_concurr
= MAX_BAU_CONCURRENT
;
1591 max_concurr_const
= MAX_BAU_CONCURRENT
;
1594 if (val
< 1 || val
> bcp
->cpus_in_uvhub
) {
1596 "Error: BAU max concurrent %d is invalid\n",
1601 max_concurr_const
= val
;
1605 *tunables
[cnt
].tunp
= tunables
[cnt
].deflt
;
1607 *tunables
[cnt
].tunp
= val
;
1617 * Handle a write to debugfs. (/sys/kernel/debug/sgi_uv/bau_tunables)
1619 static ssize_t
tunables_write(struct file
*file
, const char __user
*user
,
1620 size_t count
, loff_t
*data
)
1625 struct bau_control
*bcp
;
1627 if (count
== 0 || count
> sizeof(instr
)-1)
1629 if (copy_from_user(instr
, user
, count
))
1632 instr
[count
] = '\0';
1635 bcp
= &per_cpu(bau_control
, cpu
);
1636 ret
= parse_tunables_write(bcp
, instr
, count
);
1641 for_each_present_cpu(cpu
) {
1642 bcp
= &per_cpu(bau_control
, cpu
);
1643 bcp
->max_concurr
= max_concurr
;
1644 bcp
->max_concurr_const
= max_concurr
;
1645 bcp
->plugged_delay
= plugged_delay
;
1646 bcp
->plugsb4reset
= plugsb4reset
;
1647 bcp
->timeoutsb4reset
= timeoutsb4reset
;
1648 bcp
->ipi_reset_limit
= ipi_reset_limit
;
1649 bcp
->complete_threshold
= complete_threshold
;
1650 bcp
->cong_response_us
= congested_respns_us
;
1651 bcp
->cong_reps
= congested_reps
;
1652 bcp
->disabled_period
= sec_2_cycles(disabled_period
);
1653 bcp
->giveup_limit
= giveup_limit
;
1658 static const struct seq_operations uv_ptc_seq_ops
= {
1659 .start
= ptc_seq_start
,
1660 .next
= ptc_seq_next
,
1661 .stop
= ptc_seq_stop
,
1662 .show
= ptc_seq_show
1665 static int ptc_proc_open(struct inode
*inode
, struct file
*file
)
1667 return seq_open(file
, &uv_ptc_seq_ops
);
1670 static int tunables_open(struct inode
*inode
, struct file
*file
)
1675 static const struct file_operations proc_uv_ptc_operations
= {
1676 .open
= ptc_proc_open
,
1678 .write
= ptc_proc_write
,
1679 .llseek
= seq_lseek
,
1680 .release
= seq_release
,
1683 static const struct file_operations tunables_fops
= {
1684 .open
= tunables_open
,
1685 .read
= tunables_read
,
1686 .write
= tunables_write
,
1687 .llseek
= default_llseek
,
1690 static int __init
uv_ptc_init(void)
1692 struct proc_dir_entry
*proc_uv_ptc
;
1694 if (!is_uv_system())
1697 proc_uv_ptc
= proc_create(UV_PTC_BASENAME
, 0444, NULL
,
1698 &proc_uv_ptc_operations
);
1700 pr_err("unable to create %s proc entry\n",
1705 tunables_dir
= debugfs_create_dir(UV_BAU_TUNABLES_DIR
, NULL
);
1706 if (!tunables_dir
) {
1707 pr_err("unable to create debugfs directory %s\n",
1708 UV_BAU_TUNABLES_DIR
);
1711 tunables_file
= debugfs_create_file(UV_BAU_TUNABLES_FILE
, 0600,
1712 tunables_dir
, NULL
, &tunables_fops
);
1713 if (!tunables_file
) {
1714 pr_err("unable to create debugfs file %s\n",
1715 UV_BAU_TUNABLES_FILE
);
1722 * Initialize the sending side's sending buffers.
1724 static void activation_descriptor_init(int node
, int pnode
, int base_pnode
)
1733 struct bau_desc
*bau_desc
;
1734 struct bau_desc
*bd2
;
1735 struct uv1_bau_msg_header
*uv1_hdr
;
1736 struct uv2_3_bau_msg_header
*uv2_3_hdr
;
1737 struct bau_control
*bcp
;
1740 * each bau_desc is 64 bytes; there are 8 (ITEMS_PER_DESC)
1741 * per cpu; and one per cpu on the uvhub (ADP_SZ)
1743 dsize
= sizeof(struct bau_desc
) * ADP_SZ
* ITEMS_PER_DESC
;
1744 bau_desc
= kmalloc_node(dsize
, GFP_KERNEL
, node
);
1747 gpa
= uv_gpa(bau_desc
);
1748 n
= uv_gpa_to_gnode(gpa
);
1749 m
= ops
.bau_gpa_to_offset(gpa
);
1753 /* the 14-bit pnode */
1754 write_mmr_descriptor_base(pnode
, (n
<< UV_DESC_PSHIFT
| m
));
1756 * Initializing all 8 (ITEMS_PER_DESC) descriptors for each
1757 * cpu even though we only use the first one; one descriptor can
1758 * describe a broadcast to 256 uv hubs.
1760 for (i
= 0, bd2
= bau_desc
; i
< (ADP_SZ
* ITEMS_PER_DESC
); i
++, bd2
++) {
1761 memset(bd2
, 0, sizeof(struct bau_desc
));
1763 uv1_hdr
= &bd2
->header
.uv1_hdr
;
1764 uv1_hdr
->swack_flag
= 1;
1766 * The base_dest_nasid set in the message header
1767 * is the nasid of the first uvhub in the partition.
1768 * The bit map will indicate destination pnode numbers
1769 * relative to that base. They may not be consecutive
1770 * if nasid striding is being used.
1772 uv1_hdr
->base_dest_nasid
=
1773 UV_PNODE_TO_NASID(base_pnode
);
1774 uv1_hdr
->dest_subnodeid
= UV_LB_SUBNODEID
;
1775 uv1_hdr
->command
= UV_NET_ENDPOINT_INTD
;
1776 uv1_hdr
->int_both
= 1;
1778 * all others need to be set to zero:
1779 * fairness chaining multilevel count replied_to
1783 * BIOS uses legacy mode, but uv2 and uv3 hardware always
1784 * uses native mode for selective broadcasts.
1786 uv2_3_hdr
= &bd2
->header
.uv2_3_hdr
;
1787 uv2_3_hdr
->swack_flag
= 1;
1788 uv2_3_hdr
->base_dest_nasid
=
1789 UV_PNODE_TO_NASID(base_pnode
);
1790 uv2_3_hdr
->dest_subnodeid
= UV_LB_SUBNODEID
;
1791 uv2_3_hdr
->command
= UV_NET_ENDPOINT_INTD
;
1794 for_each_present_cpu(cpu
) {
1795 if (pnode
!= uv_blade_to_pnode(uv_cpu_to_blade_id(cpu
)))
1797 bcp
= &per_cpu(bau_control
, cpu
);
1798 bcp
->descriptor_base
= bau_desc
;
1803 * initialize the destination side's receiving buffers
1804 * entered for each uvhub in the partition
1805 * - node is first node (kernel memory notion) on the uvhub
1806 * - pnode is the uvhub's physical identifier
1808 static void pq_init(int node
, int pnode
)
1814 unsigned long gnode
, first
, last
, tail
;
1815 struct bau_pq_entry
*pqp
;
1816 struct bau_control
*bcp
;
1818 plsize
= (DEST_Q_SIZE
+ 1) * sizeof(struct bau_pq_entry
);
1819 vp
= kmalloc_node(plsize
, GFP_KERNEL
, node
);
1820 pqp
= (struct bau_pq_entry
*)vp
;
1823 cp
= (char *)pqp
+ 31;
1824 pqp
= (struct bau_pq_entry
*)(((unsigned long)cp
>> 5) << 5);
1826 for_each_present_cpu(cpu
) {
1827 if (pnode
!= uv_cpu_to_pnode(cpu
))
1829 /* for every cpu on this pnode: */
1830 bcp
= &per_cpu(bau_control
, cpu
);
1831 bcp
->queue_first
= pqp
;
1832 bcp
->bau_msg_head
= pqp
;
1833 bcp
->queue_last
= pqp
+ (DEST_Q_SIZE
- 1);
1836 first
= ops
.bau_gpa_to_offset(uv_gpa(pqp
));
1837 last
= ops
.bau_gpa_to_offset(uv_gpa(pqp
+ (DEST_Q_SIZE
- 1)));
1840 * Pre UV4, the gnode is required to locate the payload queue
1841 * and the payload queue tail must be maintained by the kernel.
1843 bcp
= &per_cpu(bau_control
, smp_processor_id());
1844 if (bcp
->uvhub_version
<= UV_BAU_V3
) {
1846 gnode
= uv_gpa_to_gnode(uv_gpa(pqp
));
1847 first
= (gnode
<< UV_PAYLOADQ_GNODE_SHIFT
) | tail
;
1848 write_mmr_payload_tail(pnode
, tail
);
1851 ops
.write_payload_first(pnode
, first
);
1852 ops
.write_payload_last(pnode
, last
);
1854 /* in effect, all msg_type's are set to MSG_NOOP */
1855 memset(pqp
, 0, sizeof(struct bau_pq_entry
) * DEST_Q_SIZE
);
1859 * Initialization of each UV hub's structures
1861 static void __init
init_uvhub(int uvhub
, int vector
, int base_pnode
)
1865 unsigned long apicid
;
1867 node
= uvhub_to_first_node(uvhub
);
1868 pnode
= uv_blade_to_pnode(uvhub
);
1870 activation_descriptor_init(node
, pnode
, base_pnode
);
1872 pq_init(node
, pnode
);
1874 * The below initialization can't be in firmware because the
1875 * messaging IRQ will be determined by the OS.
1877 apicid
= uvhub_to_first_apicid(uvhub
) | uv_apicid_hibits
;
1878 write_mmr_data_config(pnode
, ((apicid
<< 32) | vector
));
1882 * We will set BAU_MISC_CONTROL with a timeout period.
1883 * But the BIOS has set UVH_AGING_PRESCALE_SEL and UVH_TRANSACTION_TIMEOUT.
1884 * So the destination timeout period has to be calculated from them.
1886 static int calculate_destination_timeout(void)
1888 unsigned long mmr_image
;
1894 unsigned long ts_ns
;
1897 mult1
= SOFTACK_TIMEOUT_PERIOD
& BAU_MISC_CONTROL_MULT_MASK
;
1898 mmr_image
= uv_read_local_mmr(UVH_AGING_PRESCALE_SEL
);
1899 index
= (mmr_image
>> BAU_URGENCY_7_SHIFT
) & BAU_URGENCY_7_MASK
;
1900 mmr_image
= uv_read_local_mmr(UVH_TRANSACTION_TIMEOUT
);
1901 mult2
= (mmr_image
>> BAU_TRANS_SHIFT
) & BAU_TRANS_MASK
;
1902 ts_ns
= timeout_base_ns
[index
];
1903 ts_ns
*= (mult1
* mult2
);
1906 /* same destination timeout for uv2 and uv3 */
1907 /* 4 bits 0/1 for 10/80us base, 3 bits of multiplier */
1908 mmr_image
= uv_read_local_mmr(UVH_LB_BAU_MISC_CONTROL
);
1909 mmr_image
= (mmr_image
& UV_SA_MASK
) >> UV_SA_SHFT
;
1910 if (mmr_image
& (1L << UV2_ACK_UNITS_SHFT
))
1914 mult1
= mmr_image
& UV2_ACK_MASK
;
1920 static void __init
init_per_cpu_tunables(void)
1923 struct bau_control
*bcp
;
1925 for_each_present_cpu(cpu
) {
1926 bcp
= &per_cpu(bau_control
, cpu
);
1927 bcp
->baudisabled
= 0;
1930 bcp
->statp
= &per_cpu(ptcstats
, cpu
);
1931 /* time interval to catch a hardware stay-busy bug */
1932 bcp
->timeout_interval
= usec_2_cycles(2*timeout_us
);
1933 bcp
->max_concurr
= max_concurr
;
1934 bcp
->max_concurr_const
= max_concurr
;
1935 bcp
->plugged_delay
= plugged_delay
;
1936 bcp
->plugsb4reset
= plugsb4reset
;
1937 bcp
->timeoutsb4reset
= timeoutsb4reset
;
1938 bcp
->ipi_reset_limit
= ipi_reset_limit
;
1939 bcp
->complete_threshold
= complete_threshold
;
1940 bcp
->cong_response_us
= congested_respns_us
;
1941 bcp
->cong_reps
= congested_reps
;
1942 bcp
->disabled_period
= sec_2_cycles(disabled_period
);
1943 bcp
->giveup_limit
= giveup_limit
;
1944 spin_lock_init(&bcp
->queue_lock
);
1945 spin_lock_init(&bcp
->uvhub_lock
);
1946 spin_lock_init(&bcp
->disable_lock
);
1951 * Scan all cpus to collect blade and socket summaries.
1953 static int __init
get_cpu_topology(int base_pnode
,
1954 struct uvhub_desc
*uvhub_descs
,
1955 unsigned char *uvhub_mask
)
1961 struct bau_control
*bcp
;
1962 struct uvhub_desc
*bdp
;
1963 struct socket_desc
*sdp
;
1965 for_each_present_cpu(cpu
) {
1966 bcp
= &per_cpu(bau_control
, cpu
);
1968 memset(bcp
, 0, sizeof(struct bau_control
));
1970 pnode
= uv_cpu_hub_info(cpu
)->pnode
;
1971 if ((pnode
- base_pnode
) >= UV_DISTRIBUTION_SIZE
) {
1973 "cpu %d pnode %d-%d beyond %d; BAU disabled\n",
1974 cpu
, pnode
, base_pnode
, UV_DISTRIBUTION_SIZE
);
1978 bcp
->osnode
= cpu_to_node(cpu
);
1979 bcp
->partition_base_pnode
= base_pnode
;
1981 uvhub
= uv_cpu_hub_info(cpu
)->numa_blade_id
;
1982 *(uvhub_mask
+ (uvhub
/8)) |= (1 << (uvhub
%8));
1983 bdp
= &uvhub_descs
[uvhub
];
1989 /* kludge: 'assuming' one node per socket, and assuming that
1990 disabling a socket just leaves a gap in node numbers */
1991 socket
= bcp
->osnode
& 1;
1992 bdp
->socket_mask
|= (1 << socket
);
1993 sdp
= &bdp
->socket
[socket
];
1994 sdp
->cpu_number
[sdp
->num_cpus
] = cpu
;
1996 if (sdp
->num_cpus
> MAX_CPUS_PER_SOCKET
) {
1997 pr_emerg("%d cpus per socket invalid\n",
2006 * Each socket is to get a local array of pnodes/hubs.
2008 static void make_per_cpu_thp(struct bau_control
*smaster
)
2011 size_t hpsz
= sizeof(struct hub_and_pnode
) * num_possible_cpus();
2013 smaster
->thp
= kmalloc_node(hpsz
, GFP_KERNEL
, smaster
->osnode
);
2014 memset(smaster
->thp
, 0, hpsz
);
2015 for_each_present_cpu(cpu
) {
2016 smaster
->thp
[cpu
].pnode
= uv_cpu_hub_info(cpu
)->pnode
;
2017 smaster
->thp
[cpu
].uvhub
= uv_cpu_hub_info(cpu
)->numa_blade_id
;
2022 * Each uvhub is to get a local cpumask.
2024 static void make_per_hub_cpumask(struct bau_control
*hmaster
)
2026 int sz
= sizeof(cpumask_t
);
2028 hmaster
->cpumask
= kzalloc_node(sz
, GFP_KERNEL
, hmaster
->osnode
);
2032 * Initialize all the per_cpu information for the cpu's on a given socket,
2033 * given what has been gathered into the socket_desc struct.
2034 * And reports the chosen hub and socket masters back to the caller.
2036 static int scan_sock(struct socket_desc
*sdp
, struct uvhub_desc
*bdp
,
2037 struct bau_control
**smasterp
,
2038 struct bau_control
**hmasterp
)
2040 int i
, cpu
, uvhub_cpu
;
2041 struct bau_control
*bcp
;
2043 for (i
= 0; i
< sdp
->num_cpus
; i
++) {
2044 cpu
= sdp
->cpu_number
[i
];
2045 bcp
= &per_cpu(bau_control
, cpu
);
2052 bcp
->cpus_in_uvhub
= bdp
->num_cpus
;
2053 bcp
->cpus_in_socket
= sdp
->num_cpus
;
2054 bcp
->socket_master
= *smasterp
;
2055 bcp
->uvhub
= bdp
->uvhub
;
2057 bcp
->uvhub_version
= UV_BAU_V1
;
2058 else if (is_uv2_hub())
2059 bcp
->uvhub_version
= UV_BAU_V2
;
2060 else if (is_uv3_hub())
2061 bcp
->uvhub_version
= UV_BAU_V3
;
2062 else if (is_uv4_hub())
2063 bcp
->uvhub_version
= UV_BAU_V4
;
2065 pr_emerg("uvhub version not 1, 2, 3, or 4\n");
2068 bcp
->uvhub_master
= *hmasterp
;
2069 uvhub_cpu
= uv_cpu_blade_processor_id(cpu
);
2070 bcp
->uvhub_cpu
= uvhub_cpu
;
2073 * The ERROR and BUSY status registers are located pairwise over
2074 * the STATUS_0 and STATUS_1 mmrs; each an array[32] of 2 bits.
2076 if (uvhub_cpu
< UV_CPUS_PER_AS
) {
2077 bcp
->status_mmr
= UVH_LB_BAU_SB_ACTIVATION_STATUS_0
;
2078 bcp
->status_index
= uvhub_cpu
* UV_ACT_STATUS_SIZE
;
2080 bcp
->status_mmr
= UVH_LB_BAU_SB_ACTIVATION_STATUS_1
;
2081 bcp
->status_index
= (uvhub_cpu
- UV_CPUS_PER_AS
)
2082 * UV_ACT_STATUS_SIZE
;
2085 if (bcp
->uvhub_cpu
>= MAX_CPUS_PER_UVHUB
) {
2086 pr_emerg("%d cpus per uvhub invalid\n",
2095 * Summarize the blade and socket topology into the per_cpu structures.
2097 static int __init
summarize_uvhub_sockets(int nuvhubs
,
2098 struct uvhub_desc
*uvhub_descs
,
2099 unsigned char *uvhub_mask
)
2103 unsigned short socket_mask
;
2105 for (uvhub
= 0; uvhub
< nuvhubs
; uvhub
++) {
2106 struct uvhub_desc
*bdp
;
2107 struct bau_control
*smaster
= NULL
;
2108 struct bau_control
*hmaster
= NULL
;
2110 if (!(*(uvhub_mask
+ (uvhub
/8)) & (1 << (uvhub
%8))))
2113 bdp
= &uvhub_descs
[uvhub
];
2114 socket_mask
= bdp
->socket_mask
;
2116 while (socket_mask
) {
2117 struct socket_desc
*sdp
;
2118 if ((socket_mask
& 1)) {
2119 sdp
= &bdp
->socket
[socket
];
2120 if (scan_sock(sdp
, bdp
, &smaster
, &hmaster
))
2122 make_per_cpu_thp(smaster
);
2125 socket_mask
= (socket_mask
>> 1);
2127 make_per_hub_cpumask(hmaster
);
2133 * initialize the bau_control structure for each cpu
2135 static int __init
init_per_cpu(int nuvhubs
, int base_part_pnode
)
2137 unsigned char *uvhub_mask
;
2139 struct uvhub_desc
*uvhub_descs
;
2141 if (is_uv3_hub() || is_uv2_hub() || is_uv1_hub())
2142 timeout_us
= calculate_destination_timeout();
2144 vp
= kmalloc(nuvhubs
* sizeof(struct uvhub_desc
), GFP_KERNEL
);
2145 uvhub_descs
= (struct uvhub_desc
*)vp
;
2146 memset(uvhub_descs
, 0, nuvhubs
* sizeof(struct uvhub_desc
));
2147 uvhub_mask
= kzalloc((nuvhubs
+7)/8, GFP_KERNEL
);
2149 if (get_cpu_topology(base_part_pnode
, uvhub_descs
, uvhub_mask
))
2152 if (summarize_uvhub_sockets(nuvhubs
, uvhub_descs
, uvhub_mask
))
2157 init_per_cpu_tunables();
2166 static const struct bau_operations uv1_bau_ops __initconst
= {
2167 .bau_gpa_to_offset
= uv_gpa_to_offset
,
2168 .read_l_sw_ack
= read_mmr_sw_ack
,
2169 .read_g_sw_ack
= read_gmmr_sw_ack
,
2170 .write_l_sw_ack
= write_mmr_sw_ack
,
2171 .write_g_sw_ack
= write_gmmr_sw_ack
,
2172 .write_payload_first
= write_mmr_payload_first
,
2173 .write_payload_last
= write_mmr_payload_last
,
2174 .wait_completion
= uv1_wait_completion
,
2177 static const struct bau_operations uv2_3_bau_ops __initconst
= {
2178 .bau_gpa_to_offset
= uv_gpa_to_offset
,
2179 .read_l_sw_ack
= read_mmr_sw_ack
,
2180 .read_g_sw_ack
= read_gmmr_sw_ack
,
2181 .write_l_sw_ack
= write_mmr_sw_ack
,
2182 .write_g_sw_ack
= write_gmmr_sw_ack
,
2183 .write_payload_first
= write_mmr_payload_first
,
2184 .write_payload_last
= write_mmr_payload_last
,
2185 .wait_completion
= uv2_3_wait_completion
,
2188 static const struct bau_operations uv4_bau_ops __initconst
= {
2189 .bau_gpa_to_offset
= uv_gpa_to_soc_phys_ram
,
2190 .read_l_sw_ack
= read_mmr_proc_sw_ack
,
2191 .read_g_sw_ack
= read_gmmr_proc_sw_ack
,
2192 .write_l_sw_ack
= write_mmr_proc_sw_ack
,
2193 .write_g_sw_ack
= write_gmmr_proc_sw_ack
,
2194 .write_payload_first
= write_mmr_proc_payload_first
,
2195 .write_payload_last
= write_mmr_proc_payload_last
,
2196 .wait_completion
= uv4_wait_completion
,
2200 * Initialization of BAU-related structures
2202 static int __init
uv_bau_init(void)
2210 cpumask_var_t
*mask
;
2212 if (!is_uv_system())
2217 else if (is_uv3_hub())
2218 ops
= uv2_3_bau_ops
;
2219 else if (is_uv2_hub())
2220 ops
= uv2_3_bau_ops
;
2221 else if (is_uv1_hub())
2224 nuvhubs
= uv_num_possible_blades();
2226 pr_crit("UV: BAU disabled - insufficient hub count\n");
2227 goto err_bau_disable
;
2230 for_each_possible_cpu(cur_cpu
) {
2231 mask
= &per_cpu(uv_flush_tlb_mask
, cur_cpu
);
2232 zalloc_cpumask_var_node(mask
, GFP_KERNEL
, cpu_to_node(cur_cpu
));
2235 uv_base_pnode
= 0x7fffffff;
2236 for (uvhub
= 0; uvhub
< nuvhubs
; uvhub
++) {
2237 cpus
= uv_blade_nr_possible_cpus(uvhub
);
2238 if (cpus
&& (uv_blade_to_pnode(uvhub
) < uv_base_pnode
))
2239 uv_base_pnode
= uv_blade_to_pnode(uvhub
);
2242 /* software timeouts are not supported on UV4 */
2243 if (is_uv3_hub() || is_uv2_hub() || is_uv1_hub())
2246 if (init_per_cpu(nuvhubs
, uv_base_pnode
)) {
2247 pr_crit("UV: BAU disabled - per CPU init failed\n");
2248 goto err_bau_disable
;
2251 vector
= UV_BAU_MESSAGE
;
2252 for_each_possible_blade(uvhub
) {
2253 if (uv_blade_nr_possible_cpus(uvhub
))
2254 init_uvhub(uvhub
, vector
, uv_base_pnode
);
2257 alloc_intr_gate(vector
, uv_bau_message_intr1
);
2259 for_each_possible_blade(uvhub
) {
2260 if (uv_blade_nr_possible_cpus(uvhub
)) {
2263 pnode
= uv_blade_to_pnode(uvhub
);
2266 write_gmmr_activation(pnode
, val
);
2267 mmr
= 1; /* should be 1 to broadcast to both sockets */
2269 write_mmr_data_broadcast(pnode
, mmr
);
2277 for_each_possible_cpu(cur_cpu
)
2278 free_cpumask_var(per_cpu(uv_flush_tlb_mask
, cur_cpu
));
2285 core_initcall(uv_bau_init
);
2286 fs_initcall(uv_ptc_init
);