Deleted Added
full compact
ipmi.c (257421) ipmi.c (278321)
1/*-
2 * Copyright (c) 2006 IronPort Systems Inc. <ambrisko@ironport.com>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2006 IronPort Systems Inc. <ambrisko@ironport.com>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/dev/ipmi/ipmi.c 257421 2013-10-31 05:13:53Z glebius $");
28__FBSDID("$FreeBSD: head/sys/dev/ipmi/ipmi.c 278321 2015-02-06 16:45:10Z jhb $");
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/bus.h>
33#include <sys/condvar.h>
34#include <sys/conf.h>
35#include <sys/kernel.h>
36#include <sys/malloc.h>

--- 7 unchanged lines hidden (view full) ---

44#ifdef LOCAL_MODULE
45#include <ipmi.h>
46#include <ipmivars.h>
47#else
48#include <sys/ipmi.h>
49#include <dev/ipmi/ipmivars.h>
50#endif
51
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/bus.h>
33#include <sys/condvar.h>
34#include <sys/conf.h>
35#include <sys/kernel.h>
36#include <sys/malloc.h>

--- 7 unchanged lines hidden (view full) ---

44#ifdef LOCAL_MODULE
45#include <ipmi.h>
46#include <ipmivars.h>
47#else
48#include <sys/ipmi.h>
49#include <dev/ipmi/ipmivars.h>
50#endif
51
52/*
53 * Driver request structures are allocated on the stack via alloca() to
54 * avoid calling malloc(), especially for the watchdog handler.
55 * To avoid too much stack growth, a previously allocated structure can
56 * be reused via IPMI_INIT_DRIVER_REQUEST(), but the caller should ensure
57 * that there is adequate reply/request space in the original allocation.
58 */
59#define IPMI_INIT_DRIVER_REQUEST(req, addr, cmd, reqlen, replylen) \
60 bzero((req), sizeof(struct ipmi_request)); \
61 ipmi_init_request((req), NULL, 0, (addr), (cmd), (reqlen), (replylen))
62
63#define IPMI_ALLOC_DRIVER_REQUEST(req, addr, cmd, reqlen, replylen) \
64 (req) = __builtin_alloca(sizeof(struct ipmi_request) + \
65 (reqlen) + (replylen)); \
66 IPMI_INIT_DRIVER_REQUEST((req), (addr), (cmd), (reqlen), \
67 (replylen))
68
52#ifdef IPMB
53static int ipmi_ipmb_checksum(u_char, int);
54static int ipmi_ipmb_send_message(device_t, u_char, u_char, u_char,
55 u_char, u_char, int)
56#endif
57
58static d_ioctl_t ipmi_ioctl;
59static d_poll_t ipmi_poll;

--- 116 unchanged lines hidden (view full) ---

176 ipmi_purge_completed_requests(dev);
177
178 /*
179 * If we still have outstanding requests, they must be stuck
180 * in an interface driver, so wait for those to drain.
181 */
182 dev->ipmi_closing = 1;
183 while (dev->ipmi_requests > 0) {
69#ifdef IPMB
70static int ipmi_ipmb_checksum(u_char, int);
71static int ipmi_ipmb_send_message(device_t, u_char, u_char, u_char,
72 u_char, u_char, int)
73#endif
74
75static d_ioctl_t ipmi_ioctl;
76static d_poll_t ipmi_poll;

--- 116 unchanged lines hidden (view full) ---

193 ipmi_purge_completed_requests(dev);
194
195 /*
196 * If we still have outstanding requests, they must be stuck
197 * in an interface driver, so wait for those to drain.
198 */
199 dev->ipmi_closing = 1;
200 while (dev->ipmi_requests > 0) {
184 msleep(&dev->ipmi_requests, &sc->ipmi_lock, PWAIT,
185 "ipmidrain", 0);
201 msleep(&dev->ipmi_requests, &sc->ipmi_requests_lock,
202 PWAIT, "ipmidrain", 0);
186 ipmi_purge_completed_requests(dev);
187 }
188 }
189 sc->ipmi_opened--;
190 IPMI_UNLOCK(sc);
191
192 /* Cleanup. */
193 free(dev, M_IPMI);

--- 16 unchanged lines hidden (view full) ---

