@@ -98,6 +98,10 @@ EXPORT_SYMBOL_GPL(zpci_iomap_start);
9898static int __read_mostly aisb_max ;
9999
100100static struct kmem_cache * zdev_irq_cache ;
101+ static struct kmem_cache * zdev_fmb_cache ;
102+
103+ debug_info_t * pci_debug_msg_id ;
104+ debug_info_t * pci_debug_err_id ;
101105
102106static inline int irq_to_msi_nr (unsigned int irq )
103107{
@@ -216,6 +220,7 @@ struct mod_pci_args {
216220 u64 base ;
217221 u64 limit ;
218222 u64 iota ;
223+ u64 fmb_addr ;
219224};
220225
221226static int mod_pci (struct zpci_dev * zdev , int fn , u8 dmaas , struct mod_pci_args * args )
@@ -232,6 +237,7 @@ static int mod_pci(struct zpci_dev *zdev, int fn, u8 dmaas, struct mod_pci_args
232237 fib -> pba = args -> base ;
233238 fib -> pal = args -> limit ;
234239 fib -> iota = args -> iota ;
240+ fib -> fmb_addr = args -> fmb_addr ;
235241
236242 rc = mpcifc_instr (req , fib );
237243 free_page ((unsigned long ) fib );
@@ -242,7 +248,7 @@ static int mod_pci(struct zpci_dev *zdev, int fn, u8 dmaas, struct mod_pci_args
242248int zpci_register_ioat (struct zpci_dev * zdev , u8 dmaas ,
243249 u64 base , u64 limit , u64 iota )
244250{
245- struct mod_pci_args args = { base , limit , iota };
251+ struct mod_pci_args args = { base , limit , iota , 0 };
246252
247253 WARN_ON_ONCE (iota & 0x3fff );
248254 args .iota |= ZPCI_IOTA_RTTO_FLAG ;
@@ -252,19 +258,54 @@ int zpci_register_ioat(struct zpci_dev *zdev, u8 dmaas,
252258/* Modify PCI: Unregister I/O address translation parameters */
253259int zpci_unregister_ioat (struct zpci_dev * zdev , u8 dmaas )
254260{
255- struct mod_pci_args args = { 0 , 0 , 0 };
261+ struct mod_pci_args args = { 0 , 0 , 0 , 0 };
256262
257263 return mod_pci (zdev , ZPCI_MOD_FC_DEREG_IOAT , dmaas , & args );
258264}
259265
260266/* Modify PCI: Unregister adapter interruptions */
261267static int zpci_unregister_airq (struct zpci_dev * zdev )
262268{
263- struct mod_pci_args args = { 0 , 0 , 0 };
269+ struct mod_pci_args args = { 0 , 0 , 0 , 0 };
264270
265271 return mod_pci (zdev , ZPCI_MOD_FC_DEREG_INT , 0 , & args );
266272}
267273
274+ /* Modify PCI: Set PCI function measurement parameters */
275+ int zpci_fmb_enable_device (struct zpci_dev * zdev )
276+ {
277+ struct mod_pci_args args = { 0 , 0 , 0 , 0 };
278+
279+ if (zdev -> fmb )
280+ return - EINVAL ;
281+
282+ zdev -> fmb = kmem_cache_alloc (zdev_fmb_cache , GFP_KERNEL );
283+ if (!zdev -> fmb )
284+ return - ENOMEM ;
285+ memset (zdev -> fmb , 0 , sizeof (* zdev -> fmb ));
286+ WARN_ON ((u64 ) zdev -> fmb & 0xf );
287+
288+ args .fmb_addr = virt_to_phys (zdev -> fmb );
289+ return mod_pci (zdev , ZPCI_MOD_FC_SET_MEASURE , 0 , & args );
290+ }
291+
292+ /* Modify PCI: Disable PCI function measurement */
293+ int zpci_fmb_disable_device (struct zpci_dev * zdev )
294+ {
295+ struct mod_pci_args args = { 0 , 0 , 0 , 0 };
296+ int rc ;
297+
298+ if (!zdev -> fmb )
299+ return - EINVAL ;
300+
301+ /* Function measurement is disabled if fmb address is zero */
302+ rc = mod_pci (zdev , ZPCI_MOD_FC_SET_MEASURE , 0 , & args );
303+
304+ kmem_cache_free (zdev_fmb_cache , zdev -> fmb );
305+ zdev -> fmb = NULL ;
306+ return rc ;
307+ }
308+
268309#define ZPCI_PCIAS_CFGSPC 15
269310
270311static int zpci_cfg_load (struct zpci_dev * zdev , int offset , u32 * val , u8 len )
@@ -633,6 +674,7 @@ static void zpci_remove_device(struct pci_dev *pdev)
633674 dev_info (& pdev -> dev , "Removing device %u\n" , zdev -> domain );
634675 zdev -> state = ZPCI_FN_STATE_CONFIGURED ;
635676 zpci_dma_exit_device (zdev );
677+ zpci_fmb_disable_device (zdev );
636678 zpci_sysfs_remove_device (& pdev -> dev );
637679 zpci_unmap_resources (pdev );
638680 list_del (& zdev -> entry ); /* can be called from init */
@@ -799,6 +841,16 @@ static void zpci_irq_exit(void)
799841 kfree (bucket );
800842}
801843
844+ void zpci_debug_info (struct zpci_dev * zdev , struct seq_file * m )
845+ {
846+ if (!zdev )
847+ return ;
848+
849+ seq_printf (m , "global irq retries: %u\n" , atomic_read (& irq_retries ));
850+ seq_printf (m , "aibv[0]:%016lx aibv[1]:%016lx aisb:%016lx\n" ,
851+ get_imap (0 )-> aibv , get_imap (1 )-> aibv , * bucket -> aisb );
852+ }
853+
802854static struct resource * zpci_alloc_bus_resource (unsigned long start , unsigned long size ,
803855 unsigned long flags , int domain )
804856{
@@ -994,6 +1046,8 @@ int zpci_scan_device(struct zpci_dev *zdev)
9941046 goto out ;
9951047 }
9961048
1049+ zpci_debug_init_device (zdev );
1050+ zpci_fmb_enable_device (zdev );
9971051 zpci_map_resources (zdev );
9981052 pci_bus_add_devices (zdev -> bus );
9991053
@@ -1020,6 +1074,11 @@ static int zpci_mem_init(void)
10201074 if (!zdev_irq_cache )
10211075 goto error_zdev ;
10221076
1077+ zdev_fmb_cache = kmem_cache_create ("PCI_FMB_cache" , sizeof (struct zpci_fmb ),
1078+ 16 , 0 , NULL );
1079+ if (!zdev_fmb_cache )
1080+ goto error_fmb ;
1081+
10231082 /* TODO: use realloc */
10241083 zpci_iomap_start = kzalloc (ZPCI_IOMAP_MAX_ENTRIES * sizeof (* zpci_iomap_start ),
10251084 GFP_KERNEL );
@@ -1028,6 +1087,8 @@ static int zpci_mem_init(void)
10281087 return 0 ;
10291088
10301089error_iomap :
1090+ kmem_cache_destroy (zdev_fmb_cache );
1091+ error_fmb :
10311092 kmem_cache_destroy (zdev_irq_cache );
10321093error_zdev :
10331094 return - ENOMEM ;
@@ -1037,6 +1098,7 @@ static void zpci_mem_exit(void)
10371098{
10381099 kfree (zpci_iomap_start );
10391100 kmem_cache_destroy (zdev_irq_cache );
1101+ kmem_cache_destroy (zdev_fmb_cache );
10401102}
10411103
10421104unsigned int pci_probe = 1 ;
@@ -1066,6 +1128,10 @@ static int __init pci_base_init(void)
10661128 test_facility (69 ), test_facility (70 ),
10671129 test_facility (71 ));
10681130
1131+ rc = zpci_debug_init ();
1132+ if (rc )
1133+ return rc ;
1134+
10691135 rc = zpci_mem_init ();
10701136 if (rc )
10711137 goto out_mem ;
@@ -1098,6 +1164,7 @@ static int __init pci_base_init(void)
10981164out_hash :
10991165 zpci_mem_exit ();
11001166out_mem :
1167+ zpci_debug_exit ();
11011168 return rc ;
11021169}
11031170subsys_initcall (pci_base_init );
0 commit comments