;;; -*- Mode:Lisp; Readtable:CL; Package:USER; Base:10; Patch-File:T -*-
;;; Patch file for System version 124.27
;;; Reason:
;;;  If you forcibly take the 3com controller with (si:set-processor-owning-ethernet),
;;;  you are now warned that unless the former 3com owner is dead, it must do a
;;;  (net:configure).
;;; Written 6-Jun-88 15:07:48 by pld (Peter L. DeWolf) at site Gigamos Cambridge
;;; while running on Azathoth from band 1
;;; with Experimental System 124.25, Experimental Local-File 74.1, Experimental File-Server 23.1, Experimental Unix-Interface 12.0, Experimental ZMail 72.1, Experimental Tape 23.6, Experimental Lambda-Diag 16.1, microcode 1756, SDU Boot Tape 3.14, SDU ROM 8, the old ones.



; From modified file DJ: L.NETWORK.KERNEL; CONFIGURE.LISP#102 at 6-Jun-88 15:07:49
#10R NETWORK#: 
(COMPILER-LET ((*PACKAGE* (GLOBAL:PKG-FIND-PACKAGE "NETWORK")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: NETWORK; KERNEL; CONFIGURE  "

(defun si:set-3com-owner (operation)
  (let* ((index (* 2 si:%system-configuration-ethernet-owner))
	 (lo (aref si:*sys-conf* index))
	 (hi (aref si:*sys-conf* (1+ index)))
	 (my-slot (si:get-slot-index si:rg-quad-slot))
	 (result nil))
    (flet ((write-ethernet-slot (n)
				(setf (aref si:*sys-conf* index) (ldb (byte 16. 0) n))
				(setf (aref si:*sys-conf* (1+ index)) (ldb (byte 16. 16.) n))))
      (if (and (= lo #o177777) (= hi #o177777))
	  (setq ethernet:*3com-owner* nil result "No 3com hardware.")
	(let ((current-owner (if (ldb-test (byte 1 15.) hi) (si:get-slot-index lo) nil)))
	  (cond (si:dont-use-3com
		 (when (and current-owner (= current-owner my-slot))
		   (write-ethernet-slot 0))	;if I own it, give it up
		 (setq ethernet:*3com-owner* nil)
		 (setq result "3com hardware reserved for raw ethernet"))
		((and (or (null current-owner) (= current-owner my-slot))
		      (or (eq operation :GIVE-UP) (eq operation nil)))
		 (write-ethernet-slot 0)
		 (setq ethernet:*3com-owner* nil)
		 (setq result "No one owns the 3com."))
		((or (null current-owner) (eq operation :TAKE) (eq operation t))
		 (write-ethernet-slot (dpb 1 (byte 1 31.) my-slot))
		 (setq ethernet:*3com-owner* si:*my-op*)
		 (when current-owner
		   (format t
       "~&WARNING: the 3com was owned by the processor in slot ~D but this processor has~
        ~%forcibly taken it.  If the other processor is dead, all is well, but if it is~
        ~%alive, both processors will get incorrect data until it does (net:configure)."
			   current-owner))
		 (setq result "I own the 3com."))
		(t				;:find, or don't own, but :give-up
		 (dolist (op (cons si:*my-op* si:*other-processors*)
			     (si:config-ferror nil "slot ~d (the ethernet owner) not found in sys-conf"
					       current-owner))
		   (when (= current-owner (si:%processor-conf-slot-number (si:op-proc-conf op)))
		     (setq ethernet:*3com-owner* op)
		     (setq result (if (= current-owner my-slot)
				      "I own the 3com."
				    (format nil "Processor in slot ~d owns the 3com." current-owner)))
		     (return)))))))
      (unless (eq ethernet:*3com-owner* si:*my-op*)
	(when (fboundp 'ethernet:disable-lambda-ucode)
	  (ethernet:disable-lambda-ucode)))
      result)))

))
