1 // SPDX-License-Identifier: GPL-2.0
3 * Driver for the HP iLO management processor.
5 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
8 #include <linux/kernel.h>
9 #include <linux/types.h>
10 #include <linux/module.h>
12 #include <linux/pci.h>
13 #include <linux/interrupt.h>
14 #include <linux/ioport.h>
15 #include <linux/device.h>
16 #include <linux/file.h>
17 #include <linux/cdev.h>
18 #include <linux/sched.h>
19 #include <linux/spinlock.h>
20 #include <linux/delay.h>
21 #include <linux/uaccess.h>
23 #include <linux/wait.h>
24 #include <linux/poll.h>
25 #include <linux/slab.h>
28 static struct class *ilo_class;
29 static unsigned int ilo_major;
30 static unsigned int max_ccb = 16;
31 static char ilo_hwdev[MAX_ILO_DEV];
32 static const struct pci_device_id ilo_blacklist[] = {
34 {PCI_DEVICE_SUB(PCI_VENDOR_ID_HP, 0x3307, PCI_VENDOR_ID_HP, 0x1979)},
36 {PCI_DEVICE_SUB(PCI_VENDOR_ID_HP, 0x3307, PCI_VENDOR_ID_HP_3PAR, 0x0289)},
40 static inline int get_entry_id(int entry)
42 return (entry & ENTRY_MASK_DESCRIPTOR) >> ENTRY_BITPOS_DESCRIPTOR;
45 static inline int get_entry_len(int entry)
47 return ((entry & ENTRY_MASK_QWORDS) >> ENTRY_BITPOS_QWORDS) << 3;
50 static inline int mk_entry(int id, int len)
52 int qlen = len & 7 ? (len >> 3) + 1 : len >> 3;
53 return id << ENTRY_BITPOS_DESCRIPTOR | qlen << ENTRY_BITPOS_QWORDS;
56 static inline int desc_mem_sz(int nr_entry)
58 return nr_entry << L2_QENTRY_SZ;
62 * FIFO queues, shared with hardware.
64 * If a queue has empty slots, an entry is added to the queue tail,
65 * and that entry is marked as occupied.
66 * Entries can be dequeued from the head of the list, when the device
67 * has marked the entry as consumed.
69 * Returns true on successful queue/dequeue, false on failure.
71 static int fifo_enqueue(struct ilo_hwinfo *hw, char *fifobar, int entry)
73 struct fifo *fifo_q = FIFOBARTOHANDLE(fifobar);
77 spin_lock_irqsave(&hw->fifo_lock, flags);
78 if (!(fifo_q->fifobar[(fifo_q->tail + 1) & fifo_q->imask]
80 fifo_q->fifobar[fifo_q->tail & fifo_q->imask] |=
81 (entry & ENTRY_MASK_NOSTATE) | fifo_q->merge;
85 spin_unlock_irqrestore(&hw->fifo_lock, flags);
90 static int fifo_dequeue(struct ilo_hwinfo *hw, char *fifobar, int *entry)
92 struct fifo *fifo_q = FIFOBARTOHANDLE(fifobar);
97 spin_lock_irqsave(&hw->fifo_lock, flags);
98 c = fifo_q->fifobar[fifo_q->head & fifo_q->imask];
99 if (c & ENTRY_MASK_C) {
101 *entry = c & ENTRY_MASK_NOSTATE;
103 fifo_q->fifobar[fifo_q->head & fifo_q->imask] =
104 (c | ENTRY_MASK) + 1;
108 spin_unlock_irqrestore(&hw->fifo_lock, flags);
113 static int fifo_check_recv(struct ilo_hwinfo *hw, char *fifobar)
115 struct fifo *fifo_q = FIFOBARTOHANDLE(fifobar);
120 spin_lock_irqsave(&hw->fifo_lock, flags);
121 c = fifo_q->fifobar[fifo_q->head & fifo_q->imask];
122 if (c & ENTRY_MASK_C)
124 spin_unlock_irqrestore(&hw->fifo_lock, flags);
129 static int ilo_pkt_enqueue(struct ilo_hwinfo *hw, struct ccb *ccb,
130 int dir, int id, int len)
136 fifobar = ccb->ccb_u1.send_fifobar;
138 fifobar = ccb->ccb_u3.recv_fifobar;
140 entry = mk_entry(id, len);
141 return fifo_enqueue(hw, fifobar, entry);
144 static int ilo_pkt_dequeue(struct ilo_hwinfo *hw, struct ccb *ccb,
145 int dir, int *id, int *len, void **pkt)
147 char *fifobar, *desc;
148 int entry = 0, pkt_id = 0;
152 fifobar = ccb->ccb_u1.send_fifobar;
153 desc = ccb->ccb_u2.send_desc;
155 fifobar = ccb->ccb_u3.recv_fifobar;
156 desc = ccb->ccb_u4.recv_desc;
159 ret = fifo_dequeue(hw, fifobar, &entry);
161 pkt_id = get_entry_id(entry);
165 *len = get_entry_len(entry);
167 *pkt = (void *)(desc + desc_mem_sz(pkt_id));
173 static int ilo_pkt_recv(struct ilo_hwinfo *hw, struct ccb *ccb)
175 char *fifobar = ccb->ccb_u3.recv_fifobar;
177 return fifo_check_recv(hw, fifobar);
180 static inline void doorbell_set(struct ccb *ccb)
182 iowrite8(1, ccb->ccb_u5.db_base);
185 static inline void doorbell_clr(struct ccb *ccb)
187 iowrite8(2, ccb->ccb_u5.db_base);
190 static inline int ctrl_set(int l2sz, int idxmask, int desclim)
192 int active = 0, go = 1;
193 return l2sz << CTRL_BITPOS_L2SZ |
194 idxmask << CTRL_BITPOS_FIFOINDEXMASK |
195 desclim << CTRL_BITPOS_DESCLIMIT |
196 active << CTRL_BITPOS_A |
200 static void ctrl_setup(struct ccb *ccb, int nr_desc, int l2desc_sz)
202 /* for simplicity, use the same parameters for send and recv ctrls */
203 ccb->send_ctrl = ctrl_set(l2desc_sz, nr_desc-1, nr_desc-1);
204 ccb->recv_ctrl = ctrl_set(l2desc_sz, nr_desc-1, nr_desc-1);
207 static inline int fifo_sz(int nr_entry)
209 /* size of a fifo is determined by the number of entries it contains */
210 return nr_entry * sizeof(u64) + FIFOHANDLESIZE;
213 static void fifo_setup(void *base_addr, int nr_entry)
215 struct fifo *fifo_q = base_addr;
218 /* set up an empty fifo */
222 fifo_q->nrents = nr_entry;
223 fifo_q->imask = nr_entry - 1;
224 fifo_q->merge = ENTRY_MASK_O;
226 for (i = 0; i < nr_entry; i++)
227 fifo_q->fifobar[i] = 0;
230 static void ilo_ccb_close(struct pci_dev *pdev, struct ccb_data *data)
232 struct ccb *driver_ccb = &data->driver_ccb;
233 struct ccb __iomem *device_ccb = data->mapped_ccb;
236 /* complicated dance to tell the hw we are stopping */
237 doorbell_clr(driver_ccb);
238 iowrite32(ioread32(&device_ccb->send_ctrl) & ~(1 << CTRL_BITPOS_G),
239 &device_ccb->send_ctrl);
240 iowrite32(ioread32(&device_ccb->recv_ctrl) & ~(1 << CTRL_BITPOS_G),
241 &device_ccb->recv_ctrl);
243 /* give iLO some time to process stop request */
244 for (retries = MAX_WAIT; retries > 0; retries--) {
245 doorbell_set(driver_ccb);
247 if (!(ioread32(&device_ccb->send_ctrl) & (1 << CTRL_BITPOS_A))
249 !(ioread32(&device_ccb->recv_ctrl) & (1 << CTRL_BITPOS_A)))
253 dev_err(&pdev->dev, "Closing, but controller still active\n");
255 /* clear the hw ccb */
256 memset_io(device_ccb, 0, sizeof(struct ccb));
258 /* free resources used to back send/recv queues */
259 dma_free_coherent(&pdev->dev, data->dma_size, data->dma_va,
263 static int ilo_ccb_setup(struct ilo_hwinfo *hw, struct ccb_data *data, int slot)
267 struct ccb *driver_ccb, *ilo_ccb;
269 driver_ccb = &data->driver_ccb;
270 ilo_ccb = &data->ilo_ccb;
272 data->dma_size = 2 * fifo_sz(NR_QENTRY) +
273 2 * desc_mem_sz(NR_QENTRY) +
274 ILO_START_ALIGN + ILO_CACHE_SZ;
276 data->dma_va = dma_alloc_coherent(&hw->ilo_dev->dev, data->dma_size,
277 &data->dma_pa, GFP_ATOMIC);
281 dma_va = (char *)data->dma_va;
282 dma_pa = data->dma_pa;
284 dma_va = (char *)roundup((unsigned long)dma_va, ILO_START_ALIGN);
285 dma_pa = roundup(dma_pa, ILO_START_ALIGN);
288 * Create two ccb's, one with virt addrs, one with phys addrs.
289 * Copy the phys addr ccb to device shared mem.
291 ctrl_setup(driver_ccb, NR_QENTRY, L2_QENTRY_SZ);
292 ctrl_setup(ilo_ccb, NR_QENTRY, L2_QENTRY_SZ);
294 fifo_setup(dma_va, NR_QENTRY);
295 driver_ccb->ccb_u1.send_fifobar = dma_va + FIFOHANDLESIZE;
296 ilo_ccb->ccb_u1.send_fifobar_pa = dma_pa + FIFOHANDLESIZE;
297 dma_va += fifo_sz(NR_QENTRY);
298 dma_pa += fifo_sz(NR_QENTRY);
300 dma_va = (char *)roundup((unsigned long)dma_va, ILO_CACHE_SZ);
301 dma_pa = roundup(dma_pa, ILO_CACHE_SZ);
303 fifo_setup(dma_va, NR_QENTRY);
304 driver_ccb->ccb_u3.recv_fifobar = dma_va + FIFOHANDLESIZE;
305 ilo_ccb->ccb_u3.recv_fifobar_pa = dma_pa + FIFOHANDLESIZE;
306 dma_va += fifo_sz(NR_QENTRY);
307 dma_pa += fifo_sz(NR_QENTRY);
309 driver_ccb->ccb_u2.send_desc = dma_va;
310 ilo_ccb->ccb_u2.send_desc_pa = dma_pa;
311 dma_pa += desc_mem_sz(NR_QENTRY);
312 dma_va += desc_mem_sz(NR_QENTRY);
314 driver_ccb->ccb_u4.recv_desc = dma_va;
315 ilo_ccb->ccb_u4.recv_desc_pa = dma_pa;
317 driver_ccb->channel = slot;
318 ilo_ccb->channel = slot;
320 driver_ccb->ccb_u5.db_base = hw->db_vaddr + (slot << L2_DB_SIZE);
321 ilo_ccb->ccb_u5.db_base = NULL; /* hw ccb's doorbell is not used */
326 static void ilo_ccb_open(struct ilo_hwinfo *hw, struct ccb_data *data, int slot)
329 struct ccb *driver_ccb = &data->driver_ccb;
331 /* copy the ccb with physical addrs to device memory */
332 data->mapped_ccb = (struct ccb __iomem *)
333 (hw->ram_vaddr + (slot * ILOHW_CCB_SZ));
334 memcpy_toio(data->mapped_ccb, &data->ilo_ccb, sizeof(struct ccb));
336 /* put packets on the send and receive queues */
338 for (pkt_id = 0; pkt_id < NR_QENTRY; pkt_id++) {
339 ilo_pkt_enqueue(hw, driver_ccb, SENDQ, pkt_id, pkt_sz);
340 doorbell_set(driver_ccb);
343 pkt_sz = desc_mem_sz(1);
344 for (pkt_id = 0; pkt_id < NR_QENTRY; pkt_id++)
345 ilo_pkt_enqueue(hw, driver_ccb, RECVQ, pkt_id, pkt_sz);
347 /* the ccb is ready to use */
348 doorbell_clr(driver_ccb);
351 static int ilo_ccb_verify(struct ilo_hwinfo *hw, struct ccb_data *data)
354 struct ccb *driver_ccb = &data->driver_ccb;
356 /* make sure iLO is really handling requests */
357 for (i = MAX_WAIT; i > 0; i--) {
358 if (ilo_pkt_dequeue(hw, driver_ccb, SENDQ, &pkt_id, NULL, NULL))
364 dev_err(&hw->ilo_dev->dev, "Open could not dequeue a packet\n");
368 ilo_pkt_enqueue(hw, driver_ccb, SENDQ, pkt_id, 0);
369 doorbell_set(driver_ccb);
373 static inline int is_channel_reset(struct ccb *ccb)
375 /* check for this particular channel needing a reset */
376 return FIFOBARTOHANDLE(ccb->ccb_u1.send_fifobar)->reset;
379 static inline void set_channel_reset(struct ccb *ccb)
381 /* set a flag indicating this channel needs a reset */
382 FIFOBARTOHANDLE(ccb->ccb_u1.send_fifobar)->reset = 1;
385 static inline int get_device_outbound(struct ilo_hwinfo *hw)
387 return ioread32(&hw->mmio_vaddr[DB_OUT]);
390 static inline int is_db_reset(int db_out)
392 return db_out & (1 << DB_RESET);
395 static inline void clear_pending_db(struct ilo_hwinfo *hw, int clr)
397 iowrite32(clr, &hw->mmio_vaddr[DB_OUT]);
400 static inline void clear_device(struct ilo_hwinfo *hw)
402 /* clear the device (reset bits, pending channel entries) */
403 clear_pending_db(hw, -1);
406 static inline void ilo_enable_interrupts(struct ilo_hwinfo *hw)
408 iowrite8(ioread8(&hw->mmio_vaddr[DB_IRQ]) | 1, &hw->mmio_vaddr[DB_IRQ]);
411 static inline void ilo_disable_interrupts(struct ilo_hwinfo *hw)
413 iowrite8(ioread8(&hw->mmio_vaddr[DB_IRQ]) & ~1,
414 &hw->mmio_vaddr[DB_IRQ]);
417 static void ilo_set_reset(struct ilo_hwinfo *hw)
422 * Mapped memory is zeroed on ilo reset, so set a per ccb flag
423 * to indicate that this ccb needs to be closed and reopened.
425 for (slot = 0; slot < max_ccb; slot++) {
426 if (!hw->ccb_alloc[slot])
428 set_channel_reset(&hw->ccb_alloc[slot]->driver_ccb);
432 static ssize_t ilo_read(struct file *fp, char __user *buf,
433 size_t len, loff_t *off)
435 int err, found, cnt, pkt_id, pkt_len;
436 struct ccb_data *data = fp->private_data;
437 struct ccb *driver_ccb = &data->driver_ccb;
438 struct ilo_hwinfo *hw = data->ilo_hw;
441 if (is_channel_reset(driver_ccb)) {
443 * If the device has been reset, applications
444 * need to close and reopen all ccbs.
450 * This function is to be called when data is expected
451 * in the channel, and will return an error if no packet is found
452 * during the loop below. The sleep/retry logic is to allow
453 * applications to call read() immediately post write(),
454 * and give iLO some time to process the sent packet.
458 /* look for a received packet */
459 found = ilo_pkt_dequeue(hw, driver_ccb, RECVQ, &pkt_id,
465 } while (!found && cnt);
470 /* only copy the length of the received packet */
474 err = copy_to_user(buf, pkt, len);
476 /* return the received packet to the queue */
477 ilo_pkt_enqueue(hw, driver_ccb, RECVQ, pkt_id, desc_mem_sz(1));
479 return err ? -EFAULT : len;
482 static ssize_t ilo_write(struct file *fp, const char __user *buf,
483 size_t len, loff_t *off)
485 int err, pkt_id, pkt_len;
486 struct ccb_data *data = fp->private_data;
487 struct ccb *driver_ccb = &data->driver_ccb;
488 struct ilo_hwinfo *hw = data->ilo_hw;
491 if (is_channel_reset(driver_ccb))
494 /* get a packet to send the user command */
495 if (!ilo_pkt_dequeue(hw, driver_ccb, SENDQ, &pkt_id, &pkt_len, &pkt))
498 /* limit the length to the length of the packet */
502 /* on failure, set the len to 0 to return empty packet to the device */
503 err = copy_from_user(pkt, buf, len);
507 /* send the packet */
508 ilo_pkt_enqueue(hw, driver_ccb, SENDQ, pkt_id, len);
509 doorbell_set(driver_ccb);
511 return err ? -EFAULT : len;
514 static __poll_t ilo_poll(struct file *fp, poll_table *wait)
516 struct ccb_data *data = fp->private_data;
517 struct ccb *driver_ccb = &data->driver_ccb;
519 poll_wait(fp, &data->ccb_waitq, wait);
521 if (is_channel_reset(driver_ccb))
523 else if (ilo_pkt_recv(data->ilo_hw, driver_ccb))
524 return EPOLLIN | EPOLLRDNORM;
529 static int ilo_close(struct inode *ip, struct file *fp)
532 struct ccb_data *data;
533 struct ilo_hwinfo *hw;
536 slot = iminor(ip) % max_ccb;
537 hw = container_of(ip->i_cdev, struct ilo_hwinfo, cdev);
539 spin_lock(&hw->open_lock);
541 if (hw->ccb_alloc[slot]->ccb_cnt == 1) {
543 data = fp->private_data;
545 spin_lock_irqsave(&hw->alloc_lock, flags);
546 hw->ccb_alloc[slot] = NULL;
547 spin_unlock_irqrestore(&hw->alloc_lock, flags);
549 ilo_ccb_close(hw->ilo_dev, data);
553 hw->ccb_alloc[slot]->ccb_cnt--;
555 spin_unlock(&hw->open_lock);
560 static int ilo_open(struct inode *ip, struct file *fp)
563 struct ccb_data *data;
564 struct ilo_hwinfo *hw;
567 slot = iminor(ip) % max_ccb;
568 hw = container_of(ip->i_cdev, struct ilo_hwinfo, cdev);
570 /* new ccb allocation */
571 data = kzalloc(sizeof(*data), GFP_KERNEL);
575 spin_lock(&hw->open_lock);
577 /* each fd private_data holds sw/hw view of ccb */
578 if (hw->ccb_alloc[slot] == NULL) {
579 /* create a channel control block for this minor */
580 error = ilo_ccb_setup(hw, data, slot);
587 data->ccb_excl = fp->f_flags & O_EXCL;
589 init_waitqueue_head(&data->ccb_waitq);
591 /* write the ccb to hw */
592 spin_lock_irqsave(&hw->alloc_lock, flags);
593 ilo_ccb_open(hw, data, slot);
594 hw->ccb_alloc[slot] = data;
595 spin_unlock_irqrestore(&hw->alloc_lock, flags);
597 /* make sure the channel is functional */
598 error = ilo_ccb_verify(hw, data);
601 spin_lock_irqsave(&hw->alloc_lock, flags);
602 hw->ccb_alloc[slot] = NULL;
603 spin_unlock_irqrestore(&hw->alloc_lock, flags);
605 ilo_ccb_close(hw->ilo_dev, data);
613 if (fp->f_flags & O_EXCL || hw->ccb_alloc[slot]->ccb_excl) {
615 * The channel exists, and either this open
616 * or a previous open of this channel wants
621 hw->ccb_alloc[slot]->ccb_cnt++;
626 spin_unlock(&hw->open_lock);
629 fp->private_data = hw->ccb_alloc[slot];
634 static const struct file_operations ilo_fops = {
635 .owner = THIS_MODULE,
640 .release = ilo_close,
641 .llseek = noop_llseek,
644 static irqreturn_t ilo_isr(int irq, void *data)
646 struct ilo_hwinfo *hw = data;
649 spin_lock(&hw->alloc_lock);
651 /* check for ccbs which have data */
652 pending = get_device_outbound(hw);
654 spin_unlock(&hw->alloc_lock);
658 if (is_db_reset(pending)) {
659 /* wake up all ccbs if the device was reset */
664 for (i = 0; i < max_ccb; i++) {
665 if (!hw->ccb_alloc[i])
667 if (pending & (1 << i))
668 wake_up_interruptible(&hw->ccb_alloc[i]->ccb_waitq);
671 /* clear the device of the channels that have been handled */
672 clear_pending_db(hw, pending);
674 spin_unlock(&hw->alloc_lock);
679 static void ilo_unmap_device(struct pci_dev *pdev, struct ilo_hwinfo *hw)
681 pci_iounmap(pdev, hw->db_vaddr);
682 pci_iounmap(pdev, hw->ram_vaddr);
683 pci_iounmap(pdev, hw->mmio_vaddr);
686 static int ilo_map_device(struct pci_dev *pdev, struct ilo_hwinfo *hw)
693 /* map the memory mapped i/o registers */
694 hw->mmio_vaddr = pci_iomap(pdev, 1, 0);
695 if (hw->mmio_vaddr == NULL) {
696 dev_err(&pdev->dev, "Error mapping mmio\n");
700 /* map the adapter shared memory region */
701 rc = pci_read_config_byte(pdev, PCI_REVISION_ID, &pci_rev_id);
703 dev_err(&pdev->dev, "Error reading PCI rev id: %d\n", rc);
707 if (pci_rev_id >= PCI_REV_ID_NECHES) {
709 /* Last 8k is reserved for CCBs */
710 off = pci_resource_len(pdev, bar) - 0x2000;
715 hw->ram_vaddr = pci_iomap_range(pdev, bar, off, max_ccb * ILOHW_CCB_SZ);
716 if (hw->ram_vaddr == NULL) {
717 dev_err(&pdev->dev, "Error mapping shared mem\n");
721 /* map the doorbell aperture */
722 hw->db_vaddr = pci_iomap(pdev, 3, max_ccb * ONE_DB_SIZE);
723 if (hw->db_vaddr == NULL) {
724 dev_err(&pdev->dev, "Error mapping doorbell\n");
730 pci_iounmap(pdev, hw->ram_vaddr);
732 pci_iounmap(pdev, hw->mmio_vaddr);
737 static void ilo_remove(struct pci_dev *pdev)
740 struct ilo_hwinfo *ilo_hw = pci_get_drvdata(pdev);
745 clear_device(ilo_hw);
747 minor = MINOR(ilo_hw->cdev.dev);
748 for (i = minor; i < minor + max_ccb; i++)
749 device_destroy(ilo_class, MKDEV(ilo_major, i));
751 cdev_del(&ilo_hw->cdev);
752 ilo_disable_interrupts(ilo_hw);
753 free_irq(pdev->irq, ilo_hw);
754 ilo_unmap_device(pdev, ilo_hw);
755 pci_release_regions(pdev);
757 * pci_disable_device(pdev) used to be here. But this PCI device has
758 * two functions with interrupt lines connected to a single pin. The
759 * other one is a USB host controller. So when we disable the PIN here
760 * e.g. by rmmod hpilo, the controller stops working. It is because
761 * the interrupt link is disabled in ACPI since it is not refcounted
762 * yet. See acpi_pci_link_free_irq called from acpi_pci_irq_disable.
765 ilo_hwdev[(minor / max_ccb)] = 0;
768 static int ilo_probe(struct pci_dev *pdev,
769 const struct pci_device_id *ent)
771 int devnum, minor, start, error = 0;
772 struct ilo_hwinfo *ilo_hw;
774 if (pci_match_id(ilo_blacklist, pdev)) {
775 dev_dbg(&pdev->dev, "Not supported on this device\n");
779 if (max_ccb > MAX_CCB)
781 else if (max_ccb < MIN_CCB)
784 /* find a free range for device files */
785 for (devnum = 0; devnum < MAX_ILO_DEV; devnum++) {
786 if (ilo_hwdev[devnum] == 0) {
787 ilo_hwdev[devnum] = 1;
792 if (devnum == MAX_ILO_DEV) {
793 dev_err(&pdev->dev, "Error finding free device\n");
797 /* track global allocations for this device */
799 ilo_hw = kzalloc(sizeof(*ilo_hw), GFP_KERNEL);
803 ilo_hw->ilo_dev = pdev;
804 spin_lock_init(&ilo_hw->alloc_lock);
805 spin_lock_init(&ilo_hw->fifo_lock);
806 spin_lock_init(&ilo_hw->open_lock);
808 error = pci_enable_device(pdev);
812 pci_set_master(pdev);
814 error = pci_request_regions(pdev, ILO_NAME);
818 error = ilo_map_device(pdev, ilo_hw);
822 pci_set_drvdata(pdev, ilo_hw);
823 clear_device(ilo_hw);
825 error = request_irq(pdev->irq, ilo_isr, IRQF_SHARED, "hpilo", ilo_hw);
829 ilo_enable_interrupts(ilo_hw);
831 cdev_init(&ilo_hw->cdev, &ilo_fops);
832 ilo_hw->cdev.owner = THIS_MODULE;
833 start = devnum * max_ccb;
834 error = cdev_add(&ilo_hw->cdev, MKDEV(ilo_major, start), max_ccb);
836 dev_err(&pdev->dev, "Could not add cdev\n");
840 for (minor = 0 ; minor < max_ccb; minor++) {
842 dev = device_create(ilo_class, &pdev->dev,
843 MKDEV(ilo_major, minor), NULL,
844 "hpilo!d%dccb%d", devnum, minor);
846 dev_err(&pdev->dev, "Could not create files\n");
851 ilo_disable_interrupts(ilo_hw);
852 free_irq(pdev->irq, ilo_hw);
854 ilo_unmap_device(pdev, ilo_hw);
856 pci_release_regions(pdev);
858 /* pci_disable_device(pdev); see comment in ilo_remove */
862 ilo_hwdev[devnum] = 0;
866 static const struct pci_device_id ilo_devices[] = {
867 { PCI_DEVICE(PCI_VENDOR_ID_COMPAQ, 0xB204) },
868 { PCI_DEVICE(PCI_VENDOR_ID_HP, 0x3307) },
871 MODULE_DEVICE_TABLE(pci, ilo_devices);
873 static struct pci_driver ilo_driver = {
875 .id_table = ilo_devices,
877 .remove = ilo_remove,
880 static int __init ilo_init(void)
885 ilo_class = class_create("iLO");
886 if (IS_ERR(ilo_class)) {
887 error = PTR_ERR(ilo_class);
891 error = alloc_chrdev_region(&dev, 0, MAX_OPEN, ILO_NAME);
895 ilo_major = MAJOR(dev);
897 error = pci_register_driver(&ilo_driver);
903 unregister_chrdev_region(dev, MAX_OPEN);
905 class_destroy(ilo_class);
910 static void __exit ilo_exit(void)
912 pci_unregister_driver(&ilo_driver);
913 unregister_chrdev_region(MKDEV(ilo_major, 0), MAX_OPEN);
914 class_destroy(ilo_class);
917 MODULE_VERSION("1.5.0");
918 MODULE_ALIAS(ILO_NAME);
919 MODULE_DESCRIPTION(ILO_NAME);
921 MODULE_LICENSE("GPL v2");
923 module_param(max_ccb, uint, 0444);
924 MODULE_PARM_DESC(max_ccb, "Maximum number of HP iLO channels to attach (8-24)(default=16)");
926 module_init(ilo_init);
927 module_exit(ilo_exit);