2 * linux/drivers/message/fusion/mptlan.c
3 * IP Over Fibre Channel device driver.
4 * For use with LSI Logic Fibre Channel PCI chip/adapters
5 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
7 * Copyright (c) 2000-2007 LSI Logic Corporation
8 * (mailto:mpt_linux_developer@lsi.com)
11 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; version 2 of the License.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
23 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
24 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
25 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
26 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
27 solely responsible for determining the appropriateness of using and
28 distributing the Program and assumes all risks associated with its
29 exercise of rights under this Agreement, including but not limited to
30 the risks and costs of program errors, damage to or loss of data,
31 programs or equipment, and unavailability or interruption of operations.
33 DISCLAIMER OF LIABILITY
34 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
35 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
37 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
38 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
39 USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
40 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
42 You should have received a copy of the GNU General Public License
43 along with this program; if not, write to the Free Software
44 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
47 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
49 * Define statements used for debugging
51 //#define MPT_LAN_IO_DEBUG
53 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
56 #include <linux/init.h>
57 #include <linux/module.h>
60 #define my_VERSION MPT_LINUX_VERSION_COMMON
61 #define MYNAM "mptlan"
63 MODULE_LICENSE("GPL");
64 MODULE_VERSION(my_VERSION);
66 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
68 * MPT LAN message sizes without variable part.
70 #define MPT_LAN_RECEIVE_POST_REQUEST_SIZE \
71 (sizeof(LANReceivePostRequest_t) - sizeof(SGE_MPI_UNION))
73 #define MPT_LAN_TRANSACTION32_SIZE \
74 (sizeof(SGETransaction32_t) - sizeof(u32))
77 * Fusion MPT LAN private structures
83 struct NAA_Hosed *next;
86 struct BufferControl {
94 u8 pnum; /* Port number in the IOC. This is not a Unix network port! */
96 atomic_t buckets_out; /* number of unused buckets on IOC */
97 int bucketthresh; /* Send more when this many left */
99 int *mpt_txfidx; /* Free Tx Context list */
101 spinlock_t txfidx_lock;
103 int *mpt_rxfidx; /* Free Rx Context list */
105 spinlock_t rxfidx_lock;
107 struct BufferControl *RcvCtl; /* Receive BufferControl structs */
108 struct BufferControl *SendCtl; /* Send BufferControl structs */
110 int max_buckets_out; /* Max buckets to send to IOC */
111 int tx_max_out; /* IOC's Tx queue len */
115 struct net_device_stats stats; /* Per device statistics */
117 struct delayed_work post_buckets_task;
118 struct net_device *dev;
119 unsigned long post_buckets_active;
122 struct mpt_lan_ohdr {
129 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
134 static int lan_reply (MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf,
135 MPT_FRAME_HDR *reply);
136 static int mpt_lan_open(struct net_device *dev);
137 static int mpt_lan_reset(struct net_device *dev);
138 static int mpt_lan_close(struct net_device *dev);
139 static void mpt_lan_post_receive_buckets(struct mpt_lan_priv *priv);
140 static void mpt_lan_wake_post_buckets_task(struct net_device *dev,
142 static int mpt_lan_receive_post_turbo(struct net_device *dev, u32 tmsg);
143 static int mpt_lan_receive_post_reply(struct net_device *dev,
144 LANReceivePostReply_t *pRecvRep);
145 static int mpt_lan_send_turbo(struct net_device *dev, u32 tmsg);
146 static int mpt_lan_send_reply(struct net_device *dev,
147 LANSendReply_t *pSendRep);
148 static int mpt_lan_ioc_reset(MPT_ADAPTER *ioc, int reset_phase);
149 static int mpt_lan_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply);
150 static unsigned short mpt_lan_type_trans(struct sk_buff *skb,
151 struct net_device *dev);
153 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
155 * Fusion MPT LAN private data
157 static int LanCtx = -1;
159 static u32 max_buckets_out = 127;
160 static u32 tx_max_out_p = 127 - 16;
162 #ifdef QLOGIC_NAA_WORKAROUND
163 static struct NAA_Hosed *mpt_bad_naa = NULL;
164 DEFINE_RWLOCK(bad_naa_lock);
167 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
169 * Fusion MPT LAN external data
171 extern int mpt_lan_index;
173 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
175 * lan_reply - Handle all data sent from the hardware.
176 * @ioc: Pointer to MPT_ADAPTER structure
177 * @mf: Pointer to original MPT request frame (NULL if TurboReply)
178 * @reply: Pointer to MPT reply frame
180 * Returns 1 indicating original alloc'd request frame ptr
181 * should be freed, or 0 if it shouldn't.
184 lan_reply (MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *reply)
186 struct net_device *dev = ioc->netdev;
187 int FreeReqFrame = 0;
189 dioprintk((KERN_INFO MYNAM ": %s/%s: Got reply.\n",
190 IOC_AND_NETDEV_NAMES_s_s(dev)));
192 // dioprintk((KERN_INFO MYNAM "@lan_reply: mf = %p, reply = %p\n",
196 u32 tmsg = CAST_PTR_TO_U32(reply);
198 dioprintk((KERN_INFO MYNAM ": %s/%s: @lan_reply, tmsg %08x\n",
199 IOC_AND_NETDEV_NAMES_s_s(dev),
202 switch (GET_LAN_FORM(tmsg)) {
204 // NOTE! (Optimization) First case here is now caught in
205 // mptbase.c::mpt_interrupt() routine and callcack here
206 // is now skipped for this case!
208 case LAN_REPLY_FORM_MESSAGE_CONTEXT:
209 // dioprintk((KERN_INFO MYNAM "/lan_reply: "
210 // "MessageContext turbo reply received\n"));
215 case LAN_REPLY_FORM_SEND_SINGLE:
216 // dioprintk((MYNAM "/lan_reply: "
217 // "calling mpt_lan_send_reply (turbo)\n"));
219 // Potential BUG here?
220 // FreeReqFrame = mpt_lan_send_turbo(dev, tmsg);
221 // If/when mpt_lan_send_turbo would return 1 here,
222 // calling routine (mptbase.c|mpt_interrupt)
223 // would Oops because mf has already been set
224 // to NULL. So after return from this func,
225 // mpt_interrupt() will attempt to put (NULL) mf ptr
226 // item back onto its adapter FreeQ - Oops!:-(
227 // It's Ok, since mpt_lan_send_turbo() *currently*
228 // always returns 0, but..., just in case:
230 (void) mpt_lan_send_turbo(dev, tmsg);
235 case LAN_REPLY_FORM_RECEIVE_SINGLE:
236 // dioprintk((KERN_INFO MYNAM "@lan_reply: "
237 // "rcv-Turbo = %08x\n", tmsg));
238 mpt_lan_receive_post_turbo(dev, tmsg);
242 printk (KERN_ERR MYNAM "/lan_reply: Got a turbo reply "
243 "that I don't know what to do with\n");
245 /* CHECKME! Hmmm... FreeReqFrame is 0 here; is that right? */
253 // msg = (u32 *) reply;
254 // dioprintk((KERN_INFO MYNAM "@lan_reply: msg = %08x %08x %08x %08x\n",
255 // le32_to_cpu(msg[0]), le32_to_cpu(msg[1]),
256 // le32_to_cpu(msg[2]), le32_to_cpu(msg[3])));
257 // dioprintk((KERN_INFO MYNAM "@lan_reply: Function = %02xh\n",
258 // reply->u.hdr.Function));
260 switch (reply->u.hdr.Function) {
262 case MPI_FUNCTION_LAN_SEND:
264 LANSendReply_t *pSendRep;
266 pSendRep = (LANSendReply_t *) reply;
267 FreeReqFrame = mpt_lan_send_reply(dev, pSendRep);
271 case MPI_FUNCTION_LAN_RECEIVE:
273 LANReceivePostReply_t *pRecvRep;
275 pRecvRep = (LANReceivePostReply_t *) reply;
276 if (pRecvRep->NumberOfContexts) {
277 mpt_lan_receive_post_reply(dev, pRecvRep);
278 if (!(pRecvRep->MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY))
281 dioprintk((KERN_INFO MYNAM "@lan_reply: zero context "
282 "ReceivePostReply received.\n"));
286 case MPI_FUNCTION_LAN_RESET:
287 /* Just a default reply. Might want to check it to
288 * make sure that everything went ok.
293 case MPI_FUNCTION_EVENT_NOTIFICATION:
294 case MPI_FUNCTION_EVENT_ACK:
295 /* _EVENT_NOTIFICATION should NOT come down this path any more.
296 * Should be routed to mpt_lan_event_process(), but just in case...
302 printk (KERN_ERR MYNAM "/lan_reply: Got a non-turbo "
303 "reply that I don't know what to do with\n");
305 /* CHECKME! Hmmm... FreeReqFrame is 0 here; is that right? */
314 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
316 mpt_lan_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
318 struct net_device *dev = ioc->netdev;
319 struct mpt_lan_priv *priv;
324 priv = netdev_priv(dev);
326 dlprintk((KERN_INFO MYNAM ": IOC %s_reset routed to LAN driver!\n",
327 reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
328 reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
330 if (priv->mpt_rxfidx == NULL)
333 if (reset_phase == MPT_IOC_SETUP_RESET) {
335 } else if (reset_phase == MPT_IOC_PRE_RESET) {
339 netif_stop_queue(dev);
341 dlprintk ((KERN_INFO "mptlan/ioc_reset: called netif_stop_queue for %s.\n", dev->name));
343 atomic_set(&priv->buckets_out, 0);
345 /* Reset Rx Free Tail index and re-populate the queue. */
346 spin_lock_irqsave(&priv->rxfidx_lock, flags);
347 priv->mpt_rxfidx_tail = -1;
348 for (i = 0; i < priv->max_buckets_out; i++)
349 priv->mpt_rxfidx[++priv->mpt_rxfidx_tail] = i;
350 spin_unlock_irqrestore(&priv->rxfidx_lock, flags);
352 mpt_lan_post_receive_buckets(priv);
353 netif_wake_queue(dev);
359 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
361 mpt_lan_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
363 dlprintk((KERN_INFO MYNAM ": MPT event routed to LAN driver!\n"));
365 switch (le32_to_cpu(pEvReply->Event)) {
366 case MPI_EVENT_NONE: /* 00 */
367 case MPI_EVENT_LOG_DATA: /* 01 */
368 case MPI_EVENT_STATE_CHANGE: /* 02 */
369 case MPI_EVENT_UNIT_ATTENTION: /* 03 */
370 case MPI_EVENT_IOC_BUS_RESET: /* 04 */
371 case MPI_EVENT_EXT_BUS_RESET: /* 05 */
372 case MPI_EVENT_RESCAN: /* 06 */
373 /* Ok, do we need to do anything here? As far as
374 I can tell, this is when a new device gets added
376 case MPI_EVENT_LINK_STATUS_CHANGE: /* 07 */
377 case MPI_EVENT_LOOP_STATE_CHANGE: /* 08 */
378 case MPI_EVENT_LOGOUT: /* 09 */
379 case MPI_EVENT_EVENT_CHANGE: /* 0A */
385 * NOTE: pEvent->AckRequired handling now done in mptbase.c;
386 * Do NOT do it here now!
392 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
394 mpt_lan_open(struct net_device *dev)
396 struct mpt_lan_priv *priv = netdev_priv(dev);
399 if (mpt_lan_reset(dev) != 0) {
400 MPT_ADAPTER *mpt_dev = priv->mpt_dev;
402 printk (KERN_WARNING MYNAM "/lan_open: lan_reset failed.");
405 printk ("The ioc is active. Perhaps it needs to be"
408 printk ("The ioc in inactive, most likely in the "
409 "process of being reset. Please try again in "
413 priv->mpt_txfidx = kmalloc(priv->tx_max_out * sizeof(int), GFP_KERNEL);
414 if (priv->mpt_txfidx == NULL)
416 priv->mpt_txfidx_tail = -1;
418 priv->SendCtl = kcalloc(priv->tx_max_out, sizeof(struct BufferControl),
420 if (priv->SendCtl == NULL)
422 for (i = 0; i < priv->tx_max_out; i++)
423 priv->mpt_txfidx[++priv->mpt_txfidx_tail] = i;
425 dlprintk((KERN_INFO MYNAM "@lo: Finished initializing SendCtl\n"));
427 priv->mpt_rxfidx = kmalloc(priv->max_buckets_out * sizeof(int),
429 if (priv->mpt_rxfidx == NULL)
431 priv->mpt_rxfidx_tail = -1;
433 priv->RcvCtl = kcalloc(priv->max_buckets_out,
434 sizeof(struct BufferControl),
436 if (priv->RcvCtl == NULL)
438 for (i = 0; i < priv->max_buckets_out; i++)
439 priv->mpt_rxfidx[++priv->mpt_rxfidx_tail] = i;
441 /**/ dlprintk((KERN_INFO MYNAM "/lo: txfidx contains - "));
442 /**/ for (i = 0; i < priv->tx_max_out; i++)
443 /**/ dlprintk((" %xh", priv->mpt_txfidx[i]));
444 /**/ dlprintk(("\n"));
446 dlprintk((KERN_INFO MYNAM "/lo: Finished initializing RcvCtl\n"));
448 mpt_lan_post_receive_buckets(priv);
449 printk(KERN_INFO MYNAM ": %s/%s: interface up & active\n",
450 IOC_AND_NETDEV_NAMES_s_s(dev));
452 if (mpt_event_register(LanCtx, mpt_lan_event_process) != 0) {
453 printk (KERN_WARNING MYNAM "/lo: Unable to register for Event"
454 " Notifications. This is a bad thing! We're not going "
455 "to go ahead, but I'd be leery of system stability at "
459 netif_start_queue(dev);
460 dlprintk((KERN_INFO MYNAM "/lo: Done.\n"));
464 kfree(priv->mpt_rxfidx);
465 priv->mpt_rxfidx = NULL;
467 kfree(priv->SendCtl);
468 priv->SendCtl = NULL;
470 kfree(priv->mpt_txfidx);
471 priv->mpt_txfidx = NULL;
475 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
476 /* Send a LanReset message to the FW. This should result in the FW returning
477 any buckets it still has. */
479 mpt_lan_reset(struct net_device *dev)
482 LANResetRequest_t *pResetReq;
483 struct mpt_lan_priv *priv = netdev_priv(dev);
485 mf = mpt_get_msg_frame(LanCtx, priv->mpt_dev);
488 /* dlprintk((KERN_ERR MYNAM "/reset: Evil funkiness abounds! "
489 "Unable to allocate a request frame.\n"));
494 pResetReq = (LANResetRequest_t *) mf;
496 pResetReq->Function = MPI_FUNCTION_LAN_RESET;
497 pResetReq->ChainOffset = 0;
498 pResetReq->Reserved = 0;
499 pResetReq->PortNumber = priv->pnum;
500 pResetReq->MsgFlags = 0;
501 pResetReq->Reserved2 = 0;
503 mpt_put_msg_frame(LanCtx, priv->mpt_dev, mf);
508 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
510 mpt_lan_close(struct net_device *dev)
512 struct mpt_lan_priv *priv = netdev_priv(dev);
513 MPT_ADAPTER *mpt_dev = priv->mpt_dev;
514 unsigned long timeout;
517 dlprintk((KERN_INFO MYNAM ": mpt_lan_close called\n"));
519 mpt_event_deregister(LanCtx);
521 dlprintk((KERN_INFO MYNAM ":lan_close: Posted %d buckets "
522 "since driver was loaded, %d still out\n",
523 priv->total_posted,atomic_read(&priv->buckets_out)));
525 netif_stop_queue(dev);
529 timeout = jiffies + 2 * HZ;
530 while (atomic_read(&priv->buckets_out) && time_before(jiffies, timeout))
531 schedule_timeout_interruptible(1);
533 for (i = 0; i < priv->max_buckets_out; i++) {
534 if (priv->RcvCtl[i].skb != NULL) {
535 /**/ dlprintk((KERN_INFO MYNAM "/lan_close: bucket %05x "
536 /**/ "is still out\n", i));
537 pci_unmap_single(mpt_dev->pcidev, priv->RcvCtl[i].dma,
540 dev_kfree_skb(priv->RcvCtl[i].skb);
545 kfree(priv->mpt_rxfidx);
547 for (i = 0; i < priv->tx_max_out; i++) {
548 if (priv->SendCtl[i].skb != NULL) {
549 pci_unmap_single(mpt_dev->pcidev, priv->SendCtl[i].dma,
550 priv->SendCtl[i].len,
552 dev_kfree_skb(priv->SendCtl[i].skb);
556 kfree(priv->SendCtl);
557 kfree(priv->mpt_txfidx);
559 atomic_set(&priv->buckets_out, 0);
561 printk(KERN_INFO MYNAM ": %s/%s: interface down & inactive\n",
562 IOC_AND_NETDEV_NAMES_s_s(dev));
567 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
568 static struct net_device_stats *
569 mpt_lan_get_stats(struct net_device *dev)
571 struct mpt_lan_priv *priv = netdev_priv(dev);
573 return (struct net_device_stats *) &priv->stats;
576 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
578 mpt_lan_change_mtu(struct net_device *dev, int new_mtu)
580 if ((new_mtu < MPT_LAN_MIN_MTU) || (new_mtu > MPT_LAN_MAX_MTU))
586 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
587 /* Tx timeout handler. */
589 mpt_lan_tx_timeout(struct net_device *dev)
591 struct mpt_lan_priv *priv = netdev_priv(dev);
592 MPT_ADAPTER *mpt_dev = priv->mpt_dev;
594 if (mpt_dev->active) {
595 dlprintk (("mptlan/tx_timeout: calling netif_wake_queue for %s.\n", dev->name));
596 netif_wake_queue(dev);
600 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
603 mpt_lan_send_turbo(struct net_device *dev, u32 tmsg)
605 struct mpt_lan_priv *priv = netdev_priv(dev);
606 MPT_ADAPTER *mpt_dev = priv->mpt_dev;
607 struct sk_buff *sent;
611 ctx = GET_LAN_BUFFER_CONTEXT(tmsg);
612 sent = priv->SendCtl[ctx].skb;
614 priv->stats.tx_packets++;
615 priv->stats.tx_bytes += sent->len;
617 dioprintk((KERN_INFO MYNAM ": %s/%s: @%s, skb %p sent.\n",
618 IOC_AND_NETDEV_NAMES_s_s(dev),
619 __FUNCTION__, sent));
621 priv->SendCtl[ctx].skb = NULL;
622 pci_unmap_single(mpt_dev->pcidev, priv->SendCtl[ctx].dma,
623 priv->SendCtl[ctx].len, PCI_DMA_TODEVICE);
624 dev_kfree_skb_irq(sent);
626 spin_lock_irqsave(&priv->txfidx_lock, flags);
627 priv->mpt_txfidx[++priv->mpt_txfidx_tail] = ctx;
628 spin_unlock_irqrestore(&priv->txfidx_lock, flags);
630 netif_wake_queue(dev);
634 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
636 mpt_lan_send_reply(struct net_device *dev, LANSendReply_t *pSendRep)
638 struct mpt_lan_priv *priv = netdev_priv(dev);
639 MPT_ADAPTER *mpt_dev = priv->mpt_dev;
640 struct sk_buff *sent;
642 int FreeReqFrame = 0;
647 count = pSendRep->NumberOfContexts;
649 dioprintk((KERN_INFO MYNAM ": send_reply: IOCStatus: %04x\n",
650 le16_to_cpu(pSendRep->IOCStatus)));
652 /* Add check for Loginfo Flag in IOCStatus */
654 switch (le16_to_cpu(pSendRep->IOCStatus) & MPI_IOCSTATUS_MASK) {
655 case MPI_IOCSTATUS_SUCCESS:
656 priv->stats.tx_packets += count;
659 case MPI_IOCSTATUS_LAN_CANCELED:
660 case MPI_IOCSTATUS_LAN_TRANSMIT_ABORTED:
663 case MPI_IOCSTATUS_INVALID_SGL:
664 priv->stats.tx_errors += count;
665 printk (KERN_ERR MYNAM ": %s/%s: ERROR - Invalid SGL sent to IOC!\n",
666 IOC_AND_NETDEV_NAMES_s_s(dev));
670 priv->stats.tx_errors += count;
674 pContext = &pSendRep->BufferContext;
676 spin_lock_irqsave(&priv->txfidx_lock, flags);
678 ctx = GET_LAN_BUFFER_CONTEXT(le32_to_cpu(*pContext));
680 sent = priv->SendCtl[ctx].skb;
681 priv->stats.tx_bytes += sent->len;
683 dioprintk((KERN_INFO MYNAM ": %s/%s: @%s, skb %p sent.\n",
684 IOC_AND_NETDEV_NAMES_s_s(dev),
685 __FUNCTION__, sent));
687 priv->SendCtl[ctx].skb = NULL;
688 pci_unmap_single(mpt_dev->pcidev, priv->SendCtl[ctx].dma,
689 priv->SendCtl[ctx].len, PCI_DMA_TODEVICE);
690 dev_kfree_skb_irq(sent);
692 priv->mpt_txfidx[++priv->mpt_txfidx_tail] = ctx;
697 spin_unlock_irqrestore(&priv->txfidx_lock, flags);
700 if (!(pSendRep->MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY))
703 netif_wake_queue(dev);
707 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
709 mpt_lan_sdu_send (struct sk_buff *skb, struct net_device *dev)
711 struct mpt_lan_priv *priv = netdev_priv(dev);
712 MPT_ADAPTER *mpt_dev = priv->mpt_dev;
714 LANSendRequest_t *pSendReq;
715 SGETransaction32_t *pTrans;
716 SGESimple64_t *pSimple;
720 u16 cur_naa = 0x1000;
722 dioprintk((KERN_INFO MYNAM ": %s called, skb_addr = %p\n",
725 spin_lock_irqsave(&priv->txfidx_lock, flags);
726 if (priv->mpt_txfidx_tail < 0) {
727 netif_stop_queue(dev);
728 spin_unlock_irqrestore(&priv->txfidx_lock, flags);
730 printk (KERN_ERR "%s: no tx context available: %u\n",
731 __FUNCTION__, priv->mpt_txfidx_tail);
735 mf = mpt_get_msg_frame(LanCtx, mpt_dev);
737 netif_stop_queue(dev);
738 spin_unlock_irqrestore(&priv->txfidx_lock, flags);
740 printk (KERN_ERR "%s: Unable to alloc request frame\n",
745 ctx = priv->mpt_txfidx[priv->mpt_txfidx_tail--];
746 spin_unlock_irqrestore(&priv->txfidx_lock, flags);
748 // dioprintk((KERN_INFO MYNAM ": %s/%s: Creating new msg frame (send).\n",
749 // IOC_AND_NETDEV_NAMES_s_s(dev)));
751 pSendReq = (LANSendRequest_t *) mf;
753 /* Set the mac.raw pointer, since this apparently isn't getting
754 * done before we get the skb. Pull the data pointer past the mac data.
756 skb->mac.raw = skb->data;
759 dma = pci_map_single(mpt_dev->pcidev, skb->data, skb->len,
762 priv->SendCtl[ctx].skb = skb;
763 priv->SendCtl[ctx].dma = dma;
764 priv->SendCtl[ctx].len = skb->len;
767 pSendReq->Reserved = 0;
768 pSendReq->Function = MPI_FUNCTION_LAN_SEND;
769 pSendReq->ChainOffset = 0;
770 pSendReq->Reserved2 = 0;
771 pSendReq->MsgFlags = 0;
772 pSendReq->PortNumber = priv->pnum;
774 /* Transaction Context Element */
775 pTrans = (SGETransaction32_t *) pSendReq->SG_List;
777 /* No Flags, 8 bytes of Details, 32bit Context (bloody turbo replies) */
778 pTrans->ContextSize = sizeof(u32);
779 pTrans->DetailsLength = 2 * sizeof(u32);
781 pTrans->TransactionContext[0] = cpu_to_le32(ctx);
783 // dioprintk((KERN_INFO MYNAM ": %s/%s: BC = %08x, skb = %p, buff = %p\n",
784 // IOC_AND_NETDEV_NAMES_s_s(dev),
785 // ctx, skb, skb->data));
787 #ifdef QLOGIC_NAA_WORKAROUND
789 struct NAA_Hosed *nh;
791 /* Munge the NAA for Tx packets to QLogic boards, which don't follow
792 RFC 2625. The longer I look at this, the more my opinion of Qlogic
794 read_lock_irq(&bad_naa_lock);
795 for (nh = mpt_bad_naa; nh != NULL; nh=nh->next) {
796 if ((nh->ieee[0] == skb->mac.raw[0]) &&
797 (nh->ieee[1] == skb->mac.raw[1]) &&
798 (nh->ieee[2] == skb->mac.raw[2]) &&
799 (nh->ieee[3] == skb->mac.raw[3]) &&
800 (nh->ieee[4] == skb->mac.raw[4]) &&
801 (nh->ieee[5] == skb->mac.raw[5])) {
803 dlprintk ((KERN_INFO "mptlan/sdu_send: using NAA value "
804 "= %04x.\n", cur_naa));
808 read_unlock_irq(&bad_naa_lock);
812 pTrans->TransactionDetails[0] = cpu_to_le32((cur_naa << 16) |
813 (skb->mac.raw[0] << 8) |
814 (skb->mac.raw[1] << 0));
815 pTrans->TransactionDetails[1] = cpu_to_le32((skb->mac.raw[2] << 24) |
816 (skb->mac.raw[3] << 16) |
817 (skb->mac.raw[4] << 8) |
818 (skb->mac.raw[5] << 0));
820 pSimple = (SGESimple64_t *) &pTrans->TransactionDetails[2];
822 /* If we ever decide to send more than one Simple SGE per LANSend, then
823 we will need to make sure that LAST_ELEMENT only gets set on the
824 last one. Otherwise, bad voodoo and evil funkiness will commence. */
825 pSimple->FlagsLength = cpu_to_le32(
826 ((MPI_SGE_FLAGS_LAST_ELEMENT |
827 MPI_SGE_FLAGS_END_OF_BUFFER |
828 MPI_SGE_FLAGS_SIMPLE_ELEMENT |
829 MPI_SGE_FLAGS_SYSTEM_ADDRESS |
830 MPI_SGE_FLAGS_HOST_TO_IOC |
831 MPI_SGE_FLAGS_64_BIT_ADDRESSING |
832 MPI_SGE_FLAGS_END_OF_LIST) << MPI_SGE_FLAGS_SHIFT) |
834 pSimple->Address.Low = cpu_to_le32((u32) dma);
835 if (sizeof(dma_addr_t) > sizeof(u32))
836 pSimple->Address.High = cpu_to_le32((u32) ((u64) dma >> 32));
838 pSimple->Address.High = 0;
840 mpt_put_msg_frame (LanCtx, mpt_dev, mf);
841 dev->trans_start = jiffies;
843 dioprintk((KERN_INFO MYNAM ": %s/%s: Sending packet. FlagsLength = %08x.\n",
844 IOC_AND_NETDEV_NAMES_s_s(dev),
845 le32_to_cpu(pSimple->FlagsLength)));
850 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
852 mpt_lan_wake_post_buckets_task(struct net_device *dev, int priority)
854 * @priority: 0 = put it on the timer queue, 1 = put it on the immediate queue
857 struct mpt_lan_priv *priv = dev->priv;
859 if (test_and_set_bit(0, &priv->post_buckets_active) == 0) {
861 schedule_delayed_work(&priv->post_buckets_task, 0);
863 schedule_delayed_work(&priv->post_buckets_task, 1);
864 dioprintk((KERN_INFO MYNAM ": post_buckets queued on "
867 dioprintk((KERN_INFO MYNAM ": %s/%s: Queued post_buckets task.\n",
868 IOC_AND_NETDEV_NAMES_s_s(dev) ));
872 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
874 mpt_lan_receive_skb(struct net_device *dev, struct sk_buff *skb)
876 struct mpt_lan_priv *priv = dev->priv;
878 skb->protocol = mpt_lan_type_trans(skb, dev);
880 dioprintk((KERN_INFO MYNAM ": %s/%s: Incoming packet (%d bytes) "
881 "delivered to upper level.\n",
882 IOC_AND_NETDEV_NAMES_s_s(dev), skb->len));
884 priv->stats.rx_bytes += skb->len;
885 priv->stats.rx_packets++;
890 dioprintk((MYNAM "/receive_skb: %d buckets remaining\n",
891 atomic_read(&priv->buckets_out)));
893 if (atomic_read(&priv->buckets_out) < priv->bucketthresh)
894 mpt_lan_wake_post_buckets_task(dev, 1);
896 dioprintk((KERN_INFO MYNAM "/receive_post_reply: %d buckets "
897 "remaining, %d received back since sod\n",
898 atomic_read(&priv->buckets_out), priv->total_received));
903 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
906 mpt_lan_receive_post_turbo(struct net_device *dev, u32 tmsg)
908 struct mpt_lan_priv *priv = dev->priv;
909 MPT_ADAPTER *mpt_dev = priv->mpt_dev;
910 struct sk_buff *skb, *old_skb;
914 ctx = GET_LAN_BUCKET_CONTEXT(tmsg);
915 skb = priv->RcvCtl[ctx].skb;
917 len = GET_LAN_PACKET_LENGTH(tmsg);
919 if (len < MPT_LAN_RX_COPYBREAK) {
922 skb = (struct sk_buff *)dev_alloc_skb(len);
924 printk (KERN_ERR MYNAM ": %s/%s: ERROR - Can't allocate skb! (%s@%d)\n",
925 IOC_AND_NETDEV_NAMES_s_s(dev),
930 pci_dma_sync_single_for_cpu(mpt_dev->pcidev, priv->RcvCtl[ctx].dma,
931 priv->RcvCtl[ctx].len, PCI_DMA_FROMDEVICE);
933 memcpy(skb_put(skb, len), old_skb->data, len);
935 pci_dma_sync_single_for_device(mpt_dev->pcidev, priv->RcvCtl[ctx].dma,
936 priv->RcvCtl[ctx].len, PCI_DMA_FROMDEVICE);
942 priv->RcvCtl[ctx].skb = NULL;
944 pci_unmap_single(mpt_dev->pcidev, priv->RcvCtl[ctx].dma,
945 priv->RcvCtl[ctx].len, PCI_DMA_FROMDEVICE);
948 spin_lock_irqsave(&priv->rxfidx_lock, flags);
949 priv->mpt_rxfidx[++priv->mpt_rxfidx_tail] = ctx;
950 spin_unlock_irqrestore(&priv->rxfidx_lock, flags);
952 atomic_dec(&priv->buckets_out);
953 priv->total_received++;
955 return mpt_lan_receive_skb(dev, skb);
958 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
960 mpt_lan_receive_post_free(struct net_device *dev,
961 LANReceivePostReply_t *pRecvRep)
963 struct mpt_lan_priv *priv = dev->priv;
964 MPT_ADAPTER *mpt_dev = priv->mpt_dev;
971 count = pRecvRep->NumberOfContexts;
973 /**/ dlprintk((KERN_INFO MYNAM "/receive_post_reply: "
974 "IOC returned %d buckets, freeing them...\n", count));
976 spin_lock_irqsave(&priv->rxfidx_lock, flags);
977 for (i = 0; i < count; i++) {
978 ctx = le32_to_cpu(pRecvRep->BucketContext[i]);
980 skb = priv->RcvCtl[ctx].skb;
982 // dlprintk((KERN_INFO MYNAM ": %s: dev_name = %s\n",
983 // IOC_AND_NETDEV_NAMES_s_s(dev)));
984 // dlprintk((KERN_INFO MYNAM "@rpr[2], priv = %p, buckets_out addr = %p",
985 // priv, &(priv->buckets_out)));
986 // dlprintk((KERN_INFO MYNAM "@rpr[2] TC + 3\n"));
988 priv->RcvCtl[ctx].skb = NULL;
989 pci_unmap_single(mpt_dev->pcidev, priv->RcvCtl[ctx].dma,
990 priv->RcvCtl[ctx].len, PCI_DMA_FROMDEVICE);
991 dev_kfree_skb_any(skb);
993 priv->mpt_rxfidx[++priv->mpt_rxfidx_tail] = ctx;
995 spin_unlock_irqrestore(&priv->rxfidx_lock, flags);
997 atomic_sub(count, &priv->buckets_out);
999 // for (i = 0; i < priv->max_buckets_out; i++)
1000 // if (priv->RcvCtl[i].skb != NULL)
1001 // dlprintk((KERN_INFO MYNAM "@rpr: bucket %03x "
1002 // "is still out\n", i));
1004 /* dlprintk((KERN_INFO MYNAM "/receive_post_reply: freed %d buckets\n",
1007 /**/ dlprintk((KERN_INFO MYNAM "@receive_post_reply: %d buckets "
1008 /**/ "remaining, %d received back since sod.\n",
1009 /**/ atomic_read(&priv->buckets_out), priv->total_received));
1013 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1015 mpt_lan_receive_post_reply(struct net_device *dev,
1016 LANReceivePostReply_t *pRecvRep)
1018 struct mpt_lan_priv *priv = dev->priv;
1019 MPT_ADAPTER *mpt_dev = priv->mpt_dev;
1020 struct sk_buff *skb, *old_skb;
1021 unsigned long flags;
1022 u32 len, ctx, offset;
1023 u32 remaining = le32_to_cpu(pRecvRep->BucketsRemaining);
1027 dioprintk((KERN_INFO MYNAM ": mpt_lan_receive_post_reply called\n"));
1028 dioprintk((KERN_INFO MYNAM ": receive_post_reply: IOCStatus: %04x\n",
1029 le16_to_cpu(pRecvRep->IOCStatus)));
1031 if ((le16_to_cpu(pRecvRep->IOCStatus) & MPI_IOCSTATUS_MASK) ==
1032 MPI_IOCSTATUS_LAN_CANCELED)
1033 return mpt_lan_receive_post_free(dev, pRecvRep);
1035 len = le32_to_cpu(pRecvRep->PacketLength);
1037 printk (KERN_ERR MYNAM ": %s/%s: ERROR - Got a non-TURBO "
1038 "ReceivePostReply w/ PacketLength zero!\n",
1039 IOC_AND_NETDEV_NAMES_s_s(dev));
1040 printk (KERN_ERR MYNAM ": MsgFlags = %02x, IOCStatus = %04x\n",
1041 pRecvRep->MsgFlags, le16_to_cpu(pRecvRep->IOCStatus));
1045 ctx = le32_to_cpu(pRecvRep->BucketContext[0]);
1046 count = pRecvRep->NumberOfContexts;
1047 skb = priv->RcvCtl[ctx].skb;
1049 offset = le32_to_cpu(pRecvRep->PacketOffset);
1050 // if (offset != 0) {
1051 // printk (KERN_INFO MYNAM ": %s/%s: Got a ReceivePostReply "
1052 // "w/ PacketOffset %u\n",
1053 // IOC_AND_NETDEV_NAMES_s_s(dev),
1057 dioprintk((KERN_INFO MYNAM ": %s/%s: @rpr, offset = %d, len = %d\n",
1058 IOC_AND_NETDEV_NAMES_s_s(dev),
1064 // dioprintk((KERN_INFO MYNAM ": %s/%s: Multiple buckets returned "
1065 // "for single packet, concatenating...\n",
1066 // IOC_AND_NETDEV_NAMES_s_s(dev)));
1068 skb = (struct sk_buff *)dev_alloc_skb(len);
1070 printk (KERN_ERR MYNAM ": %s/%s: ERROR - Can't allocate skb! (%s@%d)\n",
1071 IOC_AND_NETDEV_NAMES_s_s(dev),
1072 __FILE__, __LINE__);
1076 spin_lock_irqsave(&priv->rxfidx_lock, flags);
1077 for (i = 0; i < count; i++) {
1079 ctx = le32_to_cpu(pRecvRep->BucketContext[i]);
1080 old_skb = priv->RcvCtl[ctx].skb;
1082 l = priv->RcvCtl[ctx].len;
1086 // dioprintk((KERN_INFO MYNAM ": %s/%s: Buckets = %d, len = %u\n",
1087 // IOC_AND_NETDEV_NAMES_s_s(dev),
1090 pci_dma_sync_single_for_cpu(mpt_dev->pcidev,
1091 priv->RcvCtl[ctx].dma,
1092 priv->RcvCtl[ctx].len,
1093 PCI_DMA_FROMDEVICE);
1094 memcpy(skb_put(skb, l), old_skb->data, l);
1096 pci_dma_sync_single_for_device(mpt_dev->pcidev,
1097 priv->RcvCtl[ctx].dma,
1098 priv->RcvCtl[ctx].len,
1099 PCI_DMA_FROMDEVICE);
1101 priv->mpt_rxfidx[++priv->mpt_rxfidx_tail] = ctx;
1104 spin_unlock_irqrestore(&priv->rxfidx_lock, flags);
1106 } else if (len < MPT_LAN_RX_COPYBREAK) {
1110 skb = (struct sk_buff *)dev_alloc_skb(len);
1112 printk (KERN_ERR MYNAM ": %s/%s: ERROR - Can't allocate skb! (%s@%d)\n",
1113 IOC_AND_NETDEV_NAMES_s_s(dev),
1114 __FILE__, __LINE__);
1118 pci_dma_sync_single_for_cpu(mpt_dev->pcidev,
1119 priv->RcvCtl[ctx].dma,
1120 priv->RcvCtl[ctx].len,
1121 PCI_DMA_FROMDEVICE);
1123 memcpy(skb_put(skb, len), old_skb->data, len);
1125 pci_dma_sync_single_for_device(mpt_dev->pcidev,
1126 priv->RcvCtl[ctx].dma,
1127 priv->RcvCtl[ctx].len,
1128 PCI_DMA_FROMDEVICE);
1130 spin_lock_irqsave(&priv->rxfidx_lock, flags);
1131 priv->mpt_rxfidx[++priv->mpt_rxfidx_tail] = ctx;
1132 spin_unlock_irqrestore(&priv->rxfidx_lock, flags);
1135 spin_lock_irqsave(&priv->rxfidx_lock, flags);
1137 priv->RcvCtl[ctx].skb = NULL;
1139 pci_unmap_single(mpt_dev->pcidev, priv->RcvCtl[ctx].dma,
1140 priv->RcvCtl[ctx].len, PCI_DMA_FROMDEVICE);
1141 priv->RcvCtl[ctx].dma = 0;
1143 priv->mpt_rxfidx[++priv->mpt_rxfidx_tail] = ctx;
1144 spin_unlock_irqrestore(&priv->rxfidx_lock, flags);
1149 atomic_sub(count, &priv->buckets_out);
1150 priv->total_received += count;
1152 if (priv->mpt_rxfidx_tail >= MPT_LAN_MAX_BUCKETS_OUT) {
1153 printk (KERN_ERR MYNAM ": %s/%s: Yoohoo! mpt_rxfidx_tail = %d, "
1154 "MPT_LAN_MAX_BUCKETS_OUT = %d\n",
1155 IOC_AND_NETDEV_NAMES_s_s(dev),
1156 priv->mpt_rxfidx_tail,
1157 MPT_LAN_MAX_BUCKETS_OUT);
1163 printk (KERN_WARNING MYNAM ": %s/%s: WARNING - IOC out of buckets! "
1164 "(priv->buckets_out = %d)\n",
1165 IOC_AND_NETDEV_NAMES_s_s(dev),
1166 atomic_read(&priv->buckets_out));
1167 else if (remaining < 10)
1168 printk (KERN_INFO MYNAM ": %s/%s: IOC says %d buckets left. "
1169 "(priv->buckets_out = %d)\n",
1170 IOC_AND_NETDEV_NAMES_s_s(dev),
1171 remaining, atomic_read(&priv->buckets_out));
1173 if ((remaining < priv->bucketthresh) &&
1174 ((atomic_read(&priv->buckets_out) - remaining) >
1175 MPT_LAN_BUCKETS_REMAIN_MISMATCH_THRESH)) {
1177 printk (KERN_WARNING MYNAM " Mismatch between driver's "
1178 "buckets_out count and fw's BucketsRemaining "
1179 "count has crossed the threshold, issuing a "
1180 "LanReset to clear the fw's hashtable. You may "
1181 "want to check your /var/log/messages for \"CRC "
1182 "error\" event notifications.\n");
1185 mpt_lan_wake_post_buckets_task(dev, 0);
1188 return mpt_lan_receive_skb(dev, skb);
1191 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1192 /* Simple SGE's only at the moment */
1195 mpt_lan_post_receive_buckets(struct mpt_lan_priv *priv)
1197 struct net_device *dev = priv->dev;
1198 MPT_ADAPTER *mpt_dev = priv->mpt_dev;
1200 LANReceivePostRequest_t *pRecvReq;
1201 SGETransaction32_t *pTrans;
1202 SGESimple64_t *pSimple;
1203 struct sk_buff *skb;
1205 u32 curr, buckets, count, max;
1206 u32 len = (dev->mtu + dev->hard_header_len + 4);
1207 unsigned long flags;
1210 curr = atomic_read(&priv->buckets_out);
1211 buckets = (priv->max_buckets_out - curr);
1213 dioprintk((KERN_INFO MYNAM ": %s/%s: @%s, Start_buckets = %u, buckets_out = %u\n",
1214 IOC_AND_NETDEV_NAMES_s_s(dev),
1215 __FUNCTION__, buckets, curr));
1217 max = (mpt_dev->req_sz - MPT_LAN_RECEIVE_POST_REQUEST_SIZE) /
1218 (MPT_LAN_TRANSACTION32_SIZE + sizeof(SGESimple64_t));
1221 mf = mpt_get_msg_frame(LanCtx, mpt_dev);
1223 printk (KERN_ERR "%s: Unable to alloc request frame\n",
1225 dioprintk((KERN_ERR "%s: %u buckets remaining\n",
1226 __FUNCTION__, buckets));
1229 pRecvReq = (LANReceivePostRequest_t *) mf;
1235 pRecvReq->Function = MPI_FUNCTION_LAN_RECEIVE;
1236 pRecvReq->ChainOffset = 0;
1237 pRecvReq->MsgFlags = 0;
1238 pRecvReq->PortNumber = priv->pnum;
1240 pTrans = (SGETransaction32_t *) pRecvReq->SG_List;
1243 for (i = 0; i < count; i++) {
1246 spin_lock_irqsave(&priv->rxfidx_lock, flags);
1247 if (priv->mpt_rxfidx_tail < 0) {
1248 printk (KERN_ERR "%s: Can't alloc context\n",
1250 spin_unlock_irqrestore(&priv->rxfidx_lock,
1255 ctx = priv->mpt_rxfidx[priv->mpt_rxfidx_tail--];
1257 skb = priv->RcvCtl[ctx].skb;
1258 if (skb && (priv->RcvCtl[ctx].len != len)) {
1259 pci_unmap_single(mpt_dev->pcidev,
1260 priv->RcvCtl[ctx].dma,
1261 priv->RcvCtl[ctx].len,
1262 PCI_DMA_FROMDEVICE);
1263 dev_kfree_skb(priv->RcvCtl[ctx].skb);
1264 skb = priv->RcvCtl[ctx].skb = NULL;
1268 skb = dev_alloc_skb(len);
1270 printk (KERN_WARNING
1271 MYNAM "/%s: Can't alloc skb\n",
1273 priv->mpt_rxfidx[++priv->mpt_rxfidx_tail] = ctx;
1274 spin_unlock_irqrestore(&priv->rxfidx_lock, flags);
1278 dma = pci_map_single(mpt_dev->pcidev, skb->data,
1279 len, PCI_DMA_FROMDEVICE);
1281 priv->RcvCtl[ctx].skb = skb;
1282 priv->RcvCtl[ctx].dma = dma;
1283 priv->RcvCtl[ctx].len = len;
1286 spin_unlock_irqrestore(&priv->rxfidx_lock, flags);
1288 pTrans->ContextSize = sizeof(u32);
1289 pTrans->DetailsLength = 0;
1291 pTrans->TransactionContext[0] = cpu_to_le32(ctx);
1293 pSimple = (SGESimple64_t *) pTrans->TransactionDetails;
1295 pSimple->FlagsLength = cpu_to_le32(
1296 ((MPI_SGE_FLAGS_END_OF_BUFFER |
1297 MPI_SGE_FLAGS_SIMPLE_ELEMENT |
1298 MPI_SGE_FLAGS_64_BIT_ADDRESSING) << MPI_SGE_FLAGS_SHIFT) | len);
1299 pSimple->Address.Low = cpu_to_le32((u32) priv->RcvCtl[ctx].dma);
1300 if (sizeof(dma_addr_t) > sizeof(u32))
1301 pSimple->Address.High = cpu_to_le32((u32) ((u64) priv->RcvCtl[ctx].dma >> 32));
1303 pSimple->Address.High = 0;
1305 pTrans = (SGETransaction32_t *) (pSimple + 1);
1308 if (pSimple == NULL) {
1309 /**/ printk (KERN_WARNING MYNAM "/%s: No buckets posted\n",
1311 mpt_free_msg_frame(mpt_dev, mf);
1315 pSimple->FlagsLength |= cpu_to_le32(MPI_SGE_FLAGS_END_OF_LIST << MPI_SGE_FLAGS_SHIFT);
1317 pRecvReq->BucketCount = cpu_to_le32(i);
1319 /* printk(KERN_INFO MYNAM ": posting buckets\n ");
1320 * for (i = 0; i < j + 2; i ++)
1321 * printk (" %08x", le32_to_cpu(msg[i]));
1325 mpt_put_msg_frame(LanCtx, mpt_dev, mf);
1327 priv->total_posted += i;
1329 atomic_add(i, &priv->buckets_out);
1333 dioprintk((KERN_INFO MYNAM "/%s: End_buckets = %u, priv->buckets_out = %u\n",
1334 __FUNCTION__, buckets, atomic_read(&priv->buckets_out)));
1335 dioprintk((KERN_INFO MYNAM "/%s: Posted %u buckets and received %u back\n",
1336 __FUNCTION__, priv->total_posted, priv->total_received));
1338 clear_bit(0, &priv->post_buckets_active);
1342 mpt_lan_post_receive_buckets_work(struct work_struct *work)
1344 mpt_lan_post_receive_buckets(container_of(work, struct mpt_lan_priv,
1345 post_buckets_task.work));
1348 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1349 static struct net_device *
1350 mpt_register_lan_device (MPT_ADAPTER *mpt_dev, int pnum)
1352 struct net_device *dev = alloc_fcdev(sizeof(struct mpt_lan_priv));
1353 struct mpt_lan_priv *priv = NULL;
1354 u8 HWaddr[FC_ALEN], *a;
1359 dev->mtu = MPT_LAN_MTU;
1361 priv = netdev_priv(dev);
1364 priv->mpt_dev = mpt_dev;
1367 memset(&priv->post_buckets_task, 0, sizeof(priv->post_buckets_task));
1368 INIT_DELAYED_WORK(&priv->post_buckets_task,
1369 mpt_lan_post_receive_buckets_work);
1370 priv->post_buckets_active = 0;
1372 dlprintk((KERN_INFO MYNAM "@%d: bucketlen = %d\n",
1373 __LINE__, dev->mtu + dev->hard_header_len + 4));
1375 atomic_set(&priv->buckets_out, 0);
1376 priv->total_posted = 0;
1377 priv->total_received = 0;
1378 priv->max_buckets_out = max_buckets_out;
1379 if (mpt_dev->pfacts[0].MaxLanBuckets < max_buckets_out)
1380 priv->max_buckets_out = mpt_dev->pfacts[0].MaxLanBuckets;
1382 dlprintk((KERN_INFO MYNAM "@%d: MaxLanBuckets=%d, max_buckets_out/priv=%d/%d\n",
1384 mpt_dev->pfacts[0].MaxLanBuckets,
1386 priv->max_buckets_out));
1388 priv->bucketthresh = priv->max_buckets_out * 2 / 3;
1389 spin_lock_init(&priv->txfidx_lock);
1390 spin_lock_init(&priv->rxfidx_lock);
1392 memset(&priv->stats, 0, sizeof(priv->stats));
1394 /* Grab pre-fetched LANPage1 stuff. :-) */
1395 a = (u8 *) &mpt_dev->lan_cnfg_page1.HardwareAddressLow;
1404 dev->addr_len = FC_ALEN;
1405 memcpy(dev->dev_addr, HWaddr, FC_ALEN);
1406 memset(dev->broadcast, 0xff, FC_ALEN);
1408 /* The Tx queue is 127 deep on the 909.
1409 * Give ourselves some breathing room.
1411 priv->tx_max_out = (tx_max_out_p <= MPT_TX_MAX_OUT_LIM) ?
1412 tx_max_out_p : MPT_TX_MAX_OUT_LIM;
1414 dev->open = mpt_lan_open;
1415 dev->stop = mpt_lan_close;
1416 dev->get_stats = mpt_lan_get_stats;
1417 dev->set_multicast_list = NULL;
1418 dev->change_mtu = mpt_lan_change_mtu;
1419 dev->hard_start_xmit = mpt_lan_sdu_send;
1421 /* Not in 2.3.42. Need 2.3.45+ */
1422 dev->tx_timeout = mpt_lan_tx_timeout;
1423 dev->watchdog_timeo = MPT_LAN_TX_TIMEOUT;
1425 dlprintk((KERN_INFO MYNAM ": Finished registering dev "
1426 "and setting initial values\n"));
1428 SET_MODULE_OWNER(dev);
1430 if (register_netdev(dev) != 0) {
1438 mptlan_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1440 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1441 struct net_device *dev;
1444 for (i = 0; i < ioc->facts.NumberOfPorts; i++) {
1445 printk(KERN_INFO MYNAM ": %s: PortNum=%x, "
1446 "ProtocolFlags=%02Xh (%c%c%c%c)\n",
1447 ioc->name, ioc->pfacts[i].PortNumber,
1448 ioc->pfacts[i].ProtocolFlags,
1449 MPT_PROTOCOL_FLAGS_c_c_c_c(
1450 ioc->pfacts[i].ProtocolFlags));
1452 if (!(ioc->pfacts[i].ProtocolFlags &
1453 MPI_PORTFACTS_PROTOCOL_LAN)) {
1454 printk(KERN_INFO MYNAM ": %s: Hmmm... LAN protocol "
1455 "seems to be disabled on this adapter port!\n",
1460 dev = mpt_register_lan_device(ioc, i);
1462 printk(KERN_ERR MYNAM ": %s: Unable to register "
1463 "port%d as a LAN device\n", ioc->name,
1464 ioc->pfacts[i].PortNumber);
1468 printk(KERN_INFO MYNAM ": %s: Fusion MPT LAN device "
1469 "registered as '%s'\n", ioc->name, dev->name);
1470 printk(KERN_INFO MYNAM ": %s/%s: "
1471 "LanAddr = %02X:%02X:%02X:%02X:%02X:%02X\n",
1472 IOC_AND_NETDEV_NAMES_s_s(dev),
1473 dev->dev_addr[0], dev->dev_addr[1],
1474 dev->dev_addr[2], dev->dev_addr[3],
1475 dev->dev_addr[4], dev->dev_addr[5]);
1486 mptlan_remove(struct pci_dev *pdev)
1488 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1489 struct net_device *dev = ioc->netdev;
1492 unregister_netdev(dev);
1497 static struct mpt_pci_driver mptlan_driver = {
1498 .probe = mptlan_probe,
1499 .remove = mptlan_remove,
1502 static int __init mpt_lan_init (void)
1504 show_mptmod_ver(LANAME, LANVER);
1506 if ((LanCtx = mpt_register(lan_reply, MPTLAN_DRIVER)) <= 0) {
1507 printk (KERN_ERR MYNAM ": Failed to register with MPT base driver\n");
1511 /* Set the callback index to be used by driver core for turbo replies */
1512 mpt_lan_index = LanCtx;
1514 dlprintk((KERN_INFO MYNAM ": assigned context of %d\n", LanCtx));
1516 if (mpt_reset_register(LanCtx, mpt_lan_ioc_reset)) {
1517 printk(KERN_ERR MYNAM ": Eieee! unable to register a reset "
1518 "handler with mptbase! The world is at an end! "
1519 "Everything is fading to black! Goodbye.\n");
1523 dlprintk((KERN_INFO MYNAM ": Registered for IOC reset notifications\n"));
1525 if (mpt_device_driver_register(&mptlan_driver, MPTLAN_DRIVER))
1526 dprintk((KERN_INFO MYNAM ": failed to register dd callbacks\n"));
1530 static void __exit mpt_lan_exit(void)
1532 mpt_device_driver_deregister(MPTLAN_DRIVER);
1533 mpt_reset_deregister(LanCtx);
1536 mpt_deregister(LanCtx);
1542 module_init(mpt_lan_init);
1543 module_exit(mpt_lan_exit);
1545 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1546 static unsigned short
1547 mpt_lan_type_trans(struct sk_buff *skb, struct net_device *dev)
1549 struct mpt_lan_ohdr *fch = (struct mpt_lan_ohdr *)skb->data;
1550 struct fcllc *fcllc;
1552 skb->mac.raw = skb->data;
1553 skb_pull(skb, sizeof(struct mpt_lan_ohdr));
1555 if (fch->dtype == htons(0xffff)) {
1556 u32 *p = (u32 *) fch;
1563 printk (KERN_WARNING MYNAM ": %s: WARNING - Broadcast swap F/W bug detected!\n",
1564 NETDEV_PTR_TO_IOC_NAME_s(dev));
1565 printk (KERN_WARNING MYNAM ": Please update sender @ MAC_addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
1566 fch->saddr[0], fch->saddr[1], fch->saddr[2],
1567 fch->saddr[3], fch->saddr[4], fch->saddr[5]);
1570 if (*fch->daddr & 1) {
1571 if (!memcmp(fch->daddr, dev->broadcast, FC_ALEN)) {
1572 skb->pkt_type = PACKET_BROADCAST;
1574 skb->pkt_type = PACKET_MULTICAST;
1577 if (memcmp(fch->daddr, dev->dev_addr, FC_ALEN)) {
1578 skb->pkt_type = PACKET_OTHERHOST;
1580 skb->pkt_type = PACKET_HOST;
1584 fcllc = (struct fcllc *)skb->data;
1586 #ifdef QLOGIC_NAA_WORKAROUND
1588 u16 source_naa = fch->stype, found = 0;
1590 /* Workaround for QLogic not following RFC 2625 in regards to the NAA
1593 if ((source_naa & 0xF000) == 0)
1594 source_naa = swab16(source_naa);
1596 if (fcllc->ethertype == htons(ETH_P_ARP))
1597 dlprintk ((KERN_INFO "mptlan/type_trans: got arp req/rep w/ naa of "
1598 "%04x.\n", source_naa));
1600 if ((fcllc->ethertype == htons(ETH_P_ARP)) &&
1601 ((source_naa >> 12) != MPT_LAN_NAA_RFC2625)){
1602 struct NAA_Hosed *nh, *prevnh;
1605 dlprintk ((KERN_INFO "mptlan/type_trans: ARP Req/Rep from "
1606 "system with non-RFC 2625 NAA value (%04x).\n",
1609 write_lock_irq(&bad_naa_lock);
1610 for (prevnh = nh = mpt_bad_naa; nh != NULL;
1611 prevnh=nh, nh=nh->next) {
1612 if ((nh->ieee[0] == fch->saddr[0]) &&
1613 (nh->ieee[1] == fch->saddr[1]) &&
1614 (nh->ieee[2] == fch->saddr[2]) &&
1615 (nh->ieee[3] == fch->saddr[3]) &&
1616 (nh->ieee[4] == fch->saddr[4]) &&
1617 (nh->ieee[5] == fch->saddr[5])) {
1619 dlprintk ((KERN_INFO "mptlan/type_trans: ARP Re"
1620 "q/Rep w/ bad NAA from system already"
1626 if ((!found) && (nh == NULL)) {
1628 nh = kmalloc(sizeof(struct NAA_Hosed), GFP_KERNEL);
1629 dlprintk ((KERN_INFO "mptlan/type_trans: ARP Req/Rep w/"
1630 " bad NAA from system not yet in DB.\n"));
1639 nh->NAA = source_naa; /* Set the S_NAA value. */
1640 for (i = 0; i < FC_ALEN; i++)
1641 nh->ieee[i] = fch->saddr[i];
1642 dlprintk ((KERN_INFO "Got ARP from %02x:%02x:%02x:%02x:"
1643 "%02x:%02x with non-compliant S_NAA value.\n",
1644 fch->saddr[0], fch->saddr[1], fch->saddr[2],
1645 fch->saddr[3], fch->saddr[4],fch->saddr[5]));
1647 printk (KERN_ERR "mptlan/type_trans: Unable to"
1648 " kmalloc a NAA_Hosed struct.\n");
1650 } else if (!found) {
1651 printk (KERN_ERR "mptlan/type_trans: found not"
1652 " set, but nh isn't null. Evil "
1653 "funkiness abounds.\n");
1655 write_unlock_irq(&bad_naa_lock);
1660 /* Strip the SNAP header from ARP packets since we don't
1661 * pass them through to the 802.2/SNAP layers.
1663 if (fcllc->dsap == EXTENDED_SAP &&
1664 (fcllc->ethertype == htons(ETH_P_IP) ||
1665 fcllc->ethertype == htons(ETH_P_ARP))) {
1666 skb_pull(skb, sizeof(struct fcllc));
1667 return fcllc->ethertype;
1670 return htons(ETH_P_802_2);
1673 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/