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,6 +52,7 @@ int prompt_key(int secs, unsigned char *ch_p)
52 52
 	return 0;
53 53
 }
54 54
 
55
+#if 0
55 56
 /**************************************************************************
56 57
 IRQ - handle interrupts
57 58
 ***************************************************************************/
@@ -153,6 +154,7 @@ static void mt25218_transmit(struct nic *nic, const char *dest,	/* Destination *
153 154
 			eprintf("tranmit error");
154 155
 	}
155 156
 }
157
+#endif
156 158
 
157 159
 /**
158 160
  * Open network device
@@ -161,6 +163,9 @@ static void mt25218_transmit(struct nic *nic, const char *dest,	/* Destination *
161 163
  * @ret rc		Return status code
162 164
  */
163 165
 static int mlx_open ( struct net_device *netdev ) {
166
+
167
+	( void ) netdev;
168
+
164 169
 	return 0;
165 170
 }
166 171
 
@@ -170,6 +175,9 @@ static int mlx_open ( struct net_device *netdev ) {
170 175
  * @v netdev		Network device
171 176
  */
172 177
 static void mlx_close ( struct net_device *netdev ) {
178
+
179
+	( void ) netdev;
180
+
173 181
 }
174 182
 
175 183
 #warning "Broadcast address?"
@@ -187,6 +195,8 @@ static int mlx_transmit ( struct net_device *netdev,
187 195
 			  struct io_buffer *iobuf ) {
188 196
 	struct ibhdr *ibhdr = iobuf->data;
189 197
 
198
+	( void ) netdev;
199
+
190 200
 	iob_pull ( iobuf, sizeof ( *ibhdr ) );	
191 201
 
192 202
 	if ( memcmp ( ibhdr->peer, ib_broadcast, IB_ALEN ) == 0 ) {
@@ -202,63 +212,107 @@ static int mlx_transmit ( struct net_device *netdev,
202 212
 }
203 213
 
204 214
 /**
205
- * Poll for completed and received packets
215
+ * Handle TX completion
206 216
  *
207 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 234
 	unsigned int len;
213 235
 	struct io_buffer *iobuf;
214 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 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 246
 	iobuf = alloc_iob ( len );
244 247
 	if ( ! iobuf ) {
245
-		DBG ( "out of memory\n" );
246
-		free_wqe ( ib_cqe.wqe );
248
+		netdev_rx_err ( netdev, NULL, -ENOMEM );
247 249
 		return;
248 250
 	}
249
-	buf = get_rcv_wqe_buf(ib_cqe.wqe, 1);
251
+	buf = get_rcv_wqe_buf ( cqe->wqe, 1 );
250 252
 	memcpy ( iob_put ( iobuf, len ), buf, len );
251 253
 	//	DBG ( "Received packet header:\n" );
252 254
 	//	struct recv_wqe_st *rcv_wqe = ib_cqe.wqe;
253 255
 	//	DBG_HD ( get_rcv_wqe_buf(ib_cqe.wqe, 0),
254 256
 	//		 be32_to_cpu(rcv_wqe->mpointer[0].byte_count) );
255
-		 
256 257
 	//	DBG ( "Received packet:\n" );
257 258
 	//	DBG_HD ( iobuf->data, iob_len ( iobuf ) );
258
-
259 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,6 +322,10 @@ static void mlx_poll ( struct net_device *netdev ) {
268 322
  * @v enable		Interrupts should be enabled
269 323
  */
270 324
 static void mlx_irq ( struct net_device *netdev, int enable ) {
325
+
326
+	( void ) netdev;
327
+	( void ) enable;
328
+
271 329
 }
272 330
 
273 331
 static struct net_device_operations mlx_operations = {
@@ -278,6 +336,7 @@ static struct net_device_operations mlx_operations = {
278 336
 	.irq		= mlx_irq,
279 337
 };
280 338
 
339
+#if 0
281 340
 /**************************************************************************
282 341
 DISABLE - Turn off ethernet interface
283 342
 ***************************************************************************/
@@ -297,6 +356,7 @@ static void mt25218_disable(struct nic *nic)
297 356
 		disable_imp();
298 357
 	}
299 358
 }
359
+#endif
300 360
 
301 361
 /**
302 362
  * Remove PCI device
@@ -305,7 +365,6 @@ static void mt25218_disable(struct nic *nic)
305 365
  */
306 366
 static void mlx_remove ( struct pci_device *pci ) {
307 367
 	struct net_device *netdev = pci_get_drvdata ( pci );
308
-	struct mlx_nic *mlx = netdev->priv;
309 368
 
310 369
 	unregister_netdev ( netdev );
311 370
 	ipoib_close(0);
@@ -313,6 +372,7 @@ static void mlx_remove ( struct pci_device *pci ) {
313 372
 	netdev_put ( netdev );
314 373
 }
315 374
 
375
+#if 0
316 376
 static struct nic_operations mt25218_operations = {
317 377
 	.connect	= dummy_connect,
318 378
 	.poll		= mt25218_poll,
@@ -380,6 +440,7 @@ static int mt25218_probe(struct nic *nic, struct pci_device *pci)
380 440
 	/* else */
381 441
 	return 0;
382 442
 }
443
+#endif
383 444
 
384 445
 /**
385 446
  * Probe PCI device

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

@@ -45,6 +45,7 @@ static void be_to_cpu_buf(void *buf, int size)
45 45
 #include "ib_driver.c"
46 46
 #include "ipoib.c"
47 47
 
48
+#if 0
48 49
 static int probe_imp(struct pci_device *pci, struct nic *nic)
49 50
 {
50 51
 	int rc;
@@ -232,3 +233,4 @@ fatal_handling:
232 233
 	return -1; 
233 234
 	
234 235
 }
236
+#endif

Loading…
Cancel
Save