210ipmi_ipmb_send_message(device_t dev, u_char channel, u_char netfn,
211 u_char command, u_char seq, u_char *data, int data_len)
212{
213 struct ipmi_softc *sc = device_get_softc(dev);
214 struct ipmi_request *req;
215 u_char slave_addr = 0x52;
216 int error;
217
203 ipmi_purge_completed_requests(dev);
204 }
205 }
206 sc->ipmi_opened--;
207 IPMI_UNLOCK(sc);
208
209 /* Cleanup. */
210 free(dev, M_IPMI);

--- 16 unchanged lines hidden (view full) ---

227ipmi_ipmb_send_message(device_t dev, u_char channel, u_char netfn,
228 u_char command, u_char seq, u_char *data, int data_len)
229{
230 struct ipmi_softc *sc = device_get_softc(dev);
231 struct ipmi_request *req;
232 u_char slave_addr = 0x52;
233 int error;
234
218 req = ipmi_alloc_driver_request(IPMI_ADDR(IPMI_APP_REQUEST, 0),
235 IPMI_ALLOC_DRIVER_REQUEST(req, IPMI_ADDR(IPMI_APP_REQUEST, 0),
219 IPMI_SEND_MSG, data_len + 8, 0);
220 req->ir_request[0] = channel;
221 req->ir_request[1] = slave_addr;
222 req->ir_request[2] = IPMI_ADDR(netfn, 0);
223 req->ir_request[3] = ipmi_ipmb_checksum(&req->ir_request[1], 2);
224 req->ir_request[4] = sc->ipmi_address;
225 req->ir_request[5] = IPMI_ADDR(seq, sc->ipmi_lun);
226 req->ir_request[6] = command;
227
228 bcopy(data, &req->ir_request[7], data_len);
229 temp[data_len + 7] = ipmi_ipmb_checksum(&req->ir_request[4],
230 data_len + 3);
231
232 ipmi_submit_driver_request(sc, req);
233 error = req->ir_error;
236 IPMI_SEND_MSG, data_len + 8, 0);
237 req->ir_request[0] = channel;
238 req->ir_request[1] = slave_addr;
239 req->ir_request[2] = IPMI_ADDR(netfn, 0);
240 req->ir_request[3] = ipmi_ipmb_checksum(&req->ir_request[1], 2);
241 req->ir_request[4] = sc->ipmi_address;
242 req->ir_request[5] = IPMI_ADDR(seq, sc->ipmi_lun);
243 req->ir_request[6] = command;
244
245 bcopy(data, &req->ir_request[7], data_len);
246 temp[data_len + 7] = ipmi_ipmb_checksum(&req->ir_request[4],
247 data_len + 3);
248
249 ipmi_submit_driver_request(sc, req);
250 error = req->ir_error;
234 ipmi_free_request(req);
235
236 return (error);
237}
238
239static int
240ipmi_handle_attn(struct ipmi_softc *sc)
241{
242 struct ipmi_request *req;
243 int error;
244
245 device_printf(sc->ipmi_dev, "BMC has a message\n");
251
252 return (error);
253}
254
255static int
256ipmi_handle_attn(struct ipmi_softc *sc)
257{
258 struct ipmi_request *req;
259 int error;
260
261 device_printf(sc->ipmi_dev, "BMC has a message\n");
246 req = ipmi_alloc_driver_request(IPMI_ADDR(IPMI_APP_REQUEST, 0),
262 IPMI_ALLOC_DRIVER_REQUEST(req, IPMI_ADDR(IPMI_APP_REQUEST, 0),
247 IPMI_GET_MSG_FLAGS, 0, 1);
248
249 ipmi_submit_driver_request(sc, req);
250
251 if (req->ir_error == 0 && req->ir_compcode == 0) {
252 if (req->ir_reply[0] & IPMI_MSG_BUFFER_FULL) {
253 device_printf(sc->ipmi_dev, "message buffer full");
254 }
255 if (req->ir_reply[0] & IPMI_WDT_PRE_TIMEOUT) {
256 device_printf(sc->ipmi_dev,
257 "watchdog about to go off");
258 }
259 if (req->ir_reply[0] & IPMI_MSG_AVAILABLE) {
263 IPMI_GET_MSG_FLAGS, 0, 1);
264
265 ipmi_submit_driver_request(sc, req);
266
267 if (req->ir_error == 0 && req->ir_compcode == 0) {
268 if (req->ir_reply[0] & IPMI_MSG_BUFFER_FULL) {
269 device_printf(sc->ipmi_dev, "message buffer full");
270 }
271 if (req->ir_reply[0] & IPMI_WDT_PRE_TIMEOUT) {
272 device_printf(sc->ipmi_dev,
273 "watchdog about to go off");
274 }
275 if (req->ir_reply[0] & IPMI_MSG_AVAILABLE) {
260 ipmi_free_request(req);
261
262 req = ipmi_alloc_driver_request(
276 IPMI_ALLOC_DRIVER_REQUEST(req,
263 IPMI_ADDR(IPMI_APP_REQUEST, 0), IPMI_GET_MSG, 0,
264 16);
265
266 device_printf(sc->ipmi_dev, "throw out message ");
267 dump_buf(temp, 16);
268 }
269 }
270 error = req->ir_error;
277 IPMI_ADDR(IPMI_APP_REQUEST, 0), IPMI_GET_MSG, 0,
278 16);
279
280 device_printf(sc->ipmi_dev, "throw out message ");
281 dump_buf(temp, 16);
282 }
283 }
284 error = req->ir_error;
271 ipmi_free_request(req);
272
273 return (error);
274}
275#endif
276
277#ifdef IPMICTL_SEND_COMMAND_32
278#define PTRIN(p) ((void *)(uintptr_t)(p))
279#define PTROUT(p) ((uintptr_t)(p))

