@@ -193,15 +193,12 @@ static int switchtec_ntb_send_msg(struct switchtec_ntb *sndev, int idx,
193193 return 0 ;
194194}
195195
196- static int switchtec_ntb_mw_count (struct ntb_dev * ntb , int pidx )
196+ static int switchtec_ntb_mw_count (struct ntb_dev * ntb )
197197{
198198 struct switchtec_ntb * sndev = ntb_sndev (ntb );
199199 int nr_direct_mw = sndev -> peer_nr_direct_mw ;
200200 int nr_lut_mw = sndev -> peer_nr_lut_mw - 1 ;
201201
202- if (pidx != NTB_DEF_PEER_IDX )
203- return - EINVAL ;
204-
205202 if (!use_lut_mws )
206203 nr_lut_mw = 0 ;
207204
@@ -218,36 +215,95 @@ static int peer_lut_index(struct switchtec_ntb *sndev, int mw_idx)
218215 return mw_idx - sndev -> peer_nr_direct_mw + 1 ;
219216}
220217
221- static int switchtec_ntb_mw_get_align (struct ntb_dev * ntb , int pidx ,
222- int widx , resource_size_t * addr_align ,
223- resource_size_t * size_align ,
224- resource_size_t * size_max )
218+ static int switchtec_ntb_mw_direct_get_range (struct switchtec_ntb * sndev ,
219+ int idx , phys_addr_t * base ,
220+ resource_size_t * size ,
221+ resource_size_t * align ,
222+ resource_size_t * align_size )
225223{
226- struct switchtec_ntb * sndev = ntb_sndev (ntb );
227- int lut ;
228- resource_size_t size ;
224+ int bar = sndev -> direct_mw_to_bar [idx ];
225+ size_t offset = 0 ;
229226
230- if (pidx != NTB_DEF_PEER_IDX )
227+ if (bar < 0 )
231228 return - EINVAL ;
232229
233- lut = widx >= sndev -> peer_nr_direct_mw ;
234- size = ioread64 (& sndev -> peer_shared -> mw_sizes [widx ]);
230+ if (idx == 0 ) {
231+ /*
232+ * This is the direct BAR shared with the LUTs
233+ * which means the actual window will be offset
234+ * by the size of all the LUT entries.
235+ */
235236
236- if (size == 0 )
237- return - EINVAL ;
237+ offset = LUT_SIZE * sndev -> nr_lut_mw ;
238+ }
239+
240+ if (base )
241+ * base = pci_resource_start (sndev -> ntb .pdev , bar ) + offset ;
242+
243+ if (size ) {
244+ * size = pci_resource_len (sndev -> ntb .pdev , bar ) - offset ;
245+ if (offset && * size > offset )
246+ * size = offset ;
247+
248+ if (* size > max_mw_size )
249+ * size = max_mw_size ;
250+ }
251+
252+ if (align )
253+ * align = SZ_4K ;
254+
255+ if (align_size )
256+ * align_size = SZ_4K ;
257+
258+ return 0 ;
259+ }
238260
239- if (addr_align )
240- * addr_align = lut ? size : SZ_4K ;
261+ static int switchtec_ntb_mw_lut_get_range (struct switchtec_ntb * sndev ,
262+ int idx , phys_addr_t * base ,
263+ resource_size_t * size ,
264+ resource_size_t * align ,
265+ resource_size_t * align_size )
266+ {
267+ int bar = sndev -> direct_mw_to_bar [0 ];
268+ int offset ;
241269
242- if (size_align )
243- * size_align = lut ? size : SZ_4K ;
270+ offset = LUT_SIZE * lut_index (sndev , idx );
244271
245- if (size_max )
246- * size_max = size ;
272+ if (base )
273+ * base = pci_resource_start (sndev -> ntb .pdev , bar ) + offset ;
274+
275+ if (size )
276+ * size = LUT_SIZE ;
277+
278+ if (align )
279+ * align = LUT_SIZE ;
280+
281+ if (align_size )
282+ * align_size = LUT_SIZE ;
247283
248284 return 0 ;
249285}
250286
287+ static int switchtec_ntb_mw_get_range (struct ntb_dev * ntb , int idx ,
288+ phys_addr_t * base ,
289+ resource_size_t * size ,
290+ resource_size_t * align ,
291+ resource_size_t * align_size )
292+ {
293+ struct switchtec_ntb * sndev = ntb_sndev (ntb );
294+
295+ if (idx < sndev -> nr_direct_mw )
296+ return switchtec_ntb_mw_direct_get_range (sndev , idx , base ,
297+ size , align ,
298+ align_size );
299+ else if (idx < switchtec_ntb_mw_count (ntb ))
300+ return switchtec_ntb_mw_lut_get_range (sndev , idx , base ,
301+ size , align ,
302+ align_size );
303+ else
304+ return - EINVAL ;
305+ }
306+
251307static void switchtec_ntb_mw_clr_direct (struct switchtec_ntb * sndev , int idx )
252308{
253309 struct ntb_ctrl_regs __iomem * ctl = sndev -> mmio_peer_ctrl ;
@@ -294,7 +350,7 @@ static void switchtec_ntb_mw_set_lut(struct switchtec_ntb *sndev, int idx,
294350 & ctl -> lut_entry [peer_lut_index (sndev , idx )]);
295351}
296352
297- static int switchtec_ntb_mw_set_trans (struct ntb_dev * ntb , int pidx , int widx ,
353+ static int switchtec_ntb_mw_set_trans (struct ntb_dev * ntb , int idx ,
298354 dma_addr_t addr , resource_size_t size )
299355{
300356 struct switchtec_ntb * sndev = ntb_sndev (ntb );
@@ -303,13 +359,9 @@ static int switchtec_ntb_mw_set_trans(struct ntb_dev *ntb, int pidx, int widx,
303359 int nr_direct_mw = sndev -> peer_nr_direct_mw ;
304360 int rc ;
305361
306- if (pidx != NTB_DEF_PEER_IDX )
307- return - EINVAL ;
308-
309- dev_dbg (& sndev -> stdev -> dev , "MW %d: part %d addr %pad size %pap" ,
310- widx , pidx , & addr , & size );
362+ dev_dbg (& sndev -> stdev -> dev , "MW %d: %016llx %016llx" , idx , addr , size );
311363
312- if (widx >= switchtec_ntb_mw_count (ntb , pidx ))
364+ if (idx >= switchtec_ntb_mw_count (ntb ))
313365 return - EINVAL ;
314366
315367 if (xlate_pos < 12 )
@@ -321,15 +373,15 @@ static int switchtec_ntb_mw_set_trans(struct ntb_dev *ntb, int pidx, int widx,
321373 return rc ;
322374
323375 if (addr == 0 || size == 0 ) {
324- if (widx < nr_direct_mw )
325- switchtec_ntb_mw_clr_direct (sndev , widx );
376+ if (idx < nr_direct_mw )
377+ switchtec_ntb_mw_clr_direct (sndev , idx );
326378 else
327- switchtec_ntb_mw_clr_lut (sndev , widx );
379+ switchtec_ntb_mw_clr_lut (sndev , idx );
328380 } else {
329- if (widx < nr_direct_mw )
330- switchtec_ntb_mw_set_direct (sndev , widx , addr , size );
381+ if (idx < nr_direct_mw )
382+ switchtec_ntb_mw_set_direct (sndev , idx , addr , size );
331383 else
332- switchtec_ntb_mw_set_lut (sndev , widx , addr , size );
384+ switchtec_ntb_mw_set_lut (sndev , idx , addr , size );
333385 }
334386
335387 rc = switchtec_ntb_part_op (sndev , ctl , NTB_CTRL_PART_OP_CFG ,
@@ -338,12 +390,12 @@ static int switchtec_ntb_mw_set_trans(struct ntb_dev *ntb, int pidx, int widx,
338390 if (rc == - EIO ) {
339391 dev_err (& sndev -> stdev -> dev ,
340392 "Hardware reported an error configuring mw %d: %08x" ,
341- widx , ioread32 (& ctl -> bar_error ));
393+ idx , ioread32 (& ctl -> bar_error ));
342394
343- if (widx < nr_direct_mw )
344- switchtec_ntb_mw_clr_direct (sndev , widx );
395+ if (idx < nr_direct_mw )
396+ switchtec_ntb_mw_clr_direct (sndev , idx );
345397 else
346- switchtec_ntb_mw_clr_lut (sndev , widx );
398+ switchtec_ntb_mw_clr_lut (sndev , idx );
347399
348400 switchtec_ntb_part_op (sndev , ctl , NTB_CTRL_PART_OP_CFG ,
349401 NTB_CTRL_PART_STATUS_NORMAL );
@@ -352,80 +404,6 @@ static int switchtec_ntb_mw_set_trans(struct ntb_dev *ntb, int pidx, int widx,
352404 return rc ;
353405}
354406
355- static int switchtec_ntb_peer_mw_count (struct ntb_dev * ntb )
356- {
357- struct switchtec_ntb * sndev = ntb_sndev (ntb );
358-
359- return sndev -> nr_direct_mw + (use_lut_mws ? sndev -> nr_lut_mw - 1 : 0 );
360- }
361-
362- static int switchtec_ntb_direct_get_addr (struct switchtec_ntb * sndev ,
363- int idx , phys_addr_t * base ,
364- resource_size_t * size )
365- {
366- int bar = sndev -> direct_mw_to_bar [idx ];
367- size_t offset = 0 ;
368-
369- if (bar < 0 )
370- return - EINVAL ;
371-
372- if (idx == 0 ) {
373- /*
374- * This is the direct BAR shared with the LUTs
375- * which means the actual window will be offset
376- * by the size of all the LUT entries.
377- */
378-
379- offset = LUT_SIZE * sndev -> nr_lut_mw ;
380- }
381-
382- if (base )
383- * base = pci_resource_start (sndev -> ntb .pdev , bar ) + offset ;
384-
385- if (size ) {
386- * size = pci_resource_len (sndev -> ntb .pdev , bar ) - offset ;
387- if (offset && * size > offset )
388- * size = offset ;
389-
390- if (* size > max_mw_size )
391- * size = max_mw_size ;
392- }
393-
394- return 0 ;
395- }
396-
397- static int switchtec_ntb_lut_get_addr (struct switchtec_ntb * sndev ,
398- int idx , phys_addr_t * base ,
399- resource_size_t * size )
400- {
401- int bar = sndev -> direct_mw_to_bar [0 ];
402- int offset ;
403-
404- offset = LUT_SIZE * lut_index (sndev , idx );
405-
406- if (base )
407- * base = pci_resource_start (sndev -> ntb .pdev , bar ) + offset ;
408-
409- if (size )
410- * size = LUT_SIZE ;
411-
412- return 0 ;
413- }
414-
415- static int switchtec_ntb_peer_mw_get_addr (struct ntb_dev * ntb , int idx ,
416- phys_addr_t * base ,
417- resource_size_t * size )
418- {
419- struct switchtec_ntb * sndev = ntb_sndev (ntb );
420-
421- if (idx < sndev -> nr_direct_mw )
422- return switchtec_ntb_direct_get_addr (sndev , idx , base , size );
423- else if (idx < switchtec_ntb_peer_mw_count (ntb ))
424- return switchtec_ntb_lut_get_addr (sndev , idx , base , size );
425- else
426- return - EINVAL ;
427- }
428-
429407static void switchtec_ntb_part_link_speed (struct switchtec_ntb * sndev ,
430408 int partition ,
431409 enum ntb_speed * speed ,
@@ -503,7 +481,7 @@ static void switchtec_ntb_link_notification(struct switchtec_dev *stdev)
503481 switchtec_ntb_check_link (sndev );
504482}
505483
506- static u64 switchtec_ntb_link_is_up (struct ntb_dev * ntb ,
484+ static int switchtec_ntb_link_is_up (struct ntb_dev * ntb ,
507485 enum ntb_speed * speed ,
508486 enum ntb_width * width )
509487{
@@ -696,52 +674,41 @@ static int switchtec_ntb_spad_write(struct ntb_dev *ntb, int idx, u32 val)
696674 return 0 ;
697675}
698676
699- static u32 switchtec_ntb_peer_spad_read (struct ntb_dev * ntb , int pidx ,
700- int sidx )
677+ static u32 switchtec_ntb_peer_spad_read (struct ntb_dev * ntb , int idx )
701678{
702679 struct switchtec_ntb * sndev = ntb_sndev (ntb );
703680
704- if (pidx != NTB_DEF_PEER_IDX )
705- return - EINVAL ;
706-
707- if (sidx < 0 || sidx >= ARRAY_SIZE (sndev -> peer_shared -> spad ))
681+ if (idx < 0 || idx >= ARRAY_SIZE (sndev -> peer_shared -> spad ))
708682 return 0 ;
709683
710684 if (!sndev -> peer_shared )
711685 return 0 ;
712686
713- return ioread32 (& sndev -> peer_shared -> spad [sidx ]);
687+ return ioread32 (& sndev -> peer_shared -> spad [idx ]);
714688}
715689
716- static int switchtec_ntb_peer_spad_write (struct ntb_dev * ntb , int pidx ,
717- int sidx , u32 val )
690+ static int switchtec_ntb_peer_spad_write (struct ntb_dev * ntb , int idx , u32 val )
718691{
719692 struct switchtec_ntb * sndev = ntb_sndev (ntb );
720693
721- if (pidx != NTB_DEF_PEER_IDX )
722- return - EINVAL ;
723-
724- if (sidx < 0 || sidx >= ARRAY_SIZE (sndev -> peer_shared -> spad ))
694+ if (idx < 0 || idx >= ARRAY_SIZE (sndev -> peer_shared -> spad ))
725695 return - EINVAL ;
726696
727697 if (!sndev -> peer_shared )
728698 return - EIO ;
729699
730- iowrite32 (val , & sndev -> peer_shared -> spad [sidx ]);
700+ iowrite32 (val , & sndev -> peer_shared -> spad [idx ]);
731701
732702 return 0 ;
733703}
734704
735- static int switchtec_ntb_peer_spad_addr (struct ntb_dev * ntb , int pidx ,
736- int sidx , phys_addr_t * spad_addr )
705+ static int switchtec_ntb_peer_spad_addr (struct ntb_dev * ntb , int idx ,
706+ phys_addr_t * spad_addr )
737707{
738708 struct switchtec_ntb * sndev = ntb_sndev (ntb );
739709 unsigned long offset ;
740710
741- if (pidx != NTB_DEF_PEER_IDX )
742- return - EINVAL ;
743-
744- offset = (unsigned long )& sndev -> peer_shared -> spad [sidx ] -
711+ offset = (unsigned long )& sndev -> peer_shared -> spad [idx ] -
745712 (unsigned long )sndev -> stdev -> mmio ;
746713
747714 if (spad_addr )
@@ -752,10 +719,8 @@ static int switchtec_ntb_peer_spad_addr(struct ntb_dev *ntb, int pidx,
752719
753720static const struct ntb_dev_ops switchtec_ntb_ops = {
754721 .mw_count = switchtec_ntb_mw_count ,
755- .mw_get_align = switchtec_ntb_mw_get_align ,
722+ .mw_get_range = switchtec_ntb_mw_get_range ,
756723 .mw_set_trans = switchtec_ntb_mw_set_trans ,
757- .peer_mw_count = switchtec_ntb_peer_mw_count ,
758- .peer_mw_get_addr = switchtec_ntb_peer_mw_get_addr ,
759724 .link_is_up = switchtec_ntb_link_is_up ,
760725 .link_enable = switchtec_ntb_link_enable ,
761726 .link_disable = switchtec_ntb_link_disable ,
0 commit comments