;;; -*- Mode:Lisp; Readtable:CL; Package:USER; Base:10; Patch-File:T -*-
;;; Patch file for System version 125.7
;;; Reason:
;;;  Fix to si:set-3com-owner and si:set-excelan-owner to not snarf the
;;;  respective ethernet boards unless the corresponding driver is loaded.
;;;  Doesn't really matter except in the cold load...
;;; Written 19-Jul-88 12:38:19 by pld (Peter L. DeWolf) at site Gigamos Cambridge
;;; while running on Cthulhu from band 3
;;; with System 125.6, ZWEI 125.2, ZMail 73.0, Local-File 75.0, File-Server 24.0, Unix-Interface 13.0, Tape 24.0, Lambda-Diag 17.0, Experimental Kermit 36.0, microcode 1761, SDU Boot Tape 3.14, SDU ROM 8.



; From modified file DJ: L.NETWORK.KERNEL; CONFIGURE.LISP#105 at 19-Jul-88 12:39:30
#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 ((not (fboundp 'ethernet:setup-3com))
		 (setq ethernet:*3com-owner* nil)
		 (setq result "No 3com driver"))
		(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)))

))

; From modified file DJ: L.NETWORK.KERNEL; CONFIGURE.LISP#105 at 19-Jul-88 12:39:32
#10R NETWORK#: 
(COMPILER-LET ((*PACKAGE* (GLOBAL:PKG-FIND-PACKAGE "NETWORK")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: NETWORK; KERNEL; CONFIGURE  "


(defun si:set-excelan-owner (operation)
  (let* ((device (fs:parse-pathname "EXCELAN-NETWORK-INTERFACE:"))
	 (host (and device (send device :host)))
	 (current-owner (and host (send host :owner)))
	 (my-slot (si:get-slot-index si:rg-quad-slot))
	 (result nil))
    (cond ((or (null host) (eq current-owner :not-on-bus))
	   (setq ethernet:*excelan-owner* nil)
	   (setq result "No Excelan hardware"))
	  ((not (fboundp 'ethernet:setup-excelan))
	   (setq ethernet:*excelan-owner* nil)
	   (setq result "No excelan driver"))
	  (si:dont-use-excelan
	   (when (and current-owner (= current-owner my-slot))
	     (send host :deallocate))
	   (setq ethernet:*excelan-owner* nil)
	   (setq result "Excelan hardware reserved for raw ethernet"))
	  ((and (or (null current-owner) (= current-owner my-slot))
		(or (eq operation :GIVE-UP) (eq operation nil)))
	   (send host :deallocate)
	   (setq ethernet:*excelan-owner* nil)
	   (setq result "No one owns the Excelan."))
	  ((or (null current-owner) (eq operation :TAKE) (eq operation t))
	   (send host :allocate)
	   (setq ethernet:*excelan-owner* si:*my-op*)
	   (setq result "I own the Excelan."))
	  (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 Excelan owner) not found in sys-conf"
					 current-owner))
	     (when (= current-owner (si:%processor-conf-slot-number (si:op-proc-conf op)))
	       (setq ethernet:*excelan-owner* op)
	       (setq result (if (= current-owner my-slot)
				"I own the Excelan."
			      (format nil "Processor in slot ~d owns the Excelan." current-owner)))
	       (return)))))
    result))

))