--- 193 unchanged lines hidden (view full) ---

473#endif
474 return (0);
475}
476
477/*
478 * Request management.
479 */
480
285
286 return (error);
287}
288#endif
289
290#ifdef IPMICTL_SEND_COMMAND_32
291#define PTRIN(p) ((void *)(uintptr_t)(p))
292#define PTROUT(p) ((uintptr_t)(p))

--- 193 unchanged lines hidden (view full) ---

486#endif
487 return (0);
488}
489
490/*
491 * Request management.
492 */
493
481/* Allocate a new request with request and reply buffers. */
482struct ipmi_request *
483ipmi_alloc_request(struct ipmi_device *dev, long msgid, uint8_t addr,
484 uint8_t command, size_t requestlen, size_t replylen)
494static __inline void
495ipmi_init_request(struct ipmi_request *req, struct ipmi_device *dev, long msgid,
496 uint8_t addr, uint8_t command, size_t requestlen, size_t replylen)
485{
497{
486 struct ipmi_request *req;
487
498
488 req = malloc(sizeof(struct ipmi_request) + requestlen + replylen,
489 M_IPMI, M_WAITOK | M_ZERO);
490 req->ir_owner = dev;
491 req->ir_msgid = msgid;
492 req->ir_addr = addr;
493 req->ir_command = command;
494 if (requestlen) {
495 req->ir_request = (char *)&req[1];
496 req->ir_requestlen = requestlen;
497 }
498 if (replylen) {
499 req->ir_reply = (char *)&req[1] + requestlen;
500 req->ir_replybuflen = replylen;
501 }
499 req->ir_owner = dev;
500 req->ir_msgid = msgid;
501 req->ir_addr = addr;
502 req->ir_command = command;
503 if (requestlen) {
504 req->ir_request = (char *)&req[1];
505 req->ir_requestlen = requestlen;
506 }
507 if (replylen) {
508 req->ir_reply = (char *)&req[1] + requestlen;
509 req->ir_replybuflen = replylen;
510 }
511}
512
513/* Allocate a new request with request and reply buffers. */
514struct ipmi_request *
515ipmi_alloc_request(struct ipmi_device *dev, long msgid, uint8_t addr,
516 uint8_t command, size_t requestlen, size_t replylen)
517{
518 struct ipmi_request *req;
519
520 req = malloc(sizeof(struct ipmi_request) + requestlen + replylen,
521 M_IPMI, M_WAITOK | M_ZERO);
522 ipmi_init_request(req, dev, msgid, addr, command, requestlen, replylen);
502 return (req);
503}
504
505/* Free a request no longer in use. */
506void
507ipmi_free_request(struct ipmi_request *req)
508{
509

--- 18 unchanged lines hidden (view full) ---

528 dev = req->ir_owner;
529 TAILQ_INSERT_TAIL(&dev->ipmi_completed_requests, req, ir_link);
530 selwakeup(&dev->ipmi_select);
531 if (dev->ipmi_closing)
532 wakeup(&dev->ipmi_requests);
533 }
534}
535
523 return (req);
524}
525
526/* Free a request no longer in use. */
527void
528ipmi_free_request(struct ipmi_request *req)
529{
530

--- 18 unchanged lines hidden (view full) ---

549 dev = req->ir_owner;
550 TAILQ_INSERT_TAIL(&dev->ipmi_completed_requests, req, ir_link);
551 selwakeup(&dev->ipmi_select);
552 if (dev->ipmi_closing)
553 wakeup(&dev->ipmi_requests);
554 }
555}
556
536/* Enqueue an internal driver request and wait until it is completed. */
557/* Perform an internal driver request. */
537int
538ipmi_submit_driver_request(struct ipmi_softc *sc, struct ipmi_request *req,
539 int timo)
540{
558int
559ipmi_submit_driver_request(struct ipmi_softc *sc, struct ipmi_request *req,
560 int timo)
561{
541 int error;
542
562
543 IPMI_LOCK(sc);
544 error = sc->ipmi_enqueue_request(sc, req);
545 if (error == 0)
546 error = msleep(req, &sc->ipmi_lock, 0, "ipmireq", timo);
547 if (error == 0)
548 error = req->ir_error;
549 IPMI_UNLOCK(sc);
550 return (error);
563 return (sc->ipmi_driver_request(sc, req, timo));
551}
552
553/*
554 * Helper routine for polled system interfaces that use
555 * ipmi_polled_enqueue_request() to queue requests. This request
556 * waits until there is a pending request and then returns the first
557 * request. If the driver is shutting down, it returns NULL.
558 */
559struct ipmi_request *
560ipmi_dequeue_request(struct ipmi_softc *sc)
561{
562 struct ipmi_request *req;
563
564 IPMI_LOCK_ASSERT(sc);
565
566 while (!sc->ipmi_detaching && TAILQ_EMPTY(&sc->ipmi_pending_requests))
564}
565
566/*
567 * Helper routine for polled system interfaces that use
568 * ipmi_polled_enqueue_request() to queue requests. This request
569 * waits until there is a pending request and then returns the first
570 * request. If the driver is shutting down, it returns NULL.
571 */
572struct ipmi_request *
573ipmi_dequeue_request(struct ipmi_softc *sc)
574{
575 struct ipmi_request *req;
576
577 IPMI_LOCK_ASSERT(sc);
578
579 while (!sc->ipmi_detaching && TAILQ_EMPTY(&sc->ipmi_pending_requests))
567 cv_wait(&sc->ipmi_request_added, &sc->ipmi_lock);
580 cv_wait(&sc->ipmi_request_added, &sc->ipmi_requests_lock);
568 if (sc->ipmi_detaching)
569 return (NULL);
570
571 req = TAILQ_FIRST(&sc->ipmi_pending_requests);
572 TAILQ_REMOVE(&sc->ipmi_pending_requests, req, ir_link);
573 return (req);
574}
575

--- 17 unchanged lines hidden (view full) ---

593ipmi_set_watchdog(struct ipmi_softc *sc, unsigned int sec)
594{
595 struct ipmi_request *req;
596 int error;
597
598 if (sec > 0xffff / 10)
599 return (EINVAL);
600
581 if (sc->ipmi_detaching)
582 return (NULL);
583
584 req = TAILQ_FIRST(&sc->ipmi_pending_requests);
585 TAILQ_REMOVE(&sc->ipmi_pending_requests, req, ir_link);
586 return (req);
587}
588

--- 17 unchanged lines hidden (view full) ---

606ipmi_set_watchdog(struct ipmi_softc *sc, unsigned int sec)
607{
608 struct ipmi_request *req;
609 int error;
610
611 if (sec > 0xffff / 10)
612 return (EINVAL);
613
601 req = ipmi_alloc_driver_request(IPMI_ADDR(IPMI_APP_REQUEST, 0),
614 IPMI_ALLOC_DRIVER_REQUEST(req, IPMI_ADDR(IPMI_APP_REQUEST, 0),
602 IPMI_SET_WDOG, 6, 0);
603
604 if (sec) {
605 req->ir_request[0] = IPMI_SET_WD_TIMER_DONT_STOP
606 | IPMI_SET_WD_TIMER_SMS_OS;
607 req->ir_request[1] = IPMI_SET_WD_ACTION_RESET;
608 req->ir_request[2] = 0;
609 req->ir_request[3] = 0; /* Timer use */

--- 7 unchanged lines hidden (view full) ---

617 req->ir_request[4] = 0;
618 req->ir_request[5] = 0;
619 }
620
621 error = ipmi_submit_driver_request(sc, req, 0);
622 if (error)
623 device_printf(sc->ipmi_dev, "Failed to set watchdog\n");
624 else if (sec) {
615 IPMI_SET_WDOG, 6, 0);
616
617 if (sec) {
618 req->ir_request[0] = IPMI_SET_WD_TIMER_DONT_STOP
619 | IPMI_SET_WD_TIMER_SMS_OS;
620 req->ir_request[1] = IPMI_SET_WD_ACTION_RESET;
621 req->ir_request[2] = 0;
622 req->ir_request[3] = 0; /* Timer use */

--- 7 unchanged lines hidden (view full) ---

630 req->ir_request[4] = 0;
631 req->ir_request[5] = 0;
632 }
633
634 error = ipmi_submit_driver_request(sc, req, 0);
635 if (error)
636 device_printf(sc->ipmi_dev, "Failed to set watchdog\n");
637 else if (sec) {
625 ipmi_free_request(req);
626
627 req = ipmi_alloc_driver_request(IPMI_ADDR(IPMI_APP_REQUEST, 0),
638 IPMI_INIT_DRIVER_REQUEST(req, IPMI_ADDR(IPMI_APP_REQUEST, 0),
628 IPMI_RESET_WDOG, 0, 0);
629
630 error = ipmi_submit_driver_request(sc, req, 0);
631 if (error)
632 device_printf(sc->ipmi_dev,
633 "Failed to reset watchdog\n");
634 }
635
639 IPMI_RESET_WDOG, 0, 0);
640
641 error = ipmi_submit_driver_request(sc, req, 0);
642 if (error)
643 device_printf(sc->ipmi_dev,
644 "Failed to reset watchdog\n");
645 }
646
636 ipmi_free_request(req);
637 return (error);
638 /*
639 dump_watchdog(sc);
640 */
641}
642
643static void
644ipmi_wd_event(void *arg, unsigned int cmd, int *error)

--- 30 unchanged lines hidden (view full) ---

675 struct ipmi_request *req;
676 device_t dev;
677 int error, i;
678
679 config_intrhook_disestablish(&sc->ipmi_ich);
680 dev = sc->ipmi_dev;
681
682 /* Initialize interface-independent state. */
647 return (error);
648 /*
649 dump_watchdog(sc);
650 */
651}
652
653static void
654ipmi_wd_event(void *arg, unsigned int cmd, int *error)

