Skip to content

Commit 66d5e51

Browse files
David Altobelligregkh
authored andcommitted
hpilo: staging for interrupt handling
Refactor some hpilo routines in order to allow for locking changes in interrupt handling. Should not be functionally different. Signed-off-by: David Altobelli <david.altobelli@hp.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent daa4122 commit 66d5e51

1 file changed

Lines changed: 73 additions & 47 deletions

File tree

‎drivers/misc/hpilo.c‎

Lines changed: 73 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ static inline void doorbell_clr(struct ccb *ccb)
151151
{
152152
iowrite8(2, ccb->ccb_u5.db_base);
153153
}
154+
154155
static inline int ctrl_set(int l2sz, int idxmask, int desclim)
155156
{
156157
int active = 0, go = 1;
@@ -160,6 +161,7 @@ static inline int ctrl_set(int l2sz, int idxmask, int desclim)
160161
active << CTRL_BITPOS_A |
161162
go << CTRL_BITPOS_G;
162163
}
164+
163165
static void ctrl_setup(struct ccb *ccb, int nr_desc, int l2desc_sz)
164166
{
165167
/* for simplicity, use the same parameters for send and recv ctrls */
@@ -192,13 +194,10 @@ static void fifo_setup(void *base_addr, int nr_entry)
192194

193195
static void ilo_ccb_close(struct pci_dev *pdev, struct ccb_data *data)
194196
{
195-
struct ccb *driver_ccb;
196-
struct ccb __iomem *device_ccb;
197+
struct ccb *driver_ccb = &data->driver_ccb;
198+
struct ccb __iomem *device_ccb = data->mapped_ccb;
197199
int retries;
198200

199-
driver_ccb = &data->driver_ccb;
200-
device_ccb = data->mapped_ccb;
201-
202201
/* complicated dance to tell the hw we are stopping */
203202
doorbell_clr(driver_ccb);
204203
iowrite32(ioread32(&device_ccb->send_ctrl) & ~(1 << CTRL_BITPOS_G),
@@ -225,26 +224,22 @@ static void ilo_ccb_close(struct pci_dev *pdev, struct ccb_data *data)
225224
pci_free_consistent(pdev, data->dma_size, data->dma_va, data->dma_pa);
226225
}
227226

228-
static int ilo_ccb_open(struct ilo_hwinfo *hw, struct ccb_data *data, int slot)
227+
static int ilo_ccb_setup(struct ilo_hwinfo *hw, struct ccb_data *data, int slot)
229228
{
230229
char *dma_va, *dma_pa;
231-
int pkt_id, pkt_sz, i, error;
232230
struct ccb *driver_ccb, *ilo_ccb;
233-
struct pci_dev *pdev;
234231

235232
driver_ccb = &data->driver_ccb;
236233
ilo_ccb = &data->ilo_ccb;
237-
pdev = hw->ilo_dev;
238234

239235
data->dma_size = 2 * fifo_sz(NR_QENTRY) +
240236
2 * desc_mem_sz(NR_QENTRY) +
241237
ILO_START_ALIGN + ILO_CACHE_SZ;
242238

243-
error = -ENOMEM;
244-
data->dma_va = pci_alloc_consistent(pdev, data->dma_size,
239+
data->dma_va = pci_alloc_consistent(hw->ilo_dev, data->dma_size,
245240
&data->dma_pa);
246241
if (!data->dma_va)
247-
goto out;
242+
return -ENOMEM;
248243

249244
dma_va = (char *)data->dma_va;
250245
dma_pa = (char *)data->dma_pa;
@@ -290,10 +285,18 @@ static int ilo_ccb_open(struct ilo_hwinfo *hw, struct ccb_data *data, int slot)
290285
driver_ccb->ccb_u5.db_base = hw->db_vaddr + (slot << L2_DB_SIZE);
291286
ilo_ccb->ccb_u5.db_base = NULL; /* hw ccb's doorbell is not used */
292287

288+
return 0;
289+
}
290+
291+
static void ilo_ccb_open(struct ilo_hwinfo *hw, struct ccb_data *data, int slot)
292+
{
293+
int pkt_id, pkt_sz;
294+
struct ccb *driver_ccb = &data->driver_ccb;
295+
293296
/* copy the ccb with physical addrs to device memory */
294297
data->mapped_ccb = (struct ccb __iomem *)
295298
(hw->ram_vaddr + (slot * ILOHW_CCB_SZ));
296-
memcpy_toio(data->mapped_ccb, ilo_ccb, sizeof(struct ccb));
299+
memcpy_toio(data->mapped_ccb, &data->ilo_ccb, sizeof(struct ccb));
297300

298301
/* put packets on the send and receive queues */
299302
pkt_sz = 0;
@@ -306,7 +309,14 @@ static int ilo_ccb_open(struct ilo_hwinfo *hw, struct ccb_data *data, int slot)
306309
for (pkt_id = 0; pkt_id < NR_QENTRY; pkt_id++)
307310
ilo_pkt_enqueue(hw, driver_ccb, RECVQ, pkt_id, pkt_sz);
308311

312+
/* the ccb is ready to use */
309313
doorbell_clr(driver_ccb);
314+
}
315+
316+
static int ilo_ccb_verify(struct ilo_hwinfo *hw, struct ccb_data *data)
317+
{
318+
int pkt_id, i;
319+
struct ccb *driver_ccb = &data->driver_ccb;
310320

311321
/* make sure iLO is really handling requests */
312322
for (i = MAX_WAIT; i > 0; i--) {
@@ -315,20 +325,14 @@ static int ilo_ccb_open(struct ilo_hwinfo *hw, struct ccb_data *data, int slot)
315325
udelay(WAIT_TIME);
316326
}
317327

318-
if (i) {
319-
ilo_pkt_enqueue(hw, driver_ccb, SENDQ, pkt_id, 0);
320-
doorbell_set(driver_ccb);
321-
} else {
322-
dev_err(&pdev->dev, "Open could not dequeue a packet\n");
323-
error = -EBUSY;
324-
goto free;
328+
if (i == 0) {
329+
dev_err(&hw->ilo_dev->dev, "Open could not dequeue a packet\n");
330+
return -EBUSY;
325331
}
326332

333+
ilo_pkt_enqueue(hw, driver_ccb, SENDQ, pkt_id, 0);
334+
doorbell_set(driver_ccb);
327335
return 0;
328-
free:
329-
ilo_ccb_close(pdev, data);
330-
out:
331-
return error;
332336
}
333337

334338
static inline int is_channel_reset(struct ccb *ccb)
@@ -343,16 +347,31 @@ static inline void set_channel_reset(struct ccb *ccb)
343347
FIFOBARTOHANDLE(ccb->ccb_u1.send_fifobar)->reset = 1;
344348
}
345349

350+
static inline int get_device_outbound(struct ilo_hwinfo *hw)
351+
{
352+
return ioread32(&hw->mmio_vaddr[DB_OUT]);
353+
}
354+
355+
static inline int is_db_reset(int db_out)
356+
{
357+
return db_out & (1 << DB_RESET);
358+
}
359+
346360
static inline int is_device_reset(struct ilo_hwinfo *hw)
347361
{
348362
/* check for global reset condition */
349-
return ioread32(&hw->mmio_vaddr[DB_OUT]) & (1 << DB_RESET);
363+
return is_db_reset(get_device_outbound(hw));
364+
}
365+
366+
static inline void clear_pending_db(struct ilo_hwinfo *hw, int clr)
367+
{
368+
iowrite32(clr, &hw->mmio_vaddr[DB_OUT]);
350369
}
351370

352371
static inline void clear_device(struct ilo_hwinfo *hw)
353372
{
354373
/* clear the device (reset bits, pending channel entries) */
355-
iowrite32(-1, &hw->mmio_vaddr[DB_OUT]);
374+
clear_pending_db(hw, -1);
356375
}
357376

358377
static void ilo_locked_reset(struct ilo_hwinfo *hw)
@@ -387,15 +406,11 @@ static ssize_t ilo_read(struct file *fp, char __user *buf,
387406
size_t len, loff_t *off)
388407
{
389408
int err, found, cnt, pkt_id, pkt_len;
390-
struct ccb_data *data;
391-
struct ccb *driver_ccb;
392-
struct ilo_hwinfo *hw;
409+
struct ccb_data *data = fp->private_data;
410+
struct ccb *driver_ccb = &data->driver_ccb;
411+
struct ilo_hwinfo *hw = data->ilo_hw;
393412
void *pkt;
394413

395-
data = fp->private_data;
396-
driver_ccb = &data->driver_ccb;
397-
hw = data->ilo_hw;
398-
399414
if (is_device_reset(hw) || is_channel_reset(driver_ccb)) {
400415
/*
401416
* If the device has been reset, applications
@@ -442,15 +457,11 @@ static ssize_t ilo_write(struct file *fp, const char __user *buf,
442457
size_t len, loff_t *off)
443458
{
444459
int err, pkt_id, pkt_len;
445-
struct ccb_data *data;
446-
struct ccb *driver_ccb;
447-
struct ilo_hwinfo *hw;
460+
struct ccb_data *data = fp->private_data;
461+
struct ccb *driver_ccb = &data->driver_ccb;
462+
struct ilo_hwinfo *hw = data->ilo_hw;
448463
void *pkt;
449464

450-
data = fp->private_data;
451-
driver_ccb = &data->driver_ccb;
452-
hw = data->ilo_hw;
453-
454465
if (is_device_reset(hw) || is_channel_reset(driver_ccb)) {
455466
/*
456467
* If the device has been reset, applications
@@ -532,14 +543,28 @@ static int ilo_open(struct inode *ip, struct file *fp)
532543
/* each fd private_data holds sw/hw view of ccb */
533544
if (hw->ccb_alloc[slot] == NULL) {
534545
/* create a channel control block for this minor */
535-
error = ilo_ccb_open(hw, data, slot);
536-
if (!error) {
537-
hw->ccb_alloc[slot] = data;
538-
hw->ccb_alloc[slot]->ccb_cnt = 1;
539-
hw->ccb_alloc[slot]->ccb_excl = fp->f_flags & O_EXCL;
540-
hw->ccb_alloc[slot]->ilo_hw = hw;
541-
} else
546+
error = ilo_ccb_setup(hw, data, slot);
547+
if (error) {
548+
kfree(data);
549+
goto out;
550+
}
551+
552+
/* write the ccb to hw */
553+
ilo_ccb_open(hw, data, slot);
554+
555+
/* make sure the channel is functional */
556+
error = ilo_ccb_verify(hw, data);
557+
if (error) {
558+
ilo_ccb_close(hw->ilo_dev, data);
542559
kfree(data);
560+
goto out;
561+
}
562+
563+
data->ccb_cnt = 1;
564+
data->ccb_excl = fp->f_flags & O_EXCL;
565+
data->ilo_hw = hw;
566+
hw->ccb_alloc[slot] = data;
567+
543568
} else {
544569
kfree(data);
545570
if (fp->f_flags & O_EXCL || hw->ccb_alloc[slot]->ccb_excl) {
@@ -554,6 +579,7 @@ static int ilo_open(struct inode *ip, struct file *fp)
554579
error = 0;
555580
}
556581
}
582+
out:
557583
spin_unlock(&hw->alloc_lock);
558584

559585
if (!error)

0 commit comments

Comments
 (0)