Browse Source

Start constructing a generic poll() routine.

tags/v0.9.3
Michael Brown 17 years ago
parent
commit
da23e8d287
2 changed files with 98 additions and 35 deletions
  1. 96
    35
      src/drivers/net/mlx_ipoib/mt25218.c
  2. 2
    0
      src/drivers/net/mlx_ipoib/mt25218_imp.c

+ 96
- 35
src/drivers/net/mlx_ipoib/mt25218.c View File

52
 	return 0;
52
 	return 0;
53
 }
53
 }
54
 
54
 
55
+#if 0
55
 /**************************************************************************
56
 /**************************************************************************
56
 IRQ - handle interrupts
57
 IRQ - handle interrupts
57
 ***************************************************************************/
58
 ***************************************************************************/
153
 			eprintf("tranmit error");
154
 			eprintf("tranmit error");
154
 	}
155
 	}
155
 }
156
 }
157
+#endif
156
 
158
 
157
 /**
159
 /**
158
  * Open network device
160
  * Open network device
161
  * @ret rc		Return status code
163
  * @ret rc		Return status code
162
  */
164
  */
163
 static int mlx_open ( struct net_device *netdev ) {
165
 static int mlx_open ( struct net_device *netdev ) {
166
+
167
+	( void ) netdev;
168
+
164
 	return 0;
169
 	return 0;
165
 }
170
 }
166
 
171
 
170
  * @v netdev		Network device
175
  * @v netdev		Network device
171
  */
176
  */
172
 static void mlx_close ( struct net_device *netdev ) {
177
 static void mlx_close ( struct net_device *netdev ) {
178
+
179
+	( void ) netdev;
180
+
173
 }
181
 }
174
 
182
 
175
 #warning "Broadcast address?"
183
 #warning "Broadcast address?"