--- 30 unchanged lines hidden (view full) ---

685 struct ipmi_request *req;
686 device_t dev;
687 int error, i;
688
689 config_intrhook_disestablish(&sc->ipmi_ich);
690 dev = sc->ipmi_dev;
691
692 /* Initialize interface-independent state. */
683 mtx_init(&sc->ipmi_lock, device_get_nameunit(dev), "ipmi", MTX_DEF);
693 mtx_init(&sc->ipmi_requests_lock, "ipmi requests", NULL, MTX_DEF);
694 mtx_init(&sc->ipmi_io_lock, "ipmi io", NULL, MTX_DEF);
684 cv_init(&sc->ipmi_request_added, "ipmireq");
685 TAILQ_INIT(&sc->ipmi_pending_requests);
686
687 /* Initialize interface-dependent state. */
688 error = sc->ipmi_startup(sc);
689 if (error) {
690 device_printf(dev, "Failed to initialize interface: %d\n",
691 error);
692 return;
693 }
694
695 /* Send a GET_DEVICE_ID request. */
695 cv_init(&sc->ipmi_request_added, "ipmireq");
696 TAILQ_INIT(&sc->ipmi_pending_requests);
697
698 /* Initialize interface-dependent state. */
699 error = sc->ipmi_startup(sc);
700 if (error) {
701 device_printf(dev, "Failed to initialize interface: %d\n",
702 error);
703 return;
704 }
705
706 /* Send a GET_DEVICE_ID request. */
696 req = ipmi_alloc_driver_request(IPMI_ADDR(IPMI_APP_REQUEST, 0),
707 IPMI_ALLOC_DRIVER_REQUEST(req, IPMI_ADDR(IPMI_APP_REQUEST, 0),
697 IPMI_GET_DEVICE_ID, 0, 15);
698
699 error = ipmi_submit_driver_request(sc, req, MAX_TIMEOUT);
700 if (error == EWOULDBLOCK) {
701 device_printf(dev, "Timed out waiting for GET_DEVICE_ID\n");
708 IPMI_GET_DEVICE_ID, 0, 15);
709
710 error = ipmi_submit_driver_request(sc, req, MAX_TIMEOUT);
711 if (error == EWOULDBLOCK) {
712 device_printf(dev, "Timed out waiting for GET_DEVICE_ID\n");
702 ipmi_free_request(req);
703 return;
704 } else if (error) {
705 device_printf(dev, "Failed GET_DEVICE_ID: %d\n", error);
713 return;
714 } else if (error) {
715 device_printf(dev, "Failed GET_DEVICE_ID: %d\n", error);
706 ipmi_free_request(req);
707 return;
708 } else if (req->ir_compcode != 0) {
709 device_printf(dev,
710 "Bad completion code for GET_DEVICE_ID: %d\n",
711 req->ir_compcode);
716 return;
717 } else if (req->ir_compcode != 0) {
718 device_printf(dev,
719 "Bad completion code for GET_DEVICE_ID: %d\n",
720 req->ir_compcode);
712 ipmi_free_request(req);
713 return;
714 } else if (req->ir_replylen < 5) {
715 device_printf(dev, "Short reply for GET_DEVICE_ID: %d\n",
716 req->ir_replylen);
721 return;
722 } else if (req->ir_replylen < 5) {
723 device_printf(dev, "Short reply for GET_DEVICE_ID: %d\n",
724 req->ir_replylen);
717 ipmi_free_request(req);
718 return;
719 }
720
721 device_printf(dev, "IPMI device rev. %d, firmware rev. %d.%d%d, "
722 "version %d.%d\n",
723 req->ir_reply[1] & 0x0f,
724 req->ir_reply[2] & 0x7f, req->ir_reply[3] >> 4, req->ir_reply[3] & 0x0f,
725 req->ir_reply[4] & 0x0f, req->ir_reply[4] >> 4);
726
725 return;
726 }
727
728 device_printf(dev, "IPMI device rev. %d, firmware rev. %d.%d%d, "
729 "version %d.%d\n",
730 req->ir_reply[1] & 0x0f,
731 req->ir_reply[2] & 0x7f, req->ir_reply[3] >> 4, req->ir_reply[3] & 0x0f,
732 req->ir_reply[4] & 0x0f, req->ir_reply[4] >> 4);
733
727 ipmi_free_request(req);
728
729 req = ipmi_alloc_driver_request(IPMI_ADDR(IPMI_APP_REQUEST, 0),
734 IPMI_INIT_DRIVER_REQUEST(req, IPMI_ADDR(IPMI_APP_REQUEST, 0),
730 IPMI_CLEAR_FLAGS, 1, 0);
731
732 ipmi_submit_driver_request(sc, req, 0);
733
734 /* XXX: Magic numbers */
735 if (req->ir_compcode == 0xc0) {
736 device_printf(dev, "Clear flags is busy\n");
737 }
738 if (req->ir_compcode == 0xc1) {
739 device_printf(dev, "Clear flags illegal\n");
740 }
735 IPMI_CLEAR_FLAGS, 1, 0);
736
737 ipmi_submit_driver_request(sc, req, 0);
738
739 /* XXX: Magic numbers */
740 if (req->ir_compcode == 0xc0) {
741 device_printf(dev, "Clear flags is busy\n");
742 }
743 if (req->ir_compcode == 0xc1) {
744 device_printf(dev, "Clear flags illegal\n");
745 }
741 ipmi_free_request(req);
742
743 for (i = 0; i < 8; i++) {
746
747 for (i = 0; i < 8; i++) {
744 req = ipmi_alloc_driver_request(IPMI_ADDR(IPMI_APP_REQUEST, 0),
748 IPMI_INIT_DRIVER_REQUEST(req, IPMI_ADDR(IPMI_APP_REQUEST, 0),
745 IPMI_GET_CHANNEL_INFO, 1, 0);
746 req->ir_request[0] = i;
747
748 ipmi_submit_driver_request(sc, req, 0);
749
749 IPMI_GET_CHANNEL_INFO, 1, 0);
750 req->ir_request[0] = i;
751
752 ipmi_submit_driver_request(sc, req, 0);
753
750 if (req->ir_compcode != 0) {
751 ipmi_free_request(req);
754 if (req->ir_compcode != 0)
752 break;
755 break;
753 }
754 ipmi_free_request(req);
755 }
756 device_printf(dev, "Number of channels %d\n", i);
757
758 /* probe for watchdog */
756 }
757 device_printf(dev, "Number of channels %d\n", i);
758
759 /* probe for watchdog */
759 req = ipmi_alloc_driver_request(IPMI_ADDR(IPMI_APP_REQUEST, 0),
760 IPMI_INIT_DRIVER_REQUEST(req, IPMI_ADDR(IPMI_APP_REQUEST, 0),
760 IPMI_GET_WDOG, 0, 0);
761
762 ipmi_submit_driver_request(sc, req, 0);
763
764 if (req->ir_compcode == 0x00) {
765 device_printf(dev, "Attached watchdog\n");
766 /* register the watchdog event handler */
767 sc->ipmi_watchdog_tag = EVENTHANDLER_REGISTER(watchdog_list,
768 ipmi_wd_event, sc, 0);
769 }
761 IPMI_GET_WDOG, 0, 0);
762
763 ipmi_submit_driver_request(sc, req, 0);
764
765 if (req->ir_compcode == 0x00) {
766 device_printf(dev, "Attached watchdog\n");
767 /* register the watchdog event handler */
768 sc->ipmi_watchdog_tag = EVENTHANDLER_REGISTER(watchdog_list,
769 ipmi_wd_event, sc, 0);
770 }
770 ipmi_free_request(req);
771
772 sc->ipmi_cdev = make_dev(&ipmi_cdevsw, device_get_unit(dev),
773 UID_ROOT, GID_OPERATOR, 0660, "ipmi%d", device_get_unit(dev));
774 if (sc->ipmi_cdev == NULL) {
775 device_printf(dev, "Failed to create cdev\n");
776 return;
777 }
778 sc->ipmi_cdev->si_drv1 = sc;

