2 * SGI UltraViolet TLB flush routines.
4 * (c) 2008-2010 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/kernel.h>
12 #include <linux/slab.h>
14 #include <asm/mmu_context.h>
15 #include <asm/uv/uv.h>
16 #include <asm/uv/uv_mmrs.h>
17 #include <asm/uv/uv_hub.h>
18 #include <asm/uv/uv_bau.h>
22 #include <asm/irq_vectors.h>
23 #include <asm/timer.h>
26 struct bau_payload_queue_entry *msg;
29 struct bau_payload_queue_entry *va_queue_first;
30 struct bau_payload_queue_entry *va_queue_last;
33 /* timeouts in nanoseconds (indexed by UVH_AGING_PRESCALE_SEL urgency7 30:28) */
34 static int timeout_base_ns[] = {
44 static int timeout_us;
46 #define UV_INTD_SOFT_ACK_TIMEOUT_PERIOD 0x000000000bUL
48 static int uv_bau_max_concurrent __read_mostly;
51 static int __init setup_nobau(char *arg)
56 early_param("nobau", setup_nobau);
58 /* base pnode in this partition */
59 static int uv_partition_base_pnode __read_mostly;
60 /* position of pnode (which is nasid>>1): */
61 static int uv_nshift __read_mostly;
62 static unsigned long uv_mmask __read_mostly;
64 static DEFINE_PER_CPU(struct ptc_stats, ptcstats);
65 static DEFINE_PER_CPU(struct bau_control, bau_control);
66 static DEFINE_PER_CPU(cpumask_var_t, uv_flush_tlb_mask);
73 * Determine the first node on a uvhub. 'Nodes' are used for kernel
76 static int __init uvhub_to_first_node(int uvhub)
80 for_each_online_node(node) {
81 b = uv_node_to_blade_id(node);
89 * Determine the apicid of the first cpu on a uvhub.
91 static int __init uvhub_to_first_apicid(int uvhub)
95 for_each_present_cpu(cpu)
96 if (uvhub == uv_cpu_to_blade_id(cpu))
97 return per_cpu(x86_cpu_to_apicid, cpu);
102 * Free a software acknowledge hardware resource by clearing its Pending
103 * bit. This will return a reply to the sender.
104 * If the message has timed out, a reply has already been sent by the
105 * hardware but the resource has not been released. In that case our
106 * clear of the Timeout bit (as well) will free the resource. No reply will
107 * be sent (the hardware will only do one reply per message).
109 static inline void uv_reply_to_message(struct msg_desc *mdp,
110 struct bau_control *bcp)
113 struct bau_payload_queue_entry *msg;
116 if (!msg->canceled) {
117 dw = (msg->sw_ack_vector << UV_SW_ACK_NPENDING) |
120 UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS, dw);
123 msg->sw_ack_vector = 0;
127 * Process the receipt of a RETRY message
129 static inline void uv_bau_process_retry_msg(struct msg_desc *mdp,
130 struct bau_control *bcp)
133 int cancel_count = 0;
135 unsigned long msg_res;
136 unsigned long mmr = 0;
137 struct bau_payload_queue_entry *msg;
138 struct bau_payload_queue_entry *msg2;
139 struct ptc_stats *stat;
142 stat = &per_cpu(ptcstats, bcp->cpu);
145 * cancel any message from msg+1 to the retry itself
147 for (msg2 = msg+1, i = 0; i < DEST_Q_SIZE; msg2++, i++) {
148 if (msg2 > mdp->va_queue_last)
149 msg2 = mdp->va_queue_first;
153 /* same conditions for cancellation as uv_do_reset */
154 if ((msg2->replied_to == 0) && (msg2->canceled == 0) &&
155 (msg2->sw_ack_vector) && ((msg2->sw_ack_vector &
156 msg->sw_ack_vector) == 0) &&
157 (msg2->sending_cpu == msg->sending_cpu) &&
158 (msg2->msg_type != MSG_NOOP)) {
159 slot2 = msg2 - mdp->va_queue_first;
160 mmr = uv_read_local_mmr
161 (UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE);
162 msg_res = ((msg2->sw_ack_vector << 8) |
163 msg2->sw_ack_vector);
165 * This is a message retry; clear the resources held
166 * by the previous message only if they timed out.
167 * If it has not timed out we have an unexpected
168 * situation to report.
170 if (mmr & (msg_res << 8)) {
172 * is the resource timed out?
173 * make everyone ignore the cancelled message.
179 UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS,
180 (msg_res << 8) | msg_res);
182 printk(KERN_INFO "note bau retry: no effect\n");
186 stat->d_nocanceled++;
190 * Do all the things a cpu should do for a TLB shootdown message.
191 * Other cpu's may come here at the same time for this message.
193 static void uv_bau_process_message(struct msg_desc *mdp,
194 struct bau_control *bcp)
197 short socket_ack_count = 0;
198 struct ptc_stats *stat;
199 struct bau_payload_queue_entry *msg;
200 struct bau_control *smaster = bcp->socket_master;
203 * This must be a normal message, or retry of a normal message
206 stat = &per_cpu(ptcstats, bcp->cpu);
207 if (msg->address == TLB_FLUSH_ALL) {
211 __flush_tlb_one(msg->address);
217 * One cpu on each uvhub has the additional job on a RETRY
218 * of releasing the resource held by the message that is
219 * being retried. That message is identified by sending
222 if (msg->msg_type == MSG_RETRY && bcp == bcp->uvhub_master)
223 uv_bau_process_retry_msg(mdp, bcp);
226 * This is a sw_ack message, so we have to reply to it.
227 * Count each responding cpu on the socket. This avoids
228 * pinging the count's cache line back and forth between
231 socket_ack_count = atomic_add_short_return(1, (struct atomic_short *)
232 &smaster->socket_acknowledge_count[mdp->msg_slot]);
233 if (socket_ack_count == bcp->cpus_in_socket) {
235 * Both sockets dump their completed count total into
236 * the message's count.
238 smaster->socket_acknowledge_count[mdp->msg_slot] = 0;
239 msg_ack_count = atomic_add_short_return(socket_ack_count,
240 (struct atomic_short *)&msg->acknowledge_count);
242 if (msg_ack_count == bcp->cpus_in_uvhub) {
244 * All cpus in uvhub saw it; reply
246 uv_reply_to_message(mdp, bcp);
254 * Determine the first cpu on a uvhub.
256 static int uvhub_to_first_cpu(int uvhub)
259 for_each_present_cpu(cpu)
260 if (uvhub == uv_cpu_to_blade_id(cpu))
266 * Last resort when we get a large number of destination timeouts is
267 * to clear resources held by a given cpu.
268 * Do this with IPI so that all messages in the BAU message queue
269 * can be identified by their nonzero sw_ack_vector field.
271 * This is entered for a single cpu on the uvhub.
272 * The sender want's this uvhub to free a specific message's
276 uv_do_reset(void *ptr)
282 unsigned long msg_res;
283 struct bau_control *bcp;
284 struct reset_args *rap;
285 struct bau_payload_queue_entry *msg;
286 struct ptc_stats *stat;
288 bcp = &per_cpu(bau_control, smp_processor_id());
289 rap = (struct reset_args *)ptr;
290 stat = &per_cpu(ptcstats, bcp->cpu);
294 * We're looking for the given sender, and
295 * will free its sw_ack resource.
296 * If all cpu's finally responded after the timeout, its
297 * message 'replied_to' was set.
299 for (msg = bcp->va_queue_first, i = 0; i < DEST_Q_SIZE; msg++, i++) {
300 /* uv_do_reset: same conditions for cancellation as
301 uv_bau_process_retry_msg() */
302 if ((msg->replied_to == 0) &&
303 (msg->canceled == 0) &&
304 (msg->sending_cpu == rap->sender) &&
305 (msg->sw_ack_vector) &&
306 (msg->msg_type != MSG_NOOP)) {
308 * make everyone else ignore this message
311 slot = msg - bcp->va_queue_first;
314 * only reset the resource if it is still pending
316 mmr = uv_read_local_mmr
317 (UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE);
318 msg_res = ((msg->sw_ack_vector << 8) |
323 UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS,
332 * Use IPI to get all target uvhubs to release resources held by
333 * a given sending cpu number.
335 static void uv_reset_with_ipi(struct bau_target_uvhubmask *distribution,
341 struct reset_args reset_args;
343 reset_args.sender = sender;
346 /* find a single cpu for each uvhub in this distribution mask */
348 uvhub < sizeof(struct bau_target_uvhubmask) * BITSPERBYTE;
350 if (!bau_uvhub_isset(uvhub, distribution))
352 /* find a cpu for this uvhub */
353 cpu = uvhub_to_first_cpu(uvhub);
356 /* IPI all cpus; Preemption is already disabled */
357 smp_call_function_many(&mask, uv_do_reset, (void *)&reset_args, 1);
361 static inline unsigned long
362 cycles_2_us(unsigned long long cyc)
364 unsigned long long ns;
366 ns = (cyc * per_cpu(cyc2ns, smp_processor_id()))
367 >> CYC2NS_SCALE_FACTOR;
373 * wait for all cpus on this hub to finish their sends and go quiet
374 * leaves uvhub_quiesce set so that no new broadcasts are started by
375 * bau_flush_send_and_wait()
378 quiesce_local_uvhub(struct bau_control *hmaster)
380 atomic_add_short_return(1, (struct atomic_short *)
381 &hmaster->uvhub_quiesce);
385 * mark this quiet-requestor as done
388 end_uvhub_quiesce(struct bau_control *hmaster)
390 atomic_add_short_return(-1, (struct atomic_short *)
391 &hmaster->uvhub_quiesce);
395 * Wait for completion of a broadcast software ack message
396 * return COMPLETE, RETRY(PLUGGED or TIMEOUT) or GIVEUP
398 static int uv_wait_completion(struct bau_desc *bau_desc,
399 unsigned long mmr_offset, int right_shift, int this_cpu,
400 struct bau_control *bcp, struct bau_control *smaster, long try)
403 unsigned long descriptor_status;
407 cycles_t timeout_time;
408 struct ptc_stats *stat = &per_cpu(ptcstats, this_cpu);
409 struct bau_control *hmaster;
411 hmaster = bcp->uvhub_master;
412 timeout_time = get_cycles() + bcp->timeout_interval;
414 /* spin on the status MMR, waiting for it to go idle */
415 while ((descriptor_status = (((unsigned long)
416 uv_read_local_mmr(mmr_offset) >>
417 right_shift) & UV_ACT_STATUS_MASK)) !=
420 * Our software ack messages may be blocked because there are
421 * no swack resources available. As long as none of them
422 * has timed out hardware will NACK our message and its
423 * state will stay IDLE.
425 if (descriptor_status == DESC_STATUS_SOURCE_TIMEOUT) {
428 } else if (descriptor_status ==
429 DESC_STATUS_DESTINATION_TIMEOUT) {
431 ttime = get_cycles();
434 * Our retries may be blocked by all destination
435 * swack resources being consumed, and a timeout
436 * pending. In that case hardware returns the
437 * ERROR that looks like a destination timeout.
439 if (cycles_2_us(ttime - bcp->send_message) <
441 bcp->conseccompletes = 0;
442 return FLUSH_RETRY_PLUGGED;
445 bcp->conseccompletes = 0;
446 return FLUSH_RETRY_TIMEOUT;
449 * descriptor_status is still BUSY
453 if (relaxes >= 10000) {
455 if (get_cycles() > timeout_time) {
456 quiesce_local_uvhub(hmaster);
458 /* single-thread the register change */
459 spin_lock(&hmaster->masks_lock);
460 mmr = uv_read_local_mmr(mmr_offset);
462 mask |= (3UL < right_shift);
465 uv_write_local_mmr(mmr_offset, mmr);
466 spin_unlock(&hmaster->masks_lock);
467 end_uvhub_quiesce(hmaster);
474 bcp->conseccompletes++;
475 return FLUSH_COMPLETE;
478 static inline cycles_t
479 sec_2_cycles(unsigned long sec)
484 ns = sec * 1000000000;
485 cyc = (ns << CYC2NS_SCALE_FACTOR)/(per_cpu(cyc2ns, smp_processor_id()));
490 * conditionally add 1 to *v, unless *v is >= u
491 * return 0 if we cannot add 1 to *v because it is >= u
492 * return 1 if we can add 1 to *v because it is < u
495 * This is close to atomic_add_unless(), but this allows the 'u' value
496 * to be lowered below the current 'v'. atomic_add_unless can only stop
499 static inline int atomic_inc_unless_ge(spinlock_t *lock, atomic_t *v, int u)
502 if (atomic_read(v) >= u) {
512 * uv_flush_send_and_wait
514 * Send a broadcast and wait for it to complete.
516 * The flush_mask contains the cpus the broadcast is to be sent to, plus
517 * cpus that are on the local uvhub.
519 * Returns NULL if all flushing represented in the mask was done. The mask
521 * Returns @flush_mask if some remote flushing remains to be done. The
522 * mask will have some bits still set, representing any cpus on the local
523 * uvhub (not current cpu) and any on remote uvhubs if the broadcast failed.
525 const struct cpumask *uv_flush_send_and_wait(struct bau_desc *bau_desc,
526 struct cpumask *flush_mask,
527 struct bau_control *bcp)
532 int completion_status = 0;
535 int cpu = bcp->uvhub_cpu;
536 int this_cpu = bcp->cpu;
537 int this_uvhub = bcp->uvhub;
538 unsigned long mmr_offset;
542 struct ptc_stats *stat = &per_cpu(ptcstats, bcp->cpu);
543 struct bau_control *smaster = bcp->socket_master;
544 struct bau_control *hmaster = bcp->uvhub_master;
547 * Spin here while there are hmaster->max_concurrent or more active
548 * descriptors. This is the per-uvhub 'throttle'.
550 if (!atomic_inc_unless_ge(&hmaster->uvhub_lock,
551 &hmaster->active_descriptor_count,
552 hmaster->max_concurrent)) {
556 } while (!atomic_inc_unless_ge(&hmaster->uvhub_lock,
557 &hmaster->active_descriptor_count,
558 hmaster->max_concurrent));
561 while (hmaster->uvhub_quiesce)
564 if (cpu < UV_CPUS_PER_ACT_STATUS) {
565 mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_0;
566 right_shift = cpu * UV_ACT_STATUS_SIZE;
568 mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_1;
570 ((cpu - UV_CPUS_PER_ACT_STATUS) * UV_ACT_STATUS_SIZE);
572 time1 = get_cycles();
575 * Every message from any given cpu gets a unique message
576 * sequence number. But retries use that same number.
577 * Our message may have timed out at the destination because
578 * all sw-ack resources are in use and there is a timeout
579 * pending there. In that case, our last send never got
580 * placed into the queue and we need to persist until it
583 * Make any retry a type MSG_RETRY so that the destination will
584 * free any resource held by a previous message from this cpu.
587 /* use message type set by the caller the first time */
588 seq_number = bcp->message_number++;
590 /* use RETRY type on all the rest; same sequence */
591 bau_desc->header.msg_type = MSG_RETRY;
592 stat->s_retry_messages++;
594 bau_desc->header.sequence = seq_number;
595 index = (1UL << UVH_LB_BAU_SB_ACTIVATION_CONTROL_PUSH_SHFT) |
597 bcp->send_message = get_cycles();
599 uv_write_local_mmr(UVH_LB_BAU_SB_ACTIVATION_CONTROL, index);
602 completion_status = uv_wait_completion(bau_desc, mmr_offset,
603 right_shift, this_cpu, bcp, smaster, try);
605 if (completion_status == FLUSH_RETRY_PLUGGED) {
607 * Our retries may be blocked by all destination swack
608 * resources being consumed, and a timeout pending. In
609 * that case hardware immediately returns the ERROR
610 * that looks like a destination timeout.
612 udelay(TIMEOUT_DELAY);
613 bcp->plugged_tries++;
614 if (bcp->plugged_tries >= PLUGSB4RESET) {
615 bcp->plugged_tries = 0;
616 quiesce_local_uvhub(hmaster);
617 spin_lock(&hmaster->queue_lock);
618 uv_reset_with_ipi(&bau_desc->distribution,
620 spin_unlock(&hmaster->queue_lock);
621 end_uvhub_quiesce(hmaster);
623 stat->s_resets_plug++;
625 } else if (completion_status == FLUSH_RETRY_TIMEOUT) {
626 hmaster->max_concurrent = 1;
627 bcp->timeout_tries++;
628 udelay(TIMEOUT_DELAY);
629 if (bcp->timeout_tries >= TIMEOUTSB4RESET) {
630 bcp->timeout_tries = 0;
631 quiesce_local_uvhub(hmaster);
632 spin_lock(&hmaster->queue_lock);
633 uv_reset_with_ipi(&bau_desc->distribution,
635 spin_unlock(&hmaster->queue_lock);
636 end_uvhub_quiesce(hmaster);
638 stat->s_resets_timeout++;
641 if (bcp->ipi_attempts >= 3) {
642 bcp->ipi_attempts = 0;
643 completion_status = FLUSH_GIVEUP;
647 } while ((completion_status == FLUSH_RETRY_PLUGGED) ||
648 (completion_status == FLUSH_RETRY_TIMEOUT));
649 time2 = get_cycles();
651 if ((completion_status == FLUSH_COMPLETE) && (bcp->conseccompletes > 5)
652 && (hmaster->max_concurrent < hmaster->max_concurrent_constant))
653 hmaster->max_concurrent++;
656 * hold any cpu not timing out here; no other cpu currently held by
657 * the 'throttle' should enter the activation code
659 while (hmaster->uvhub_quiesce)
661 atomic_dec(&hmaster->active_descriptor_count);
663 /* guard against cycles wrap */
665 stat->s_time += (time2 - time1);
667 stat->s_requestor--; /* don't count this one */
668 if (completion_status == FLUSH_COMPLETE && try > 1)
670 else if (completion_status == FLUSH_GIVEUP) {
672 * Cause the caller to do an IPI-style TLB shootdown on
673 * the target cpu's, all of which are still in the mask.
680 * Success, so clear the remote cpu's from the mask so we don't
681 * use the IPI method of shootdown on them.
683 for_each_cpu(bit, flush_mask) {
684 uvhub = uv_cpu_to_blade_id(bit);
685 if (uvhub == this_uvhub)
687 cpumask_clear_cpu(bit, flush_mask);
689 if (!cpumask_empty(flush_mask))
696 * uv_flush_tlb_others - globally purge translation cache of a virtual
697 * address or all TLB's
698 * @cpumask: mask of all cpu's in which the address is to be removed
699 * @mm: mm_struct containing virtual address range
700 * @va: virtual address to be removed (or TLB_FLUSH_ALL for all TLB's on cpu)
701 * @cpu: the current cpu
703 * This is the entry point for initiating any UV global TLB shootdown.
705 * Purges the translation caches of all specified processors of the given
706 * virtual address, or purges all TLB's on specified processors.
708 * The caller has derived the cpumask from the mm_struct. This function
709 * is called only if there are bits set in the mask. (e.g. flush_tlb_page())
711 * The cpumask is converted into a uvhubmask of the uvhubs containing
714 * Note that this function should be called with preemption disabled.
716 * Returns NULL if all remote flushing was done.
717 * Returns pointer to cpumask if some remote flushing remains to be
718 * done. The returned pointer is valid till preemption is re-enabled.
720 const struct cpumask *uv_flush_tlb_others(const struct cpumask *cpumask,
721 struct mm_struct *mm,
722 unsigned long va, unsigned int cpu)
728 struct bau_desc *bau_desc;
729 struct cpumask *flush_mask;
730 struct ptc_stats *stat;
731 struct bau_control *bcp;
736 bcp = &per_cpu(bau_control, cpu);
738 * Each sending cpu has a per-cpu mask which it fills from the caller's
739 * cpu mask. Only remote cpus are converted to uvhubs and copied.
741 flush_mask = (struct cpumask *)per_cpu(uv_flush_tlb_mask, cpu);
743 * copy cpumask to flush_mask, removing current cpu
744 * (current cpu should already have been flushed by the caller and
745 * should never be returned if we return flush_mask)
747 cpumask_andnot(flush_mask, cpumask, cpumask_of(cpu));
748 if (cpu_isset(cpu, *cpumask))
749 locals++; /* current cpu was targeted */
751 bau_desc = bcp->descriptor_base;
752 bau_desc += UV_ITEMS_PER_DESCRIPTOR * bcp->uvhub_cpu;
754 bau_uvhubs_clear(&bau_desc->distribution, UV_DISTRIBUTION_SIZE);
756 for_each_cpu(tcpu, flush_mask) {
757 uvhub = uv_cpu_to_blade_id(tcpu);
758 if (uvhub == bcp->uvhub) {
762 bau_uvhub_set(uvhub, &bau_desc->distribution);
767 * No off_hub flushing; return status for local hub.
768 * Return the caller's mask if all were local (the current
769 * cpu may be in that mask).
776 stat = &per_cpu(ptcstats, cpu);
778 stat->s_ntargcpu += remotes;
779 remotes = bau_uvhub_weight(&bau_desc->distribution);
780 stat->s_ntarguvhub += remotes;
782 stat->s_ntarguvhub16++;
783 else if (remotes >= 8)
784 stat->s_ntarguvhub8++;
785 else if (remotes >= 4)
786 stat->s_ntarguvhub4++;
787 else if (remotes >= 2)
788 stat->s_ntarguvhub2++;
790 stat->s_ntarguvhub1++;
792 bau_desc->payload.address = va;
793 bau_desc->payload.sending_cpu = cpu;
796 * uv_flush_send_and_wait returns null if all cpu's were messaged, or
797 * the adjusted flush_mask if any cpu's were not messaged.
799 return uv_flush_send_and_wait(bau_desc, flush_mask, bcp);
803 * The BAU message interrupt comes here. (registered by set_intr_gate)
806 * We received a broadcast assist message.
808 * Interrupts are disabled; this interrupt could represent
809 * the receipt of several messages.
811 * All cores/threads on this hub get this interrupt.
812 * The last one to see it does the software ack.
813 * (the resource will not be freed until noninterruptable cpus see this
814 * interrupt; hardware may timeout the s/w ack and reply ERROR)
816 void uv_bau_message_interrupt(struct pt_regs *regs)
820 struct bau_payload_queue_entry *msg;
821 struct bau_control *bcp;
822 struct ptc_stats *stat;
823 struct msg_desc msgdesc;
825 time_start = get_cycles();
826 bcp = &per_cpu(bau_control, smp_processor_id());
827 stat = &per_cpu(ptcstats, smp_processor_id());
828 msgdesc.va_queue_first = bcp->va_queue_first;
829 msgdesc.va_queue_last = bcp->va_queue_last;
830 msg = bcp->bau_msg_head;
831 while (msg->sw_ack_vector) {
833 msgdesc.msg_slot = msg - msgdesc.va_queue_first;
834 msgdesc.sw_ack_slot = ffs(msg->sw_ack_vector) - 1;
836 uv_bau_process_message(&msgdesc, bcp);
838 if (msg > msgdesc.va_queue_last)
839 msg = msgdesc.va_queue_first;
840 bcp->bau_msg_head = msg;
842 stat->d_time += (get_cycles() - time_start);
853 * Each target uvhub (i.e. a uvhub that has no cpu's) needs to have
854 * shootdown message timeouts enabled. The timeout does not cause
855 * an interrupt, but causes an error message to be returned to
858 static void uv_enable_timeouts(void)
863 unsigned long mmr_image;
865 nuvhubs = uv_num_possible_blades();
867 for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
868 if (!uv_blade_nr_possible_cpus(uvhub))
871 pnode = uv_blade_to_pnode(uvhub);
873 uv_read_global_mmr64(pnode, UVH_LB_BAU_MISC_CONTROL);
875 * Set the timeout period and then lock it in, in three
876 * steps; captures and locks in the period.
878 * To program the period, the SOFT_ACK_MODE must be off.
880 mmr_image &= ~((unsigned long)1 <<
881 UVH_LB_BAU_MISC_CONTROL_ENABLE_INTD_SOFT_ACK_MODE_SHFT);
882 uv_write_global_mmr64
883 (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image);
885 * Set the 4-bit period.
887 mmr_image &= ~((unsigned long)0xf <<
888 UVH_LB_BAU_MISC_CONTROL_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHFT);
889 mmr_image |= (UV_INTD_SOFT_ACK_TIMEOUT_PERIOD <<
890 UVH_LB_BAU_MISC_CONTROL_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHFT);
891 uv_write_global_mmr64
892 (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image);
894 * Subsequent reversals of the timebase bit (3) cause an
895 * immediate timeout of one or all INTD resources as
896 * indicated in bits 2:0 (7 causes all of them to timeout).
898 mmr_image |= ((unsigned long)1 <<
899 UVH_LB_BAU_MISC_CONTROL_ENABLE_INTD_SOFT_ACK_MODE_SHFT);
900 uv_write_global_mmr64
901 (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image);
905 static void *uv_ptc_seq_start(struct seq_file *file, loff_t *offset)
907 if (*offset < num_possible_cpus())
912 static void *uv_ptc_seq_next(struct seq_file *file, void *data, loff_t *offset)
915 if (*offset < num_possible_cpus())
920 static void uv_ptc_seq_stop(struct seq_file *file, void *data)
924 static inline unsigned long long
925 microsec_2_cycles(unsigned long microsec)
928 unsigned long long cyc;
930 ns = microsec * 1000;
931 cyc = (ns << CYC2NS_SCALE_FACTOR)/(per_cpu(cyc2ns, smp_processor_id()));
936 * Display the statistics thru /proc.
937 * 'data' points to the cpu number
939 static int uv_ptc_seq_show(struct seq_file *file, void *data)
941 struct ptc_stats *stat;
944 cpu = *(loff_t *)data;
948 "# cpu sent stime numuvhubs numuvhubs16 numuvhubs8 ");
950 "numuvhubs4 numuvhubs2 numuvhubs1 numcpus dto ");
952 "retries rok resetp resett giveup sto bz throt ");
954 "sw_ack recv rtime all ");
956 "one mult none retry canc nocan reset rcan\n");
958 if (cpu < num_possible_cpus() && cpu_online(cpu)) {
959 stat = &per_cpu(ptcstats, cpu);
960 /* source side statistics */
962 "cpu %d %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ",
963 cpu, stat->s_requestor, cycles_2_us(stat->s_time),
964 stat->s_ntarguvhub, stat->s_ntarguvhub16,
965 stat->s_ntarguvhub8, stat->s_ntarguvhub4,
966 stat->s_ntarguvhub2, stat->s_ntarguvhub1,
967 stat->s_ntargcpu, stat->s_dtimeout);
968 seq_printf(file, "%ld %ld %ld %ld %ld %ld %ld %ld ",
969 stat->s_retry_messages, stat->s_retriesok,
970 stat->s_resets_plug, stat->s_resets_timeout,
971 stat->s_giveup, stat->s_stimeout,
972 stat->s_busy, stat->s_throttles);
973 /* destination side statistics */
975 "%lx %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld\n",
976 uv_read_global_mmr64(uv_cpu_to_pnode(cpu),
977 UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE),
978 stat->d_requestee, cycles_2_us(stat->d_time),
979 stat->d_alltlb, stat->d_onetlb, stat->d_multmsg,
980 stat->d_nomsg, stat->d_retries, stat->d_canceled,
981 stat->d_nocanceled, stat->d_resets,
989 * -1: resetf the statistics
990 * 0: display meaning of the statistics
991 * >0: maximum concurrent active descriptors per uvhub (throttle)
993 static ssize_t uv_ptc_proc_write(struct file *file, const char __user *user,
994 size_t count, loff_t *data)
999 struct ptc_stats *stat;
1000 struct bau_control *bcp;
1002 if (count == 0 || count > sizeof(optstr))
1004 if (copy_from_user(optstr, user, count))
1006 optstr[count - 1] = '\0';
1007 if (strict_strtol(optstr, 10, &input_arg) < 0) {
1008 printk(KERN_DEBUG "%s is invalid\n", optstr);
1012 if (input_arg == 0) {
1013 printk(KERN_DEBUG "# cpu: cpu number\n");
1014 printk(KERN_DEBUG "Sender statistics:\n");
1016 "sent: number of shootdown messages sent\n");
1018 "stime: time spent sending messages\n");
1020 "numuvhubs: number of hubs targeted with shootdown\n");
1022 "numuvhubs16: number times 16 or more hubs targeted\n");
1024 "numuvhubs8: number times 8 or more hubs targeted\n");
1026 "numuvhubs4: number times 4 or more hubs targeted\n");
1028 "numuvhubs2: number times 2 or more hubs targeted\n");
1030 "numuvhubs1: number times 1 hub targeted\n");
1032 "numcpus: number of cpus targeted with shootdown\n");
1034 "dto: number of destination timeouts\n");
1036 "retries: destination timeout retries sent\n");
1038 "rok: : destination timeouts successfully retried\n");
1040 "resetp: ipi-style resource resets for plugs\n");
1042 "resett: ipi-style resource resets for timeouts\n");
1044 "giveup: fall-backs to ipi-style shootdowns\n");
1046 "sto: number of source timeouts\n");
1048 "bz: number of stay-busy's\n");
1050 "throt: number times spun in throttle\n");
1051 printk(KERN_DEBUG "Destination side statistics:\n");
1053 "sw_ack: image of UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE\n");
1055 "recv: shootdown messages received\n");
1057 "rtime: time spent processing messages\n");
1059 "all: shootdown all-tlb messages\n");
1061 "one: shootdown one-tlb messages\n");
1063 "mult: interrupts that found multiple messages\n");
1065 "none: interrupts that found no messages\n");
1067 "retry: number of retry messages processed\n");
1069 "canc: number messages canceled by retries\n");
1071 "nocan: number retries that found nothing to cancel\n");
1073 "reset: number of ipi-style reset requests processed\n");
1075 "rcan: number messages canceled by reset requests\n");
1076 } else if (input_arg == -1) {
1077 for_each_present_cpu(cpu) {
1078 stat = &per_cpu(ptcstats, cpu);
1079 memset(stat, 0, sizeof(struct ptc_stats));
1082 uv_bau_max_concurrent = input_arg;
1083 bcp = &per_cpu(bau_control, smp_processor_id());
1084 if (uv_bau_max_concurrent < 1 ||
1085 uv_bau_max_concurrent > bcp->cpus_in_uvhub) {
1087 "Error: BAU max concurrent %d; %d is invalid\n",
1088 bcp->max_concurrent, uv_bau_max_concurrent);
1091 printk(KERN_DEBUG "Set BAU max concurrent:%d\n",
1092 uv_bau_max_concurrent);
1093 for_each_present_cpu(cpu) {
1094 bcp = &per_cpu(bau_control, cpu);
1095 bcp->max_concurrent = uv_bau_max_concurrent;
1102 static const struct seq_operations uv_ptc_seq_ops = {
1103 .start = uv_ptc_seq_start,
1104 .next = uv_ptc_seq_next,
1105 .stop = uv_ptc_seq_stop,
1106 .show = uv_ptc_seq_show
1109 static int uv_ptc_proc_open(struct inode *inode, struct file *file)
1111 return seq_open(file, &uv_ptc_seq_ops);
1114 static const struct file_operations proc_uv_ptc_operations = {
1115 .open = uv_ptc_proc_open,
1117 .write = uv_ptc_proc_write,
1118 .llseek = seq_lseek,
1119 .release = seq_release,
1122 static int __init uv_ptc_init(void)
1124 struct proc_dir_entry *proc_uv_ptc;
1126 if (!is_uv_system())
1129 proc_uv_ptc = proc_create(UV_PTC_BASENAME, 0444, NULL,
1130 &proc_uv_ptc_operations);
1132 printk(KERN_ERR "unable to create %s proc entry\n",
1140 * initialize the sending side's sending buffers
1143 uv_activation_descriptor_init(int node, int pnode)
1150 struct bau_desc *bau_desc;
1151 struct bau_desc *bd2;
1152 struct bau_control *bcp;
1155 * each bau_desc is 64 bytes; there are 8 (UV_ITEMS_PER_DESCRIPTOR)
1156 * per cpu; and up to 32 (UV_ADP_SIZE) cpu's per uvhub
1158 bau_desc = (struct bau_desc *)kmalloc_node(sizeof(struct bau_desc)*
1159 UV_ADP_SIZE*UV_ITEMS_PER_DESCRIPTOR, GFP_KERNEL, node);
1162 pa = uv_gpa(bau_desc); /* need the real nasid*/
1163 n = pa >> uv_nshift;
1166 uv_write_global_mmr64(pnode, UVH_LB_BAU_SB_DESCRIPTOR_BASE,
1167 (n << UV_DESC_BASE_PNODE_SHIFT | m));
1170 * initializing all 8 (UV_ITEMS_PER_DESCRIPTOR) descriptors for each
1171 * cpu even though we only use the first one; one descriptor can
1172 * describe a broadcast to 256 uv hubs.
1174 for (i = 0, bd2 = bau_desc; i < (UV_ADP_SIZE*UV_ITEMS_PER_DESCRIPTOR);
1176 memset(bd2, 0, sizeof(struct bau_desc));
1177 bd2->header.sw_ack_flag = 1;
1179 * base_dest_nodeid is the nasid (pnode<<1) of the first uvhub
1180 * in the partition. The bit map will indicate uvhub numbers,
1181 * which are 0-N in a partition. Pnodes are unique system-wide.
1183 bd2->header.base_dest_nodeid = uv_partition_base_pnode << 1;
1184 bd2->header.dest_subnodeid = 0x10; /* the LB */
1185 bd2->header.command = UV_NET_ENDPOINT_INTD;
1186 bd2->header.int_both = 1;
1188 * all others need to be set to zero:
1189 * fairness chaining multilevel count replied_to
1192 for_each_present_cpu(cpu) {
1193 if (pnode != uv_blade_to_pnode(uv_cpu_to_blade_id(cpu)))
1195 bcp = &per_cpu(bau_control, cpu);
1196 bcp->descriptor_base = bau_desc;
1201 * initialize the destination side's receiving buffers
1202 * entered for each uvhub in the partition
1203 * - node is first node (kernel memory notion) on the uvhub
1204 * - pnode is the uvhub's physical identifier
1207 uv_payload_queue_init(int node, int pnode)
1213 struct bau_payload_queue_entry *pqp;
1214 struct bau_payload_queue_entry *pqp_malloc;
1215 struct bau_control *bcp;
1217 pqp = (struct bau_payload_queue_entry *) kmalloc_node(
1218 (DEST_Q_SIZE + 1) * sizeof(struct bau_payload_queue_entry),
1223 cp = (char *)pqp + 31;
1224 pqp = (struct bau_payload_queue_entry *)(((unsigned long)cp >> 5) << 5);
1226 for_each_present_cpu(cpu) {
1227 if (pnode != uv_cpu_to_pnode(cpu))
1229 /* for every cpu on this pnode: */
1230 bcp = &per_cpu(bau_control, cpu);
1231 bcp->va_queue_first = pqp;
1232 bcp->bau_msg_head = pqp;
1233 bcp->va_queue_last = pqp + (DEST_Q_SIZE - 1);
1236 * need the pnode of where the memory was really allocated
1239 pn = pa >> uv_nshift;
1240 uv_write_global_mmr64(pnode,
1241 UVH_LB_BAU_INTD_PAYLOAD_QUEUE_FIRST,
1242 ((unsigned long)pn << UV_PAYLOADQ_PNODE_SHIFT) |
1243 uv_physnodeaddr(pqp));
1244 uv_write_global_mmr64(pnode, UVH_LB_BAU_INTD_PAYLOAD_QUEUE_TAIL,
1245 uv_physnodeaddr(pqp));
1246 uv_write_global_mmr64(pnode, UVH_LB_BAU_INTD_PAYLOAD_QUEUE_LAST,
1248 uv_physnodeaddr(pqp + (DEST_Q_SIZE - 1)));
1249 /* in effect, all msg_type's are set to MSG_NOOP */
1250 memset(pqp, 0, sizeof(struct bau_payload_queue_entry) * DEST_Q_SIZE);
1254 * Initialization of each UV hub's structures
1256 static void __init uv_init_uvhub(int uvhub, int vector)
1260 unsigned long apicid;
1262 node = uvhub_to_first_node(uvhub);
1263 pnode = uv_blade_to_pnode(uvhub);
1264 uv_activation_descriptor_init(node, pnode);
1265 uv_payload_queue_init(node, pnode);
1267 * the below initialization can't be in firmware because the
1268 * messaging IRQ will be determined by the OS
1270 apicid = uvhub_to_first_apicid(uvhub);
1271 uv_write_global_mmr64(pnode, UVH_BAU_DATA_CONFIG,
1272 ((apicid << 32) | vector));
1276 * We will set BAU_MISC_CONTROL with a timeout period.
1277 * But the BIOS has set UVH_AGING_PRESCALE_SEL and UVH_TRANSACTION_TIMEOUT.
1278 * So the destination timeout period has be be calculated from them.
1281 calculate_destination_timeout(void)
1283 unsigned long mmr_image;
1289 unsigned long ts_ns;
1291 mult1 = UV_INTD_SOFT_ACK_TIMEOUT_PERIOD & BAU_MISC_CONTROL_MULT_MASK;
1292 mmr_image = uv_read_local_mmr(UVH_AGING_PRESCALE_SEL);
1293 index = (mmr_image >> BAU_URGENCY_7_SHIFT) & BAU_URGENCY_7_MASK;
1294 mmr_image = uv_read_local_mmr(UVH_TRANSACTION_TIMEOUT);
1295 mult2 = (mmr_image >> BAU_TRANS_SHIFT) & BAU_TRANS_MASK;
1296 base = timeout_base_ns[index];
1297 ts_ns = base * mult1 * mult2;
1303 * initialize the bau_control structure for each cpu
1305 static void uv_init_per_cpu(int nuvhubs)
1312 struct bau_control *bcp;
1313 struct uvhub_desc *bdp;
1314 struct socket_desc *sdp;
1315 struct bau_control *hmaster = NULL;
1316 struct bau_control *smaster = NULL;
1317 struct socket_desc {
1319 short cpu_number[16];
1326 struct socket_desc socket[2];
1328 struct uvhub_desc *uvhub_descs;
1330 timeout_us = calculate_destination_timeout();
1332 uvhub_descs = (struct uvhub_desc *)
1333 kmalloc(nuvhubs * sizeof(struct uvhub_desc), GFP_KERNEL);
1334 memset(uvhub_descs, 0, nuvhubs * sizeof(struct uvhub_desc));
1335 for_each_present_cpu(cpu) {
1336 bcp = &per_cpu(bau_control, cpu);
1337 memset(bcp, 0, sizeof(struct bau_control));
1338 spin_lock_init(&bcp->masks_lock);
1339 bcp->max_concurrent = uv_bau_max_concurrent;
1340 pnode = uv_cpu_hub_info(cpu)->pnode;
1341 uvhub = uv_cpu_hub_info(cpu)->numa_blade_id;
1342 bdp = &uvhub_descs[uvhub];
1346 /* time interval to catch a hardware stay-busy bug */
1347 bcp->timeout_interval = microsec_2_cycles(2*timeout_us);
1348 /* kludge: assume uv_hub.h is constant */
1349 socket = (cpu_physical_id(cpu)>>5)&1;
1350 if (socket >= bdp->num_sockets)
1351 bdp->num_sockets = socket+1;
1352 sdp = &bdp->socket[socket];
1353 sdp->cpu_number[sdp->num_cpus] = cpu;
1357 for_each_possible_blade(uvhub) {
1358 bdp = &uvhub_descs[uvhub];
1359 for (i = 0; i < bdp->num_sockets; i++) {
1360 sdp = &bdp->socket[i];
1361 for (j = 0; j < sdp->num_cpus; j++) {
1362 cpu = sdp->cpu_number[j];
1363 bcp = &per_cpu(bau_control, cpu);
1370 bcp->cpus_in_uvhub = bdp->num_cpus;
1371 bcp->cpus_in_socket = sdp->num_cpus;
1372 bcp->socket_master = smaster;
1373 bcp->uvhub_master = hmaster;
1374 for (k = 0; k < DEST_Q_SIZE; k++)
1375 bcp->socket_acknowledge_count[k] = 0;
1377 uv_cpu_hub_info(cpu)->blade_processor_id;
1386 * Initialization of BAU-related structures
1388 static int __init uv_bau_init(void)
1397 if (!is_uv_system())
1403 for_each_possible_cpu(cur_cpu)
1404 zalloc_cpumask_var_node(&per_cpu(uv_flush_tlb_mask, cur_cpu),
1405 GFP_KERNEL, cpu_to_node(cur_cpu));
1407 uv_bau_max_concurrent = MAX_BAU_CONCURRENT;
1408 uv_nshift = uv_hub_info->m_val;
1409 uv_mmask = (1UL << uv_hub_info->m_val) - 1;
1410 nuvhubs = uv_num_possible_blades();
1412 uv_init_per_cpu(nuvhubs);
1414 uv_partition_base_pnode = 0x7fffffff;
1415 for (uvhub = 0; uvhub < nuvhubs; uvhub++)
1416 if (uv_blade_nr_possible_cpus(uvhub) &&
1417 (uv_blade_to_pnode(uvhub) < uv_partition_base_pnode))
1418 uv_partition_base_pnode = uv_blade_to_pnode(uvhub);
1420 vector = UV_BAU_MESSAGE;
1421 for_each_possible_blade(uvhub)
1422 if (uv_blade_nr_possible_cpus(uvhub))
1423 uv_init_uvhub(uvhub, vector);
1425 uv_enable_timeouts();
1426 alloc_intr_gate(vector, uv_bau_message_intr1);
1428 for_each_possible_blade(uvhub) {
1429 pnode = uv_blade_to_pnode(uvhub);
1431 uv_write_global_mmr64(pnode, UVH_LB_BAU_SB_ACTIVATION_CONTROL,
1432 ((unsigned long)1 << 63));
1433 mmr = 1; /* should be 1 to broadcast to both sockets */
1434 uv_write_global_mmr64(pnode, UVH_BAU_DATA_BROADCAST, mmr);
1439 core_initcall(uv_bau_init);
1440 core_initcall(uv_ptc_init);