187
 			  struct io_buffer *iobuf ) {
195
 			  struct io_buffer *iobuf ) {
188
 	struct ibhdr *ibhdr = iobuf->data;
196
 	struct ibhdr *ibhdr = iobuf->data;
189
 
197
 
198
+	( void ) netdev;
199
+
190
 	iob_pull ( iobuf, sizeof ( *ibhdr ) );	
200
 	iob_pull ( iobuf, sizeof ( *ibhdr ) );	
191
 
201
 
192
 	if ( memcmp ( ibhdr->peer, ib_broadcast, IB_ALEN ) == 0 ) {
202
 	if ( memcmp ( ibhdr->peer, ib_broadcast, IB_ALEN ) == 0 ) {
202
 }
212
 }
203
 
213
 
204
 /**
214
 /**
205
- * Poll for completed and received packets
215
+ * Handle TX completion
206
  *
216
  *
207
  * @v netdev		Network device
217
  * @v netdev		Network device
218
+ * @v cqe		Completion queue entry
208
  */
219
  */
209
-static void mlx_poll ( struct net_device *netdev ) {
210
-	struct ib_cqe_st ib_cqe;
211
-	uint8_t num_cqes;
220
+static void mlx_tx_complete ( struct net_device *netdev,
221
+			      struct ib_cqe_st *cqe ) {
222
+	netdev_tx_complete_next_err ( netdev,
223
+				      ( cqe->is_error ? -EIO : 0 ) );
224
+}
225
+
226
+/**
227
+ * Handle RX completion
228
+ *
229
+ * @v netdev		Network device
230
+ * @v cqe		Completion queue entry
231
+ */
232
+static void mlx_rx_complete ( struct net_device *netdev,
233
+			      struct ib_cqe_st *cqe ) {
212
 	unsigned int len;
234
 	unsigned int len;
213
 	struct io_buffer *iobuf;
235
 	struct io_buffer *iobuf;
214
 	void *buf;
236
 	void *buf;
215
-	int rc;
216
-
217
-	if ( ( rc = poll_error_buf() ) != 0 ) {
218
-		DBG ( "poll_error_buf() failed: %s\n", strerror ( rc ) );
219
-		return;
220
-	}
221
 
237
 
222
-	if ( ( rc = drain_eq() ) != 0 ) {
223
-		DBG ( "drain_eq() failed: %s\n", strerror ( rc ) );
238
+	/* Check for errors */
239
+	if ( cqe->is_error ) {
240
+		netdev_rx_err ( netdev, NULL, -EIO );
224
 		return;
241
 		return;
225
 	}
242
 	}
226
 
243
 
227
-	if ( ( rc = ib_poll_cq ( ipoib_data.rcv_cqh, &ib_cqe,
228
-				 &num_cqes ) ) != 0 ) {
229
-		DBG ( "ib_poll_cq() failed: %s\n", strerror ( rc ) );
230
-		return;
231
-	}
232
-
233
-	if ( ! num_cqes )
234
-		return;
235
-
236
-	if ( ib_cqe.is_error ) {
237
-		DBG ( "cqe error\n" );
238
-		free_wqe ( ib_cqe.wqe );
239
-		return;
240
-	}
241
-
242
-	len = ib_cqe.count;
244
+	/* Allocate I/O buffer */
245
+	len = cqe->count;
243
 	iobuf = alloc_iob ( len );
246
 	iobuf = alloc_iob ( len );
244
 	if ( ! iobuf ) {
247
 	if ( ! iobuf ) {
245
-		DBG ( "out of memory\n" );
246
-		free_wqe ( ib_cqe.wqe );
248
+		netdev_rx_err ( netdev, NULL, -ENOMEM );
247
 		return;
249
 		return;
248
 	}
250
 	}
249
-	buf = get_rcv_wqe_buf(ib_cqe.wqe, 1);
251
+	buf = get_rcv_wqe_buf ( cqe->wqe, 1 );
250
 	memcpy ( iob_put ( iobuf, len ), buf, len );
252
 	memcpy ( iob_put ( iobuf, len ), buf, len );
251
 	//	DBG ( "Received packet header:\n" );
253
 	//	DBG ( "Received packet header:\n" );
252
 	//	struct recv_wqe_st *rcv_wqe = ib_cqe.wqe;
254
 	//	struct recv_wqe_st *rcv_wqe = ib_cqe.wqe;
253
 	//	DBG_HD ( get_rcv_wqe_buf(ib_cqe.wqe, 0),
255
 	//	DBG_HD ( get_rcv_wqe_buf(ib_cqe.wqe, 0),
254
 	//		 be32_to_cpu(rcv_wqe->mpointer[0].byte_count) );
256
 	//		 be32_to_cpu(rcv_wqe->mpointer[0].byte_count) );
255
-		 
256
 	//	DBG ( "Received packet:\n" );
257
 	//	DBG ( "Received packet:\n" );
257
 	//	DBG_HD ( iobuf->data, iob_len ( iobuf ) );
258
 	//	DBG_HD ( iobuf->data, iob_len ( iobuf ) );
258
-
259
 	netdev_rx ( netdev, iobuf );
259
 	netdev_rx ( netdev, iobuf );
260
+}
260
 
261
 
261
-	free_wqe ( ib_cqe.wqe );
262
+/**
263
+ * Poll completion queue
264
+ *
265
+ * @v netdev		Network device
266
+ * @v cq		Completion queue
267
+ */
268
+static void mlx_poll_cq ( struct net_device *netdev, cq_t cq ) {
269
+	struct mlx_nic *mlx = netdev->priv;
270
+	struct ib_cqe_st cqe;
271
+	uint8_t num_cqes;
272
+
273
+	while ( 1 ) {
274
+		/* Poll for single completion queue entry */
275
+		ib_poll_cq ( cq, &cqe, &num_cqes );
276
+
277
+		/* Return if no entries in the queue */
278
+		if ( ! num_cqes )
279
+			return;
280
+
281
+		DBGC ( mlx, "MLX %p cpl in %p: err %x send %x "
282
+		       "wqe %p count %lx\n", mlx, cq, cqe.is_error,
283
+		       cqe.is_send, cqe.wqe, cqe.count );
284
+
285
+		/* Handle TX/RX completion */
286
+		if ( cqe.is_send ) {
287
+			mlx_tx_complete ( netdev, &cqe );
288
+		} else {
289
+			mlx_rx_complete ( netdev, &cqe );
290
+		}
291
+		
292
+		/* Free associated work queue entry */
293
+		free_wqe ( cqe.wqe );
294
+	}
295
+}
296
+
297
+/**
298
+ * Poll for completed and received packets
299
+ *
300
+ * @v netdev		Network device
301
+ */
302
+static void mlx_poll ( struct net_device *netdev ) {
303
+	int rc;
304
+
305
+	if ( ( rc = poll_error_buf() ) != 0 ) {
306
+		DBG ( "poll_error_buf() failed: %s\n", strerror ( rc ) );
307
+		return;
308
+	}
309
+
310
+	if ( ( rc = drain_eq() ) != 0 ) {
311
+		DBG ( "drain_eq() failed: %s\n", strerror ( rc ) );
312
+		return;
313
+	}
314
+
315
+	mlx_poll_cq ( netdev, ipoib_data.rcv_cqh );
262
 }
316
 }
263
 
317
 
264
 /**
318
 /**
268
  * @v enable		Interrupts should be enabled
322
  * @v enable		Interrupts should be enabled
269
  */
323
  */
270
 static void mlx_irq ( struct net_device *netdev, int enable ) {
324
 static void mlx_irq ( struct net_device *netdev, int enable ) {
325
+
326
+	( void ) netdev;
327
+	( void ) enable;
328
+
271
 }
329
 }
272
 
330
 
273
 static struct net_device_operations mlx_operations = {
331
 static struct net_device_operations mlx_operations = {
278
 	.irq		= mlx_irq,
336
 	.irq		= mlx_irq,
279
 };
337
 };
280
 
338
 
339
+#if 0
281
 /**************************************************************************
340
 /**************************************************************************
282
 DISABLE - Turn off ethernet interface
341
 DISABLE - Turn off ethernet interface
283
 ***************************************************************************/
342
 ***************************************************************************/
297
 		disable_imp();
356
 		disable_imp();
298
 	}