--- 50 unchanged lines hidden (view full) ---

829 }
830
831 /* XXX: should use shutdown callout I think. */
832 /* If the backend uses a kthread, shut it down. */
833 IPMI_LOCK(sc);
834 sc->ipmi_detaching = 1;
835 if (sc->ipmi_kthread) {
836 cv_broadcast(&sc->ipmi_request_added);
771
772 sc->ipmi_cdev = make_dev(&ipmi_cdevsw, device_get_unit(dev),
773 UID_ROOT, GID_OPERATOR, 0660, "ipmi%d", device_get_unit(dev));
774 if (sc->ipmi_cdev == NULL) {
775 device_printf(dev, "Failed to create cdev\n");
776 return;
777 }
778 sc->ipmi_cdev->si_drv1 = sc;

--- 50 unchanged lines hidden (view full) ---

829 }
830
831 /* XXX: should use shutdown callout I think. */
832 /* If the backend uses a kthread, shut it down. */
833 IPMI_LOCK(sc);
834 sc->ipmi_detaching = 1;
835 if (sc->ipmi_kthread) {
836 cv_broadcast(&sc->ipmi_request_added);
837 msleep(sc->ipmi_kthread, &sc->ipmi_lock, 0, "ipmi_wait", 0);
837 msleep(sc->ipmi_kthread, &sc->ipmi_requests_lock, 0,
838 "ipmi_wait", 0);
838 }
839 IPMI_UNLOCK(sc);
840 if (sc->ipmi_irq)
841 bus_teardown_intr(dev, sc->ipmi_irq_res, sc->ipmi_irq);
842
843 ipmi_release_resources(dev);
839 }
840 IPMI_UNLOCK(sc);
841 if (sc->ipmi_irq)
842 bus_teardown_intr(dev, sc->ipmi_irq_res, sc->ipmi_irq);
843
844 ipmi_release_resources(dev);
844 mtx_destroy(&sc->ipmi_lock);
845 mtx_destroy(&sc->ipmi_io_lock);
846 mtx_destroy(&sc->ipmi_requests_lock);
845 return (0);
846}
847
848void
849ipmi_release_resources(device_t dev)
850{
851 struct ipmi_softc *sc;
852 int i;

--- 70 unchanged lines hidden ---
847 return (0);
848}
849
850void
851ipmi_release_resources(device_t dev)
852{
853 struct ipmi_softc *sc;
854 int i;

--- 70 unchanged lines hidden ---