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-2005 LSI Logic Corporation
10 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; version 2 of the License.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
22 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
23 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
24 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
25 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
26 solely responsible for determining the appropriateness of using and
27 distributing the Program and assumes all risks associated with its
28 exercise of rights under this Agreement, including but not limited to
29 the risks and costs of program errors, damage to or loss of data,
30 programs or equipment, and unavailability or interruption of operations.
32 DISCLAIMER OF LIABILITY
33 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
34 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
36 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
37 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
38 USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
39 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
41 You should have received a copy of the GNU General Public License
42 along with this program; if not, write to the Free Software
43 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
46 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
48 * Define statements used for debugging
50 //#define MPT_LAN_IO_DEBUG
52 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
55 #include <linux/init.h>
56 #include <linux/module.h>
59 #define MYNAM "mptlan"
61 MODULE_LICENSE("GPL");
63 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
65 * MPT LAN message sizes without variable part.
67 #define MPT_LAN_RECEIVE_POST_REQUEST_SIZE \
68 (sizeof(LANReceivePostRequest_t) - sizeof(SGE_MPI_UNION))
70 #define MPT_LAN_TRANSACTION32_SIZE \
71 (sizeof(SGETransaction32_t) - sizeof(u32))
74 * Fusion MPT LAN private structures
80 struct NAA_Hosed *next;
83 struct BufferControl {
91 u8 pnum; /* Port number in the IOC. This is not a Unix network port! */
93 atomic_t buckets_out; /* number of unused buckets on IOC */
94 int bucketthresh; /* Send more when this many left */
96 int *mpt_txfidx; /* Free Tx Context list */
98 spinlock_t txfidx_lock;
100 int *mpt_rxfidx; /* Free Rx Context list */
102 spinlock_t rxfidx_lock;
104 struct BufferControl *RcvCtl; /* Receive BufferControl structs */
105 struct BufferControl *SendCtl; /* Send BufferControl structs */
107 int max_buckets_out; /* Max buckets to send to IOC */
108 int tx_max_out; /* IOC's Tx queue len */
112 struct net_device_stats stats; /* Per device statistics */
114 struct work_struct post_buckets_task;
115 unsigned long post_buckets_active;
118 struct mpt_lan_ohdr {
125 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
130 static int lan_reply (MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf,
131 MPT_FRAME_HDR *reply);
132 static int mpt_lan_open(struct net_device *dev);
133 static int mpt_lan_reset(struct net_device *dev);
134 static int mpt_lan_close(struct net_device *dev);
135 static void mpt_lan_post_receive_buckets(void *dev_id);
136 static void mpt_lan_wake_post_buckets_task(struct net_device *dev,
138 static int mpt_lan_receive_post_turbo(struct net_device *dev, u32 tmsg);
139 static int mpt_lan_receive_post_reply(struct net_device *dev,
140 LANReceivePostReply_t *pRecvRep);
141 static int mpt_lan_send_turbo(struct net_device *dev, u32 tmsg);
142 static int mpt_lan_send_reply(struct net_device *dev,
143 LANSendReply_t *pSendRep);
144 static int mpt_lan_ioc_reset(MPT_ADAPTER *ioc, int reset_phase);
145 static int mpt_lan_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply);
146 static unsigned short mpt_lan_type_trans(struct sk_buff *skb,
147 struct net_device *dev);
149 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
151 * Fusion MPT LAN private data
153 static int LanCtx = -1;
155 static u32 max_buckets_out = 127;
156 static u32 tx_max_out_p = 127 - 16;
158 #ifdef QLOGIC_NAA_WORKAROUND
159 static struct NAA_Hosed *mpt_bad_naa = NULL;
160 DEFINE_RWLOCK(bad_naa_lock);
163 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
165 * Fusion MPT LAN external data
167 extern int mpt_lan_index;
169 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
171 * lan_reply - Handle all data sent from the hardware.
172 * @ioc: Pointer to MPT_ADAPTER structure
173 * @mf: Pointer to original MPT request frame (NULL if TurboReply)
174 * @reply: Pointer to MPT reply frame
176 * Returns 1 indicating original alloc'd request frame ptr
177 * should be freed, or 0 if it shouldn't.
180 lan_reply (MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *reply)
182 struct net_device *dev = ioc->netdev;
183 int FreeReqFrame = 0;
185 dioprintk((KERN_INFO MYNAM ": %s/%s: Got reply.\n",
186 IOC_AND_NETDEV_NAMES_s_s(dev)));
188 // dioprintk((KERN_INFO MYNAM "@lan_reply: mf = %p, reply = %p\n",
192 u32 tmsg = CAST_PTR_TO_U32(reply);
194 dioprintk((KERN_INFO MYNAM ": %s/%s: @lan_reply, tmsg %08x\n",
195 IOC_AND_NETDEV_NAMES_s_s(dev),
198 switch (GET_LAN_FORM(tmsg)) {
200 // NOTE! (Optimization) First case here is now caught in
201 // mptbase.c::mpt_interrupt() routine and callcack here
202 // is now skipped for this case!
204 case LAN_REPLY_FORM_MESSAGE_CONTEXT:
205 // dioprintk((KERN_INFO MYNAM "/lan_reply: "
206 // "MessageContext turbo reply received\n"));
211 case LAN_REPLY_FORM_SEND_SINGLE:
212 // dioprintk((MYNAM "/lan_reply: "
213 // "calling mpt_lan_send_reply (turbo)\n"));
215 // Potential BUG here?
216 // FreeReqFrame = mpt_lan_send_turbo(dev, tmsg);
217 // If/when mpt_lan_send_turbo would return 1 here,
218 // calling routine (mptbase.c|mpt_interrupt)
219 // would Oops because mf has already been set
220 // to NULL. So after return from this func,
221 // mpt_interrupt() will attempt to put (NULL) mf ptr
222 // item back onto its adapter FreeQ - Oops!:-(
223 // It's Ok, since mpt_lan_send_turbo() *currently*
224 // always returns 0, but..., just in case:
226 (void) mpt_lan_send_turbo(dev, tmsg);
231 case LAN_REPLY_FORM_RECEIVE_SINGLE:
232 // dioprintk((KERN_INFO MYNAM "@lan_reply: "
233 // "rcv-Turbo = %08x\n", tmsg));
234 mpt_lan_receive_post_turbo(dev, tmsg);
238 printk (KERN_ERR MYNAM "/lan_reply: Got a turbo reply "
239 "that I don't know what to do with\n");
241 /* CHECKME! Hmmm... FreeReqFrame is 0 here; is that right? */
249 // msg = (u32 *) reply;
250 // dioprintk((KERN_INFO MYNAM "@lan_reply: msg = %08x %08x %08x %08x\n",
251 // le32_to_cpu(msg[0]), le32_to_cpu(msg[1]),
252 // le32_to_cpu(msg[2]), le32_to_cpu(msg[3])));
253 // dioprintk((KERN_INFO MYNAM "@lan_reply: Function = %02xh\n",
254 // reply->u.hdr.Function));
256 switch (reply->u.hdr.Function) {
258 case MPI_FUNCTION_LAN_SEND:
260 LANSendReply_t *pSendRep;
262 pSendRep = (LANSendReply_t *) reply;
263 FreeReqFrame = mpt_lan_send_reply(dev, pSendRep);
267 case MPI_FUNCTION_LAN_RECEIVE:
269 LANReceivePostReply_t *pRecvRep;
271 pRecvRep = (LANReceivePostReply_t *) reply;
272 if (pRecvRep->NumberOfContexts) {
273 mpt_lan_receive_post_reply(dev, pRecvRep);
274 if (!(pRecvRep->MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY))
277 dioprintk((KERN_INFO MYNAM "@lan_reply: zero context "
278 "ReceivePostReply received.\n"));
282 case MPI_FUNCTION_LAN_RESET:
283 /* Just a default reply. Might want to check it to
284 * make sure that everything went ok.
289 case MPI_FUNCTION_EVENT_NOTIFICATION:
290 case MPI_FUNCTION_EVENT_ACK:
291 /* _EVENT_NOTIFICATION should NOT come down this path any more.
292 * Should be routed to mpt_lan_event_process(), but just in case...
298 printk (KERN_ERR MYNAM "/lan_reply: Got a non-turbo "
299 "reply that I don't know what to do with\n");
301 /* CHECKME! Hmmm... FreeReqFrame is 0 here; is that right? */
310 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
312 mpt_lan_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
314 struct net_device *dev = ioc->netdev;
315 struct mpt_lan_priv *priv = netdev_priv(dev);
317 dlprintk((KERN_INFO MYNAM ": IOC %s_reset routed to LAN driver!\n",
318 reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
319 reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
321 if (priv->mpt_rxfidx == NULL)
324 if (reset_phase == MPT_IOC_SETUP_RESET) {
326 } else if (reset_phase == MPT_IOC_PRE_RESET) {
330 netif_stop_queue(dev);
332 dlprintk ((KERN_INFO "mptlan/ioc_reset: called netif_stop_queue for %s.\n", dev->name));
334 atomic_set(&priv->buckets_out, 0);
336 /* Reset Rx Free Tail index and re-populate the queue. */
337 spin_lock_irqsave(&priv->rxfidx_lock, flags);
338 priv->mpt_rxfidx_tail = -1;
339 for (i = 0; i < priv->max_buckets_out; i++)
340 priv->mpt_rxfidx[++priv->mpt_rxfidx_tail] = i;
341 spin_unlock_irqrestore(&priv->rxfidx_lock, flags);
343 mpt_lan_post_receive_buckets(dev);
344 netif_wake_queue(dev);
350 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
352 mpt_lan_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
354 dlprintk((KERN_INFO MYNAM ": MPT event routed to LAN driver!\n"));
356 switch (le32_to_cpu(pEvReply->Event)) {
357 case MPI_EVENT_NONE: /* 00 */
358 case MPI_EVENT_LOG_DATA: /* 01 */
359 case MPI_EVENT_STATE_CHANGE: /* 02 */
360 case MPI_EVENT_UNIT_ATTENTION: /* 03 */
361 case MPI_EVENT_IOC_BUS_RESET: /* 04 */
362 case MPI_EVENT_EXT_BUS_RESET: /* 05 */
363 case MPI_EVENT_RESCAN: /* 06 */
364 /* Ok, do we need to do anything here? As far as
365 I can tell, this is when a new device gets added
367 case MPI_EVENT_LINK_STATUS_CHANGE: /* 07 */
368 case MPI_EVENT_LOOP_STATE_CHANGE: /* 08 */
369 case MPI_EVENT_LOGOUT: /* 09 */
370 case MPI_EVENT_EVENT_CHANGE: /* 0A */
376 * NOTE: pEvent->AckRequired handling now done in mptbase.c;
377 * Do NOT do it here now!
383 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
385 mpt_lan_open(struct net_device *dev)
387 struct mpt_lan_priv *priv = netdev_priv(dev);
390 if (mpt_lan_reset(dev) != 0) {
391 MPT_ADAPTER *mpt_dev = priv->mpt_dev;
393 printk (KERN_WARNING MYNAM "/lan_open: lan_reset failed.");
396 printk ("The ioc is active. Perhaps it needs to be"
399 printk ("The ioc in inactive, most likely in the "
400 "process of being reset. Please try again in "
404 priv->mpt_txfidx = kmalloc(priv->tx_max_out * sizeof(int), GFP_KERNEL);
405 if (priv->mpt_txfidx == NULL)
407 priv->mpt_txfidx_tail = -1;
409 priv->SendCtl = kmalloc(priv->tx_max_out * sizeof(struct BufferControl),
411 if (priv->SendCtl == NULL)
413 for (i = 0; i < priv->tx_max_out; i++) {
414 memset(&priv->SendCtl[i], 0, sizeof(struct BufferControl));
415 priv->mpt_txfidx[++priv->mpt_txfidx_tail] = i;
418 dlprintk((KERN_INFO MYNAM "@lo: Finished initializing SendCtl\n"));
420 priv->mpt_rxfidx = kmalloc(priv->max_buckets_out * sizeof(int),
422 if (priv->mpt_rxfidx == NULL)
424 priv->mpt_rxfidx_tail = -1;
426 priv->RcvCtl = kmalloc(priv->max_buckets_out *
427 sizeof(struct BufferControl),
429 if (priv->RcvCtl == NULL)
431 for (i = 0; i < priv->max_buckets_out; i++) {
432 memset(&priv->RcvCtl[i], 0, sizeof(struct BufferControl));
433 priv->mpt_rxfidx[++priv->mpt_rxfidx_tail] = i;
436 /**/ dlprintk((KERN_INFO MYNAM "/lo: txfidx contains - "));
437 /**/ for (i = 0; i < priv->tx_max_out; i++)
438 /**/ dlprintk((" %xh", priv->mpt_txfidx[i]));
439 /**/ dlprintk(("\n"));
441 dlprintk((KERN_INFO MYNAM "/lo: Finished initializing RcvCtl\n"));
443 mpt_lan_post_receive_buckets(dev);
444 printk(KERN_INFO MYNAM ": %s/%s: interface up & active\n",
445 IOC_AND_NETDEV_NAMES_s_s(dev));
447 if (mpt_event_register(LanCtx, mpt_lan_event_process) != 0) {
448 printk (KERN_WARNING MYNAM "/lo: Unable to register for Event"
449 " Notifications. This is a bad thing! We're not going "
450 "to go ahead, but I'd be leery of system stability at "
454 netif_start_queue(dev);
455 dlprintk((KERN_INFO MYNAM "/lo: Done.\n"));
459 kfree(priv->mpt_rxfidx);
460 priv->mpt_rxfidx = NULL;
462 kfree(priv->SendCtl);
463 priv->SendCtl = NULL;
465 kfree(priv->mpt_txfidx);
466 priv->mpt_txfidx = NULL;
470 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
471 /* Send a LanReset message to the FW. This should result in the FW returning
472 any buckets it still has. */
474 mpt_lan_reset(struct net_device *dev)
477 LANResetRequest_t *pResetReq;
478 struct mpt_lan_priv *priv = netdev_priv(dev);
480 mf = mpt_get_msg_frame(LanCtx, priv->mpt_dev);
483 /* dlprintk((KERN_ERR MYNAM "/reset: Evil funkiness abounds! "
484 "Unable to allocate a request frame.\n"));
489 pResetReq = (LANResetRequest_t *) mf;
491 pResetReq->Function = MPI_FUNCTION_LAN_RESET;
492 pResetReq->ChainOffset = 0;
493 pResetReq->Reserved = 0;
494 pResetReq->PortNumber = priv->pnum;
495 pResetReq->MsgFlags = 0;
496 pResetReq->Reserved2 = 0;
498 mpt_put_msg_frame(LanCtx, priv->mpt_dev, mf);
503 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
505 mpt_lan_close(struct net_device *dev)
507 struct mpt_lan_priv *priv = netdev_priv(dev);
508 MPT_ADAPTER *mpt_dev = priv->mpt_dev;
509 unsigned int timeout;
512 dlprintk((KERN_INFO MYNAM ": mpt_lan_close called\n"));
514 mpt_event_deregister(LanCtx);
516 dlprintk((KERN_INFO MYNAM ":lan_close: Posted %d buckets "
517 "since driver was loaded, %d still out\n",
518 priv->total_posted,atomic_read(&priv->buckets_out)));
520 netif_stop_queue(dev);
525 while (atomic_read(&priv->buckets_out) && --timeout) {
526 set_current_state(TASK_INTERRUPTIBLE);
530 for (i = 0; i < priv->max_buckets_out; i++) {
531 if (priv->RcvCtl[i].skb != NULL) {
532 /**/ dlprintk((KERN_INFO MYNAM "/lan_close: bucket %05x "
533 /**/ "is still out\n", i));
534 pci_unmap_single(mpt_dev->pcidev, priv->RcvCtl[i].dma,
537 dev_kfree_skb(priv->RcvCtl[i].skb);
542 kfree(priv->mpt_rxfidx);
544 for (i = 0; i < priv->tx_max_out; i++) {
545 if (priv->SendCtl[i].skb != NULL) {
546 pci_unmap_single(mpt_dev->pcidev, priv->SendCtl[i].dma,
547 priv->SendCtl[i].len,
549 dev_kfree_skb(priv->SendCtl[i].skb);
553 kfree(priv->SendCtl);
554 kfree(priv->mpt_txfidx);
556 atomic_set(&priv->buckets_out, 0);
558 printk(KERN_INFO MYNAM ": %s/%s: interface down & inactive\n",
559 IOC_AND_NETDEV_NAMES_s_s(dev));
564 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
565 static struct net_device_stats *
566 mpt_lan_get_stats(struct net_device *dev)
568 struct mpt_lan_priv *priv = netdev_priv(dev);
570 return (struct net_device_stats *) &priv->stats;
573 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
575 mpt_lan_change_mtu(struct net_device *dev, int new_mtu)
577 if ((new_mtu < MPT_LAN_MIN_MTU) || (new_mtu > MPT_LAN_MAX_MTU))
583 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
584 /* Tx timeout handler. */
586 mpt_lan_tx_timeout(struct net_device *dev)
588 struct mpt_lan_priv *priv = netdev_priv(dev);
589 MPT_ADAPTER *mpt_dev = priv->mpt_dev;
591 if (mpt_dev->active) {
592 dlprintk (("mptlan/tx_timeout: calling netif_wake_queue for %s.\n", dev->name));
593 netif_wake_queue(dev);
597 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
600 mpt_lan_send_turbo(struct net_device *dev, u32 tmsg)
602 struct mpt_lan_priv *priv = netdev_priv(dev);
603 MPT_ADAPTER *mpt_dev = priv->mpt_dev;
604 struct sk_buff *sent;
608 ctx = GET_LAN_BUFFER_CONTEXT(tmsg);
609 sent = priv->SendCtl[ctx].skb;
611 priv->stats.tx_packets++;
612 priv->stats.tx_bytes += sent->len;
614 dioprintk((KERN_INFO MYNAM ": %s/%s: @%s, skb %p sent.\n",
615 IOC_AND_NETDEV_NAMES_s_s(dev),
616 __FUNCTION__, sent));
618 priv->SendCtl[ctx].skb = NULL;
619 pci_unmap_single(mpt_dev->pcidev, priv->SendCtl[ctx].dma,
620 priv->SendCtl[ctx].len, PCI_DMA_TODEVICE);
621 dev_kfree_skb_irq(sent);
623 spin_lock_irqsave(&priv->txfidx_lock, flags);
624 priv->mpt_txfidx[++priv->mpt_txfidx_tail] = ctx;
625 spin_unlock_irqrestore(&priv->txfidx_lock, flags);
627 netif_wake_queue(dev);
631 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
633 mpt_lan_send_reply(struct net_device *dev, LANSendReply_t *pSendRep)
635 struct mpt_lan_priv *priv = netdev_priv(dev);
636 MPT_ADAPTER *mpt_dev = priv->mpt_dev;
637 struct sk_buff *sent;
639 int FreeReqFrame = 0;
644 count = pSendRep->NumberOfContexts;
646 dioprintk((KERN_INFO MYNAM ": send_reply: IOCStatus: %04x\n",
647 le16_to_cpu(pSendRep->IOCStatus)));
649 /* Add check for Loginfo Flag in IOCStatus */
651 switch (le16_to_cpu(pSendRep->IOCStatus) & MPI_IOCSTATUS_MASK) {
652 case MPI_IOCSTATUS_SUCCESS:
653 priv->stats.tx_packets += count;
656 case MPI_IOCSTATUS_LAN_CANCELED:
657 case MPI_IOCSTATUS_LAN_TRANSMIT_ABORTED:
660 case MPI_IOCSTATUS_INVALID_SGL:
661 priv->stats.tx_errors += count;
662 printk (KERN_ERR MYNAM ": %s/%s: ERROR - Invalid SGL sent to IOC!\n",
663 IOC_AND_NETDEV_NAMES_s_s(dev));
667 priv->stats.tx_errors += count;
671 pContext = &pSendRep->BufferContext;
673 spin_lock_irqsave(&priv->txfidx_lock, flags);
675 ctx = GET_LAN_BUFFER_CONTEXT(le32_to_cpu(*pContext));
677 sent = priv->SendCtl[ctx].skb;
678 priv->stats.tx_bytes += sent->len;
680 dioprintk((KERN_INFO MYNAM ": %s/%s: @%s, skb %p sent.\n",
681 IOC_AND_NETDEV_NAMES_s_s(dev),
682 __FUNCTION__, sent));
684 priv->SendCtl[ctx].skb = NULL;
685 pci_unmap_single(mpt_dev->pcidev, priv->SendCtl[ctx].dma,
686 priv->SendCtl[ctx].len, PCI_DMA_TODEVICE);
687 dev_kfree_skb_irq(sent);
689 priv->mpt_txfidx[++priv->mpt_txfidx_tail] = ctx;
694 spin_unlock_irqrestore(&priv->txfidx_lock, flags);
697 if (!(pSendRep->MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY))
700 netif_wake_queue(dev);
704 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
706 mpt_lan_sdu_send (struct sk_buff *skb, struct net_device *dev)
708 struct mpt_lan_priv *priv = netdev_priv(dev);
709 MPT_ADAPTER *mpt_dev = priv->mpt_dev;
711 LANSendRequest_t *pSendReq;
712 SGETransaction32_t *pTrans;
713 SGESimple64_t *pSimple;
717 u16 cur_naa = 0x1000;
719 dioprintk((KERN_INFO MYNAM ": %s called, skb_addr = %p\n",
722 spin_lock_irqsave(&priv->txfidx_lock, flags);
723 if (priv->mpt_txfidx_tail < 0) {
724 netif_stop_queue(dev);
725 spin_unlock_irqrestore(&priv->txfidx_lock, flags);
727 printk (KERN_ERR "%s: no tx context available: %u\n",
728 __FUNCTION__, priv->mpt_txfidx_tail);
732 mf = mpt_get_msg_frame(LanCtx, mpt_dev);
734 netif_stop_queue(dev);
735 spin_unlock_irqrestore(&priv->txfidx_lock, flags);
737 printk (KERN_ERR "%s: Unable to alloc request frame\n",
742 ctx = priv->mpt_txfidx[priv->mpt_txfidx_tail--];
743 spin_unlock_irqrestore(&priv->txfidx_lock, flags);
745 // dioprintk((KERN_INFO MYNAM ": %s/%s: Creating new msg frame (send).\n",
746 // IOC_AND_NETDEV_NAMES_s_s(dev)));
748 pSendReq = (LANSendRequest_t *) mf;
750 /* Set the mac.raw pointer, since this apparently isn't getting
751 * done before we get the skb. Pull the data pointer past the mac data.
753 skb->mac.raw = skb->data;
756 dma = pci_map_single(mpt_dev->pcidev, skb->data, skb->len,
759 priv->SendCtl[ctx].skb = skb;
760 priv->SendCtl[ctx].dma = dma;
761 priv->SendCtl[ctx].len = skb->len;
764 pSendReq->Reserved = 0;
765 pSendReq->Function = MPI_FUNCTION_LAN_SEND;
766 pSendReq->ChainOffset = 0;
767 pSendReq->Reserved2 = 0;
768 pSendReq->MsgFlags = 0;
769 pSendReq->PortNumber = priv->pnum;
771 /* Transaction Context Element */
772 pTrans = (SGETransaction32_t *) pSendReq->SG_List;
774 /* No Flags, 8 bytes of Details, 32bit Context (bloody turbo replies) */
775 pTrans->ContextSize = sizeof(u32);
776 pTrans->DetailsLength = 2 * sizeof(u32);
778 pTrans->TransactionContext[0] = cpu_to_le32(ctx);
780 // dioprintk((KERN_INFO MYNAM ": %s/%s: BC = %08x, skb = %p, buff = %p\n",
781 // IOC_AND_NETDEV_NAMES_s_s(dev),
782 // ctx, skb, skb->data));
784 #ifdef QLOGIC_NAA_WORKAROUND
786 struct NAA_Hosed *nh;
788 /* Munge the NAA for Tx packets to QLogic boards, which don't follow
789 RFC 2625. The longer I look at this, the more my opinion of Qlogic
791 read_lock_irq(&bad_naa_lock);
792 for (nh = mpt_bad_naa; nh != NULL; nh=nh->next) {
793 if ((nh->ieee[0] == skb->mac.raw[0]) &&
794 (nh->ieee[1] == skb->mac.raw[1]) &&
795 (nh->ieee[2] == skb->mac.raw[2]) &&
796 (nh->ieee[3] == skb->mac.raw[3]) &&
797 (nh->ieee[4] == skb->mac.raw[4]) &&
798 (nh->ieee[5] == skb->mac.raw[5])) {
800 dlprintk ((KERN_INFO "mptlan/sdu_send: using NAA value "
801 "= %04x.\n", cur_naa));
805 read_unlock_irq(&bad_naa_lock);
809 pTrans->TransactionDetails[0] = cpu_to_le32((cur_naa << 16) |
810 (skb->mac.raw[0] << 8) |
811 (skb->mac.raw[1] << 0));
812 pTrans->TransactionDetails[1] = cpu_to_le32((skb->mac.raw[2] << 24) |
813 (skb->mac.raw[3] << 16) |
814 (skb->mac.raw[4] << 8) |
815 (skb->mac.raw[5] << 0));
817 pSimple = (SGESimple64_t *) &pTrans->TransactionDetails[2];
819 /* If we ever decide to send more than one Simple SGE per LANSend, then
820 we will need to make sure that LAST_ELEMENT only gets set on the
821 last one. Otherwise, bad voodoo and evil funkiness will commence. */
822 pSimple->FlagsLength = cpu_to_le32(
823 ((MPI_SGE_FLAGS_LAST_ELEMENT |
824 MPI_SGE_FLAGS_END_OF_BUFFER |
825 MPI_SGE_FLAGS_SIMPLE_ELEMENT |
826 MPI_SGE_FLAGS_SYSTEM_ADDRESS |
827 MPI_SGE_FLAGS_HOST_TO_IOC |
828 MPI_SGE_FLAGS_64_BIT_ADDRESSING |
829 MPI_SGE_FLAGS_END_OF_LIST) << MPI_SGE_FLAGS_SHIFT) |
831 pSimple->Address.Low = cpu_to_le32((u32) dma);
832 if (sizeof(dma_addr_t) > sizeof(u32))
833 pSimple->Address.High = cpu_to_le32((u32) ((u64) dma >> 32));
835 pSimple->Address.High = 0;
837 mpt_put_msg_frame (LanCtx, mpt_dev, mf);
838 dev->trans_start = jiffies;
840 dioprintk((KERN_INFO MYNAM ": %s/%s: Sending packet. FlagsLength = %08x.\n",
841 IOC_AND_NETDEV_NAMES_s_s(dev),
842 le32_to_cpu(pSimple->FlagsLength)));
847 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
849 mpt_lan_wake_post_buckets_task(struct net_device *dev, int priority)
851 * @priority: 0 = put it on the timer queue, 1 = put it on the immediate queue
854 struct mpt_lan_priv *priv = dev->priv;
856 if (test_and_set_bit(0, &priv->post_buckets_active) == 0) {
858 schedule_work(&priv->post_buckets_task);
860 schedule_delayed_work(&priv->post_buckets_task, 1);
861 dioprintk((KERN_INFO MYNAM ": post_buckets queued on "
864 dioprintk((KERN_INFO MYNAM ": %s/%s: Queued post_buckets task.\n",
865 IOC_AND_NETDEV_NAMES_s_s(dev) ));
869 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
871 mpt_lan_receive_skb(struct net_device *dev, struct sk_buff *skb)
873 struct mpt_lan_priv *priv = dev->priv;
875 skb->protocol = mpt_lan_type_trans(skb, dev);
877 dioprintk((KERN_INFO MYNAM ": %s/%s: Incoming packet (%d bytes) "
878 "delivered to upper level.\n",
879 IOC_AND_NETDEV_NAMES_s_s(dev), skb->len));
881 priv->stats.rx_bytes += skb->len;
882 priv->stats.rx_packets++;
887 dioprintk((MYNAM "/receive_skb: %d buckets remaining\n",
888 atomic_read(&priv->buckets_out)));
890 if (atomic_read(&priv->buckets_out) < priv->bucketthresh)
891 mpt_lan_wake_post_buckets_task(dev, 1);
893 dioprintk((KERN_INFO MYNAM "/receive_post_reply: %d buckets "
894 "remaining, %d received back since sod\n",
895 atomic_read(&priv->buckets_out), priv->total_received));
900 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
903 mpt_lan_receive_post_turbo(struct net_device *dev, u32 tmsg)
905 struct mpt_lan_priv *priv = dev->priv;
906 MPT_ADAPTER *mpt_dev = priv->mpt_dev;
907 struct sk_buff *skb, *old_skb;
911 ctx = GET_LAN_BUCKET_CONTEXT(tmsg);
912 skb = priv->RcvCtl[ctx].skb;
914 len = GET_LAN_PACKET_LENGTH(tmsg);
916 if (len < MPT_LAN_RX_COPYBREAK) {
919 skb = (struct sk_buff *)dev_alloc_skb(len);
921 printk (KERN_ERR MYNAM ": %s/%s: ERROR - Can't allocate skb! (%s@%d)\n",
922 IOC_AND_NETDEV_NAMES_s_s(dev),
927 pci_dma_sync_single_for_cpu(mpt_dev->pcidev, priv->RcvCtl[ctx].dma,
928 priv->RcvCtl[ctx].len, PCI_DMA_FROMDEVICE);
930 memcpy(skb_put(skb, len), old_skb->data, len);
932 pci_dma_sync_single_for_device(mpt_dev->pcidev, priv->RcvCtl[ctx].dma,
933 priv->RcvCtl[ctx].len, PCI_DMA_FROMDEVICE);
939 priv->RcvCtl[ctx].skb = NULL;
941 pci_unmap_single(mpt_dev->pcidev, priv->RcvCtl[ctx].dma,
942 priv->RcvCtl[ctx].len, PCI_DMA_FROMDEVICE);
945 spin_lock_irqsave(&priv->rxfidx_lock, flags);
946 priv->mpt_rxfidx[++priv->mpt_rxfidx_tail] = ctx;
947 spin_unlock_irqrestore(&priv->rxfidx_lock, flags);
949 atomic_dec(&priv->buckets_out);
950 priv->total_received++;
952 return mpt_lan_receive_skb(dev, skb);
955 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
957 mpt_lan_receive_post_free(struct net_device *dev,
958 LANReceivePostReply_t *pRecvRep)
960 struct mpt_lan_priv *priv = dev->priv;
961 MPT_ADAPTER *mpt_dev = priv->mpt_dev;
968 count = pRecvRep->NumberOfContexts;
970 /**/ dlprintk((KERN_INFO MYNAM "/receive_post_reply: "
971 "IOC returned %d buckets, freeing them...\n", count));
973 spin_lock_irqsave(&priv->rxfidx_lock, flags);
974 for (i = 0; i < count; i++) {
975 ctx = le32_to_cpu(pRecvRep->BucketContext[i]);
977 skb = priv->RcvCtl[ctx].skb;
979 // dlprintk((KERN_INFO MYNAM ": %s: dev_name = %s\n",
980 // IOC_AND_NETDEV_NAMES_s_s(dev)));
981 // dlprintk((KERN_INFO MYNAM "@rpr[2], priv = %p, buckets_out addr = %p",
982 // priv, &(priv->buckets_out)));
983 // dlprintk((KERN_INFO MYNAM "@rpr[2] TC + 3\n"));
985 priv->RcvCtl[ctx].skb = NULL;
986 pci_unmap_single(mpt_dev->pcidev, priv->RcvCtl[ctx].dma,
987 priv->RcvCtl[ctx].len, PCI_DMA_FROMDEVICE);
988 dev_kfree_skb_any(skb);
990 priv->mpt_rxfidx[++priv->mpt_rxfidx_tail] = ctx;
992 spin_unlock_irqrestore(&priv->rxfidx_lock, flags);
994 atomic_sub(count, &priv->buckets_out);
996 // for (i = 0; i < priv->max_buckets_out; i++)
997 // if (priv->RcvCtl[i].skb != NULL)
998 // dlprintk((KERN_INFO MYNAM "@rpr: bucket %03x "
999 // "is still out\n", i));
1001 /* dlprintk((KERN_INFO MYNAM "/receive_post_reply: freed %d buckets\n",
1004 /**/ dlprintk((KERN_INFO MYNAM "@receive_post_reply: %d buckets "
1005 /**/ "remaining, %d received back since sod.\n",
1006 /**/ atomic_read(&priv->buckets_out), priv->total_received));
1010 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1012 mpt_lan_receive_post_reply(struct net_device *dev,
1013 LANReceivePostReply_t *pRecvRep)
1015 struct mpt_lan_priv *priv = dev->priv;
1016 MPT_ADAPTER *mpt_dev = priv->mpt_dev;
1017 struct sk_buff *skb, *old_skb;
1018 unsigned long flags;
1019 u32 len, ctx, offset;
1020 u32 remaining = le32_to_cpu(pRecvRep->BucketsRemaining);
1024 dioprintk((KERN_INFO MYNAM ": mpt_lan_receive_post_reply called\n"));
1025 dioprintk((KERN_INFO MYNAM ": receive_post_reply: IOCStatus: %04x\n",
1026 le16_to_cpu(pRecvRep->IOCStatus)));
1028 if ((le16_to_cpu(pRecvRep->IOCStatus) & MPI_IOCSTATUS_MASK) ==
1029 MPI_IOCSTATUS_LAN_CANCELED)
1030 return mpt_lan_receive_post_free(dev, pRecvRep);
1032 len = le32_to_cpu(pRecvRep->PacketLength);
1034 printk (KERN_ERR MYNAM ": %s/%s: ERROR - Got a non-TURBO "
1035 "ReceivePostReply w/ PacketLength zero!\n",
1036 IOC_AND_NETDEV_NAMES_s_s(dev));
1037 printk (KERN_ERR MYNAM ": MsgFlags = %02x, IOCStatus = %04x\n",
1038 pRecvRep->MsgFlags, le16_to_cpu(pRecvRep->IOCStatus));
1042 ctx = le32_to_cpu(pRecvRep->BucketContext[0]);
1043 count = pRecvRep->NumberOfContexts;
1044 skb = priv->RcvCtl[ctx].skb;
1046 offset = le32_to_cpu(pRecvRep->PacketOffset);
1047 // if (offset != 0) {
1048 // printk (KERN_INFO MYNAM ": %s/%s: Got a ReceivePostReply "
1049 // "w/ PacketOffset %u\n",
1050 // IOC_AND_NETDEV_NAMES_s_s(dev),
1054 dioprintk((KERN_INFO MYNAM ": %s/%s: @rpr, offset = %d, len = %d\n",
1055 IOC_AND_NETDEV_NAMES_s_s(dev),
1061 // dioprintk((KERN_INFO MYNAM ": %s/%s: Multiple buckets returned "
1062 // "for single packet, concatenating...\n",
1063 // IOC_AND_NETDEV_NAMES_s_s(dev)));
1065 skb = (struct sk_buff *)dev_alloc_skb(len);
1067 printk (KERN_ERR MYNAM ": %s/%s: ERROR - Can't allocate skb! (%s@%d)\n",
1068 IOC_AND_NETDEV_NAMES_s_s(dev),
1069 __FILE__, __LINE__);
1073 spin_lock_irqsave(&priv->rxfidx_lock, flags);
1074 for (i = 0; i < count; i++) {
1076 ctx = le32_to_cpu(pRecvRep->BucketContext[i]);
1077 old_skb = priv->RcvCtl[ctx].skb;
1079 l = priv->RcvCtl[ctx].len;
1083 // dioprintk((KERN_INFO MYNAM ": %s/%s: Buckets = %d, len = %u\n",
1084 // IOC_AND_NETDEV_NAMES_s_s(dev),
1087 pci_dma_sync_single_for_cpu(mpt_dev->pcidev,
1088 priv->RcvCtl[ctx].dma,
1089 priv->RcvCtl[ctx].len,
1090 PCI_DMA_FROMDEVICE);
1091 memcpy(skb_put(skb, l), old_skb->data, l);
1093 pci_dma_sync_single_for_device(mpt_dev->pcidev,
1094 priv->RcvCtl[ctx].dma,
1095 priv->RcvCtl[ctx].len,
1096 PCI_DMA_FROMDEVICE);
1098 priv->mpt_rxfidx[++priv->mpt_rxfidx_tail] = ctx;
1101 spin_unlock_irqrestore(&priv->rxfidx_lock, flags);
1103 } else if (len < MPT_LAN_RX_COPYBREAK) {
1107 skb = (struct sk_buff *)dev_alloc_skb(len);
1109 printk (KERN_ERR MYNAM ": %s/%s: ERROR - Can't allocate skb! (%s@%d)\n",
1110 IOC_AND_NETDEV_NAMES_s_s(dev),
1111 __FILE__, __LINE__);
1115 pci_dma_sync_single_for_cpu(mpt_dev->pcidev,
1116 priv->RcvCtl[ctx].dma,
1117 priv->RcvCtl[ctx].len,
1118 PCI_DMA_FROMDEVICE);
1120 memcpy(skb_put(skb, len), old_skb->data, len);
1122 pci_dma_sync_single_for_device(mpt_dev->pcidev,
1123 priv->RcvCtl[ctx].dma,
1124 priv->RcvCtl[ctx].len,
1125 PCI_DMA_FROMDEVICE);
1127 spin_lock_irqsave(&priv->rxfidx_lock, flags);
1128 priv->mpt_rxfidx[++priv->mpt_rxfidx_tail] = ctx;
1129 spin_unlock_irqrestore(&priv->rxfidx_lock, flags);
1132 spin_lock_irqsave(&priv->rxfidx_lock, flags);
1134 priv->RcvCtl[ctx].skb = NULL;
1136 pci_unmap_single(mpt_dev->pcidev, priv->RcvCtl[ctx].dma,
1137 priv->RcvCtl[ctx].len, PCI_DMA_FROMDEVICE);
1138 priv->RcvCtl[ctx].dma = 0;
1140 priv->mpt_rxfidx[++priv->mpt_rxfidx_tail] = ctx;
1141 spin_unlock_irqrestore(&priv->rxfidx_lock, flags);
1146 atomic_sub(count, &priv->buckets_out);
1147 priv->total_received += count;
1149 if (priv->mpt_rxfidx_tail >= MPT_LAN_MAX_BUCKETS_OUT) {
1150 printk (KERN_ERR MYNAM ": %s/%s: Yoohoo! mpt_rxfidx_tail = %d, "
1151 "MPT_LAN_MAX_BUCKETS_OUT = %d\n",
1152 IOC_AND_NETDEV_NAMES_s_s(dev),
1153 priv->mpt_rxfidx_tail,
1154 MPT_LAN_MAX_BUCKETS_OUT);
1156 panic("Damn it Jim! I'm a doctor, not a programmer! "
1157 "Oh, wait a sec, I am a programmer. "
1158 "And, who's Jim?!?!\n"
1159 "Arrgghh! We've done it again!\n");
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(void *dev_id)
1197 struct net_device *dev = dev_id;
1198 struct mpt_lan_priv *priv = dev->priv;
1199 MPT_ADAPTER *mpt_dev = priv->mpt_dev;
1201 LANReceivePostRequest_t *pRecvReq;
1202 SGETransaction32_t *pTrans;
1203 SGESimple64_t *pSimple;
1204 struct sk_buff *skb;
1206 u32 curr, buckets, count, max;
1207 u32 len = (dev->mtu + dev->hard_header_len + 4);
1208 unsigned long flags;
1211 curr = atomic_read(&priv->buckets_out);
1212 buckets = (priv->max_buckets_out - curr);
1214 dioprintk((KERN_INFO MYNAM ": %s/%s: @%s, Start_buckets = %u, buckets_out = %u\n",
1215 IOC_AND_NETDEV_NAMES_s_s(dev),
1216 __FUNCTION__, buckets, curr));
1218 max = (mpt_dev->req_sz - MPT_LAN_RECEIVE_POST_REQUEST_SIZE) /
1219 (MPT_LAN_TRANSACTION32_SIZE + sizeof(SGESimple64_t));
1222 mf = mpt_get_msg_frame(LanCtx, mpt_dev);
1224 printk (KERN_ERR "%s: Unable to alloc request frame\n",
1226 dioprintk((KERN_ERR "%s: %u buckets remaining\n",
1227 __FUNCTION__, buckets));
1230 pRecvReq = (LANReceivePostRequest_t *) mf;
1236 pRecvReq->Function = MPI_FUNCTION_LAN_RECEIVE;
1237 pRecvReq->ChainOffset = 0;
1238 pRecvReq->MsgFlags = 0;
1239 pRecvReq->PortNumber = priv->pnum;
1241 pTrans = (SGETransaction32_t *) pRecvReq->SG_List;
1244 for (i = 0; i < count; i++) {
1247 spin_lock_irqsave(&priv->rxfidx_lock, flags);
1248 if (priv->mpt_rxfidx_tail < 0) {
1249 printk (KERN_ERR "%s: Can't alloc context\n",
1251 spin_unlock_irqrestore(&priv->rxfidx_lock,
1256 ctx = priv->mpt_rxfidx[priv->mpt_rxfidx_tail--];
1258 skb = priv->RcvCtl[ctx].skb;
1259 if (skb && (priv->RcvCtl[ctx].len != len)) {
1260 pci_unmap_single(mpt_dev->pcidev,
1261 priv->RcvCtl[ctx].dma,
1262 priv->RcvCtl[ctx].len,
1263 PCI_DMA_FROMDEVICE);
1264 dev_kfree_skb(priv->RcvCtl[ctx].skb);
1265 skb = priv->RcvCtl[ctx].skb = NULL;
1269 skb = dev_alloc_skb(len);
1271 printk (KERN_WARNING
1272 MYNAM "/%s: Can't alloc skb\n",
1274 priv->mpt_rxfidx[++priv->mpt_rxfidx_tail] = ctx;
1275 spin_unlock_irqrestore(&priv->rxfidx_lock, flags);
1279 dma = pci_map_single(mpt_dev->pcidev, skb->data,
1280 len, PCI_DMA_FROMDEVICE);
1282 priv->RcvCtl[ctx].skb = skb;
1283 priv->RcvCtl[ctx].dma = dma;
1284 priv->RcvCtl[ctx].len = len;
1287 spin_unlock_irqrestore(&priv->rxfidx_lock, flags);
1289 pTrans->ContextSize = sizeof(u32);
1290 pTrans->DetailsLength = 0;
1292 pTrans->TransactionContext[0] = cpu_to_le32(ctx);
1294 pSimple = (SGESimple64_t *) pTrans->TransactionDetails;
1296 pSimple->FlagsLength = cpu_to_le32(
1297 ((MPI_SGE_FLAGS_END_OF_BUFFER |
1298 MPI_SGE_FLAGS_SIMPLE_ELEMENT |
1299 MPI_SGE_FLAGS_64_BIT_ADDRESSING) << MPI_SGE_FLAGS_SHIFT) | len);
1300 pSimple->Address.Low = cpu_to_le32((u32) priv->RcvCtl[ctx].dma);
1301 if (sizeof(dma_addr_t) > sizeof(u32))
1302 pSimple->Address.High = cpu_to_le32((u32) ((u64) priv->RcvCtl[ctx].dma >> 32));
1304 pSimple->Address.High = 0;
1306 pTrans = (SGETransaction32_t *) (pSimple + 1);
1309 if (pSimple == NULL) {
1310 /**/ printk (KERN_WARNING MYNAM "/%s: No buckets posted\n",
1312 mpt_free_msg_frame(mpt_dev, mf);
1316 pSimple->FlagsLength |= cpu_to_le32(MPI_SGE_FLAGS_END_OF_LIST << MPI_SGE_FLAGS_SHIFT);
1318 pRecvReq->BucketCount = cpu_to_le32(i);
1320 /* printk(KERN_INFO MYNAM ": posting buckets\n ");
1321 * for (i = 0; i < j + 2; i ++)
1322 * printk (" %08x", le32_to_cpu(msg[i]));
1326 mpt_put_msg_frame(LanCtx, mpt_dev, mf);
1328 priv->total_posted += i;
1330 atomic_add(i, &priv->buckets_out);
1334 dioprintk((KERN_INFO MYNAM "/%s: End_buckets = %u, priv->buckets_out = %u\n",
1335 __FUNCTION__, buckets, atomic_read(&priv->buckets_out)));
1336 dioprintk((KERN_INFO MYNAM "/%s: Posted %u buckets and received %u back\n",
1337 __FUNCTION__, priv->total_posted, priv->total_received));
1339 clear_bit(0, &priv->post_buckets_active);
1342 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1343 static struct net_device *
1344 mpt_register_lan_device (MPT_ADAPTER *mpt_dev, int pnum)
1346 struct net_device *dev = alloc_fcdev(sizeof(struct mpt_lan_priv));
1347 struct mpt_lan_priv *priv = NULL;
1348 u8 HWaddr[FC_ALEN], *a;
1353 dev->mtu = MPT_LAN_MTU;
1355 priv = netdev_priv(dev);
1357 priv->mpt_dev = mpt_dev;
1360 memset(&priv->post_buckets_task, 0, sizeof(struct work_struct));
1361 INIT_WORK(&priv->post_buckets_task, mpt_lan_post_receive_buckets, dev);
1362 priv->post_buckets_active = 0;
1364 dlprintk((KERN_INFO MYNAM "@%d: bucketlen = %d\n",
1365 __LINE__, dev->mtu + dev->hard_header_len + 4));
1367 atomic_set(&priv->buckets_out, 0);
1368 priv->total_posted = 0;
1369 priv->total_received = 0;
1370 priv->max_buckets_out = max_buckets_out;
1371 if (mpt_dev->pfacts[0].MaxLanBuckets < max_buckets_out)
1372 priv->max_buckets_out = mpt_dev->pfacts[0].MaxLanBuckets;
1374 dlprintk((KERN_INFO MYNAM "@%d: MaxLanBuckets=%d, max_buckets_out/priv=%d/%d\n",
1376 mpt_dev->pfacts[0].MaxLanBuckets,
1378 priv->max_buckets_out));
1380 priv->bucketthresh = priv->max_buckets_out * 2 / 3;
1381 spin_lock_init(&priv->txfidx_lock);
1382 spin_lock_init(&priv->rxfidx_lock);
1384 memset(&priv->stats, 0, sizeof(priv->stats));
1386 /* Grab pre-fetched LANPage1 stuff. :-) */
1387 a = (u8 *) &mpt_dev->lan_cnfg_page1.HardwareAddressLow;
1396 dev->addr_len = FC_ALEN;
1397 memcpy(dev->dev_addr, HWaddr, FC_ALEN);
1398 memset(dev->broadcast, 0xff, FC_ALEN);
1400 /* The Tx queue is 127 deep on the 909.
1401 * Give ourselves some breathing room.
1403 priv->tx_max_out = (tx_max_out_p <= MPT_TX_MAX_OUT_LIM) ?
1404 tx_max_out_p : MPT_TX_MAX_OUT_LIM;
1406 dev->open = mpt_lan_open;
1407 dev->stop = mpt_lan_close;
1408 dev->get_stats = mpt_lan_get_stats;
1409 dev->set_multicast_list = NULL;
1410 dev->change_mtu = mpt_lan_change_mtu;
1411 dev->hard_start_xmit = mpt_lan_sdu_send;
1413 /* Not in 2.3.42. Need 2.3.45+ */
1414 dev->tx_timeout = mpt_lan_tx_timeout;
1415 dev->watchdog_timeo = MPT_LAN_TX_TIMEOUT;
1417 dlprintk((KERN_INFO MYNAM ": Finished registering dev "
1418 "and setting initial values\n"));
1420 SET_MODULE_OWNER(dev);
1422 if (register_netdev(dev) != 0) {
1430 mptlan_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1432 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1433 struct net_device *dev;
1436 for (i = 0; i < ioc->facts.NumberOfPorts; i++) {
1437 printk(KERN_INFO MYNAM ": %s: PortNum=%x, "
1438 "ProtocolFlags=%02Xh (%c%c%c%c)\n",
1439 ioc->name, ioc->pfacts[i].PortNumber,
1440 ioc->pfacts[i].ProtocolFlags,
1441 MPT_PROTOCOL_FLAGS_c_c_c_c(
1442 ioc->pfacts[i].ProtocolFlags));
1444 if (!(ioc->pfacts[i].ProtocolFlags &
1445 MPI_PORTFACTS_PROTOCOL_LAN)) {
1446 printk(KERN_INFO MYNAM ": %s: Hmmm... LAN protocol "
1447 "seems to be disabled on this adapter port!\n",
1452 dev = mpt_register_lan_device(ioc, i);
1454 printk(KERN_ERR MYNAM ": %s: Unable to register "
1455 "port%d as a LAN device\n", ioc->name,
1456 ioc->pfacts[i].PortNumber);
1460 printk(KERN_INFO MYNAM ": %s: Fusion MPT LAN device "
1461 "registered as '%s'\n", ioc->name, dev->name);
1462 printk(KERN_INFO MYNAM ": %s/%s: "
1463 "LanAddr = %02X:%02X:%02X:%02X:%02X:%02X\n",
1464 IOC_AND_NETDEV_NAMES_s_s(dev),
1465 dev->dev_addr[0], dev->dev_addr[1],
1466 dev->dev_addr[2], dev->dev_addr[3],
1467 dev->dev_addr[4], dev->dev_addr[5]);
1478 mptlan_remove(struct pci_dev *pdev)
1480 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1481 struct net_device *dev = ioc->netdev;
1484 unregister_netdev(dev);
1489 static struct mpt_pci_driver mptlan_driver = {
1490 .probe = mptlan_probe,
1491 .remove = mptlan_remove,
1494 static int __init mpt_lan_init (void)
1496 show_mptmod_ver(LANAME, LANVER);
1498 if ((LanCtx = mpt_register(lan_reply, MPTLAN_DRIVER)) <= 0) {
1499 printk (KERN_ERR MYNAM ": Failed to register with MPT base driver\n");
1503 /* Set the callback index to be used by driver core for turbo replies */
1504 mpt_lan_index = LanCtx;
1506 dlprintk((KERN_INFO MYNAM ": assigned context of %d\n", LanCtx));
1508 if (mpt_reset_register(LanCtx, mpt_lan_ioc_reset)) {
1509 printk(KERN_ERR MYNAM ": Eieee! unable to register a reset "
1510 "handler with mptbase! The world is at an end! "
1511 "Everything is fading to black! Goodbye.\n");
1515 dlprintk((KERN_INFO MYNAM ": Registered for IOC reset notifications\n"));
1517 if (mpt_device_driver_register(&mptlan_driver, MPTLAN_DRIVER))
1518 dprintk((KERN_INFO MYNAM ": failed to register dd callbacks\n"));
1522 static void __exit mpt_lan_exit(void)
1524 mpt_device_driver_deregister(MPTLAN_DRIVER);
1525 mpt_reset_deregister(LanCtx);
1528 mpt_deregister(LanCtx);
1534 module_init(mpt_lan_init);
1535 module_exit(mpt_lan_exit);
1537 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1538 static unsigned short
1539 mpt_lan_type_trans(struct sk_buff *skb, struct net_device *dev)
1541 struct mpt_lan_ohdr *fch = (struct mpt_lan_ohdr *)skb->data;
1542 struct fcllc *fcllc;
1544 skb->mac.raw = skb->data;
1545 skb_pull(skb, sizeof(struct mpt_lan_ohdr));
1547 if (fch->dtype == htons(0xffff)) {
1548 u32 *p = (u32 *) fch;
1555 printk (KERN_WARNING MYNAM ": %s: WARNING - Broadcast swap F/W bug detected!\n",
1556 NETDEV_PTR_TO_IOC_NAME_s(dev));
1557 printk (KERN_WARNING MYNAM ": Please update sender @ MAC_addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
1558 fch->saddr[0], fch->saddr[1], fch->saddr[2],
1559 fch->saddr[3], fch->saddr[4], fch->saddr[5]);
1562 if (*fch->daddr & 1) {
1563 if (!memcmp(fch->daddr, dev->broadcast, FC_ALEN)) {
1564 skb->pkt_type = PACKET_BROADCAST;
1566 skb->pkt_type = PACKET_MULTICAST;
1569 if (memcmp(fch->daddr, dev->dev_addr, FC_ALEN)) {
1570 skb->pkt_type = PACKET_OTHERHOST;
1572 skb->pkt_type = PACKET_HOST;
1576 fcllc = (struct fcllc *)skb->data;
1578 #ifdef QLOGIC_NAA_WORKAROUND
1580 u16 source_naa = fch->stype, found = 0;
1582 /* Workaround for QLogic not following RFC 2625 in regards to the NAA
1585 if ((source_naa & 0xF000) == 0)
1586 source_naa = swab16(source_naa);
1588 if (fcllc->ethertype == htons(ETH_P_ARP))
1589 dlprintk ((KERN_INFO "mptlan/type_trans: got arp req/rep w/ naa of "
1590 "%04x.\n", source_naa));
1592 if ((fcllc->ethertype == htons(ETH_P_ARP)) &&
1593 ((source_naa >> 12) != MPT_LAN_NAA_RFC2625)){
1594 struct NAA_Hosed *nh, *prevnh;
1597 dlprintk ((KERN_INFO "mptlan/type_trans: ARP Req/Rep from "
1598 "system with non-RFC 2625 NAA value (%04x).\n",
1601 write_lock_irq(&bad_naa_lock);
1602 for (prevnh = nh = mpt_bad_naa; nh != NULL;
1603 prevnh=nh, nh=nh->next) {
1604 if ((nh->ieee[0] == fch->saddr[0]) &&
1605 (nh->ieee[1] == fch->saddr[1]) &&
1606 (nh->ieee[2] == fch->saddr[2]) &&
1607 (nh->ieee[3] == fch->saddr[3]) &&
1608 (nh->ieee[4] == fch->saddr[4]) &&
1609 (nh->ieee[5] == fch->saddr[5])) {
1611 dlprintk ((KERN_INFO "mptlan/type_trans: ARP Re"
1612 "q/Rep w/ bad NAA from system already"
1618 if ((!found) && (nh == NULL)) {
1620 nh = kmalloc(sizeof(struct NAA_Hosed), GFP_KERNEL);
1621 dlprintk ((KERN_INFO "mptlan/type_trans: ARP Req/Rep w/"
1622 " bad NAA from system not yet in DB.\n"));
1631 nh->NAA = source_naa; /* Set the S_NAA value. */
1632 for (i = 0; i < FC_ALEN; i++)
1633 nh->ieee[i] = fch->saddr[i];
1634 dlprintk ((KERN_INFO "Got ARP from %02x:%02x:%02x:%02x:"
1635 "%02x:%02x with non-compliant S_NAA value.\n",
1636 fch->saddr[0], fch->saddr[1], fch->saddr[2],
1637 fch->saddr[3], fch->saddr[4],fch->saddr[5]));
1639 printk (KERN_ERR "mptlan/type_trans: Unable to"
1640 " kmalloc a NAA_Hosed struct.\n");
1642 } else if (!found) {
1643 printk (KERN_ERR "mptlan/type_trans: found not"
1644 " set, but nh isn't null. Evil "
1645 "funkiness abounds.\n");
1647 write_unlock_irq(&bad_naa_lock);
1652 /* Strip the SNAP header from ARP packets since we don't
1653 * pass them through to the 802.2/SNAP layers.
1655 if (fcllc->dsap == EXTENDED_SAP &&
1656 (fcllc->ethertype == htons(ETH_P_IP) ||
1657 fcllc->ethertype == htons(ETH_P_ARP))) {
1658 skb_pull(skb, sizeof(struct fcllc));
1659 return fcllc->ethertype;
1662 return htons(ETH_P_802_2);
1665 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/