357
 	}
299
 }
358
 }
359
+#endif
300
 
360
 
301
 /**
361
 /**
302
  * Remove PCI device
362
  * Remove PCI device
305
  */
365
  */
306
 static void mlx_remove ( struct pci_device *pci ) {
366
 static void mlx_remove ( struct pci_device *pci ) {
307
 	struct net_device *netdev = pci_get_drvdata ( pci );
367
 	struct net_device *netdev = pci_get_drvdata ( pci );
308
-	struct mlx_nic *mlx = netdev->priv;
309
 
368
 
310
 	unregister_netdev ( netdev );
369
 	unregister_netdev ( netdev );
311
 	ipoib_close(0);
370
 	ipoib_close(0);
313
 	netdev_put ( netdev );
372
 	netdev_put ( netdev );
314
 }
373
 }
315
 
374
 
375
+#if 0
316
 static struct nic_operations mt25218_operations = {
376
 static struct nic_operations mt25218_operations = {
317
 	.connect	= dummy_connect,
377
 	.connect	= dummy_connect,
318
 	.poll		= mt25218_poll,
378
 	.poll		= mt25218_poll,
380
 	/* else */
440
 	/* else */
381
 	return 0;
441
 	return 0;
382
 }
442
 }
443
+#endif
383
 
444
 
384
 /**
445
 /**
385
  * Probe PCI device
446
  * Probe PCI device

+ 2
- 0
src/drivers/net/mlx_ipoib/mt25218_imp.c View File

45
 #include "ib_driver.c"
45
 #include "ib_driver.c"
46
 #include "ipoib.c"
46
 #include "ipoib.c"
47
 
47
 
48
+#if 0
48
 static int probe_imp(struct pci_device *pci, struct nic *nic)
49
 static int probe_imp(struct pci_device *pci, struct nic *nic)
49
 {
50
 {
50
 	int rc;
51
 	int rc;
232
 	return -1; 
233
 	return -1; 
233
 	
234
 	
234
 }
235
 }
236
+#endif

Loading…
Cancel
Save