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
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 my_VERSION MPT_LINUX_VERSION_COMMON
60 #define MYNAM "mptlan"
62 MODULE_LICENSE("GPL");
63 MODULE_VERSION(my_VERSION
);
65 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
67 * MPT LAN message sizes without variable part.
69 #define MPT_LAN_RECEIVE_POST_REQUEST_SIZE \
70 (sizeof(LANReceivePostRequest_t) - sizeof(SGE_MPI_UNION))
72 #define MPT_LAN_TRANSACTION32_SIZE \
73 (sizeof(SGETransaction32_t) - sizeof(u32))
76 * Fusion MPT LAN private structures
82 struct NAA_Hosed
*next
;
85 struct BufferControl
{
93 u8 pnum
; /* Port number in the IOC. This is not a Unix network port! */
95 atomic_t buckets_out
; /* number of unused buckets on IOC */
96 int bucketthresh
; /* Send more when this many left */
98 int *mpt_txfidx
; /* Free Tx Context list */
100 spinlock_t txfidx_lock
;
102 int *mpt_rxfidx
; /* Free Rx Context list */
104 spinlock_t rxfidx_lock
;
106 struct BufferControl
*RcvCtl
; /* Receive BufferControl structs */
107 struct BufferControl
*SendCtl
; /* Send BufferControl structs */
109 int max_buckets_out
; /* Max buckets to send to IOC */
110 int tx_max_out
; /* IOC's Tx queue len */
114 struct net_device_stats stats
; /* Per device statistics */
116 struct delayed_work post_buckets_task
;
117 struct net_device
*dev
;
118 unsigned long post_buckets_active
;
121 struct mpt_lan_ohdr
{
128 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
133 static int lan_reply (MPT_ADAPTER
*ioc
, MPT_FRAME_HDR
*mf
,
134 MPT_FRAME_HDR
*reply
);
135 static int mpt_lan_open(struct net_device
*dev
);
136 static int mpt_lan_reset(struct net_device
*dev
);
137 static int mpt_lan_close(struct net_device
*dev
);
138 static void mpt_lan_post_receive_buckets(struct mpt_lan_priv
*priv
);
139 static void mpt_lan_wake_post_buckets_task(struct net_device
*dev
,
141 static int mpt_lan_receive_post_turbo(struct net_device
*dev
, u32 tmsg
);
142 static int mpt_lan_receive_post_reply(struct net_device
*dev
,
143 LANReceivePostReply_t
*pRecvRep
);
144 static int mpt_lan_send_turbo(struct net_device
*dev
, u32 tmsg
);
145 static int mpt_lan_send_reply(struct net_device
*dev
,
146 LANSendReply_t
*pSendRep
);
147 static int mpt_lan_ioc_reset(MPT_ADAPTER
*ioc
, int reset_phase
);
148 static int mpt_lan_event_process(MPT_ADAPTER
*ioc
, EventNotificationReply_t
*pEvReply
);
149 static unsigned short mpt_lan_type_trans(struct sk_buff
*skb
,
150 struct net_device
*dev
);
152 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
154 * Fusion MPT LAN private data
156 static int LanCtx
= -1;
158 static u32 max_buckets_out
= 127;
159 static u32 tx_max_out_p
= 127 - 16;
161 #ifdef QLOGIC_NAA_WORKAROUND
162 static struct NAA_Hosed
*mpt_bad_naa
= NULL
;
163 DEFINE_RWLOCK(bad_naa_lock
);
166 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
168 * Fusion MPT LAN external data
170 extern int mpt_lan_index
;
172 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
174 * lan_reply - Handle all data sent from the hardware.
175 * @ioc: Pointer to MPT_ADAPTER structure
176 * @mf: Pointer to original MPT request frame (NULL if TurboReply)
177 * @reply: Pointer to MPT reply frame
179 * Returns 1 indicating original alloc'd request frame ptr
180 * should be freed, or 0 if it shouldn't.
183 lan_reply (MPT_ADAPTER
*ioc
, MPT_FRAME_HDR
*mf
, MPT_FRAME_HDR
*reply
)
185 struct net_device
*dev
= ioc
->netdev
;
186 int FreeReqFrame
= 0;
188 dioprintk((KERN_INFO MYNAM
": %s/%s: Got reply.\n",
189 IOC_AND_NETDEV_NAMES_s_s(dev
)));
191 // dioprintk((KERN_INFO MYNAM "@lan_reply: mf = %p, reply = %p\n",
195 u32 tmsg
= CAST_PTR_TO_U32(reply
);
197 dioprintk((KERN_INFO MYNAM
": %s/%s: @lan_reply, tmsg %08x\n",
198 IOC_AND_NETDEV_NAMES_s_s(dev
),
201 switch (GET_LAN_FORM(tmsg
)) {
203 // NOTE! (Optimization) First case here is now caught in
204 // mptbase.c::mpt_interrupt() routine and callcack here
205 // is now skipped for this case!
207 case LAN_REPLY_FORM_MESSAGE_CONTEXT
:
208 // dioprintk((KERN_INFO MYNAM "/lan_reply: "
209 // "MessageContext turbo reply received\n"));
214 case LAN_REPLY_FORM_SEND_SINGLE
:
215 // dioprintk((MYNAM "/lan_reply: "
216 // "calling mpt_lan_send_reply (turbo)\n"));
218 // Potential BUG here?
219 // FreeReqFrame = mpt_lan_send_turbo(dev, tmsg);
220 // If/when mpt_lan_send_turbo would return 1 here,
221 // calling routine (mptbase.c|mpt_interrupt)
222 // would Oops because mf has already been set
223 // to NULL. So after return from this func,
224 // mpt_interrupt() will attempt to put (NULL) mf ptr
225 // item back onto its adapter FreeQ - Oops!:-(
226 // It's Ok, since mpt_lan_send_turbo() *currently*
227 // always returns 0, but..., just in case:
229 (void) mpt_lan_send_turbo(dev
, tmsg
);
234 case LAN_REPLY_FORM_RECEIVE_SINGLE
:
235 // dioprintk((KERN_INFO MYNAM "@lan_reply: "
236 // "rcv-Turbo = %08x\n", tmsg));
237 mpt_lan_receive_post_turbo(dev
, tmsg
);
241 printk (KERN_ERR MYNAM
"/lan_reply: Got a turbo reply "
242 "that I don't know what to do with\n");
244 /* CHECKME! Hmmm... FreeReqFrame is 0 here; is that right? */
252 // msg = (u32 *) reply;
253 // dioprintk((KERN_INFO MYNAM "@lan_reply: msg = %08x %08x %08x %08x\n",
254 // le32_to_cpu(msg[0]), le32_to_cpu(msg[1]),
255 // le32_to_cpu(msg[2]), le32_to_cpu(msg[3])));
256 // dioprintk((KERN_INFO MYNAM "@lan_reply: Function = %02xh\n",
257 // reply->u.hdr.Function));
259 switch (reply
->u
.hdr
.Function
) {
261 case MPI_FUNCTION_LAN_SEND
:
263 LANSendReply_t
*pSendRep
;
265 pSendRep
= (LANSendReply_t
*) reply
;
266 FreeReqFrame
= mpt_lan_send_reply(dev
, pSendRep
);
270 case MPI_FUNCTION_LAN_RECEIVE
:
272 LANReceivePostReply_t
*pRecvRep
;
274 pRecvRep
= (LANReceivePostReply_t
*) reply
;
275 if (pRecvRep
->NumberOfContexts
) {
276 mpt_lan_receive_post_reply(dev
, pRecvRep
);
277 if (!(pRecvRep
->MsgFlags
& MPI_MSGFLAGS_CONTINUATION_REPLY
))
280 dioprintk((KERN_INFO MYNAM
"@lan_reply: zero context "
281 "ReceivePostReply received.\n"));
285 case MPI_FUNCTION_LAN_RESET
:
286 /* Just a default reply. Might want to check it to
287 * make sure that everything went ok.
292 case MPI_FUNCTION_EVENT_NOTIFICATION
:
293 case MPI_FUNCTION_EVENT_ACK
:
294 /* _EVENT_NOTIFICATION should NOT come down this path any more.
295 * Should be routed to mpt_lan_event_process(), but just in case...
301 printk (KERN_ERR MYNAM
"/lan_reply: Got a non-turbo "
302 "reply that I don't know what to do with\n");
304 /* CHECKME! Hmmm... FreeReqFrame is 0 here; is that right? */
313 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
315 mpt_lan_ioc_reset(MPT_ADAPTER
*ioc
, int reset_phase
)
317 struct net_device
*dev
= ioc
->netdev
;
318 struct mpt_lan_priv
*priv
;
323 priv
= netdev_priv(dev
);
325 dlprintk((KERN_INFO MYNAM
": IOC %s_reset routed to LAN driver!\n",
326 reset_phase
==MPT_IOC_SETUP_RESET
? "setup" : (
327 reset_phase
==MPT_IOC_PRE_RESET
? "pre" : "post")));
329 if (priv
->mpt_rxfidx
== NULL
)
332 if (reset_phase
== MPT_IOC_SETUP_RESET
) {
334 } else if (reset_phase
== MPT_IOC_PRE_RESET
) {
338 netif_stop_queue(dev
);
340 dlprintk ((KERN_INFO
"mptlan/ioc_reset: called netif_stop_queue for %s.\n", dev
->name
));
342 atomic_set(&priv
->buckets_out
, 0);
344 /* Reset Rx Free Tail index and re-populate the queue. */
345 spin_lock_irqsave(&priv
->rxfidx_lock
, flags
);
346 priv
->mpt_rxfidx_tail
= -1;
347 for (i
= 0; i
< priv
->max_buckets_out
; i
++)
348 priv
->mpt_rxfidx
[++priv
->mpt_rxfidx_tail
] = i
;
349 spin_unlock_irqrestore(&priv
->rxfidx_lock
, flags
);
351 mpt_lan_post_receive_buckets(priv
);
352 netif_wake_queue(dev
);
358 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
360 mpt_lan_event_process(MPT_ADAPTER
*ioc
, EventNotificationReply_t
*pEvReply
)
362 dlprintk((KERN_INFO MYNAM
": MPT event routed to LAN driver!\n"));
364 switch (le32_to_cpu(pEvReply
->Event
)) {
365 case MPI_EVENT_NONE
: /* 00 */
366 case MPI_EVENT_LOG_DATA
: /* 01 */
367 case MPI_EVENT_STATE_CHANGE
: /* 02 */
368 case MPI_EVENT_UNIT_ATTENTION
: /* 03 */
369 case MPI_EVENT_IOC_BUS_RESET
: /* 04 */
370 case MPI_EVENT_EXT_BUS_RESET
: /* 05 */
371 case MPI_EVENT_RESCAN
: /* 06 */
372 /* Ok, do we need to do anything here? As far as
373 I can tell, this is when a new device gets added
375 case MPI_EVENT_LINK_STATUS_CHANGE
: /* 07 */
376 case MPI_EVENT_LOOP_STATE_CHANGE
: /* 08 */
377 case MPI_EVENT_LOGOUT
: /* 09 */
378 case MPI_EVENT_EVENT_CHANGE
: /* 0A */
384 * NOTE: pEvent->AckRequired handling now done in mptbase.c;
385 * Do NOT do it here now!
391 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
393 mpt_lan_open(struct net_device
*dev
)
395 struct mpt_lan_priv
*priv
= netdev_priv(dev
);
398 if (mpt_lan_reset(dev
) != 0) {
399 MPT_ADAPTER
*mpt_dev
= priv
->mpt_dev
;
401 printk (KERN_WARNING MYNAM
"/lan_open: lan_reset failed.");
404 printk ("The ioc is active. Perhaps it needs to be"
407 printk ("The ioc in inactive, most likely in the "
408 "process of being reset. Please try again in "
412 priv
->mpt_txfidx
= kmalloc(priv
->tx_max_out
* sizeof(int), GFP_KERNEL
);
413 if (priv
->mpt_txfidx
== NULL
)
415 priv
->mpt_txfidx_tail
= -1;
417 priv
->SendCtl
= kcalloc(priv
->tx_max_out
, sizeof(struct BufferControl
),
419 if (priv
->SendCtl
== NULL
)
421 for (i
= 0; i
< priv
->tx_max_out
; i
++)
422 priv
->mpt_txfidx
[++priv
->mpt_txfidx_tail
] = i
;
424 dlprintk((KERN_INFO MYNAM
"@lo: Finished initializing SendCtl\n"));
426 priv
->mpt_rxfidx
= kmalloc(priv
->max_buckets_out
* sizeof(int),
428 if (priv
->mpt_rxfidx
== NULL
)
430 priv
->mpt_rxfidx_tail
= -1;
432 priv
->RcvCtl
= kcalloc(priv
->max_buckets_out
,
433 sizeof(struct BufferControl
),
435 if (priv
->RcvCtl
== NULL
)
437 for (i
= 0; i
< priv
->max_buckets_out
; i
++)
438 priv
->mpt_rxfidx
[++priv
->mpt_rxfidx_tail
] = i
;
440 /**/ dlprintk((KERN_INFO MYNAM
"/lo: txfidx contains - "));
441 /**/ for (i
= 0; i
< priv
->tx_max_out
; i
++)
442 /**/ dlprintk((" %xh", priv
->mpt_txfidx
[i
]));
443 /**/ dlprintk(("\n"));
445 dlprintk((KERN_INFO MYNAM
"/lo: Finished initializing RcvCtl\n"));
447 mpt_lan_post_receive_buckets(priv
);
448 printk(KERN_INFO MYNAM
": %s/%s: interface up & active\n",
449 IOC_AND_NETDEV_NAMES_s_s(dev
));
451 if (mpt_event_register(LanCtx
, mpt_lan_event_process
) != 0) {
452 printk (KERN_WARNING MYNAM
"/lo: Unable to register for Event"
453 " Notifications. This is a bad thing! We're not going "
454 "to go ahead, but I'd be leery of system stability at "
458 netif_start_queue(dev
);
459 dlprintk((KERN_INFO MYNAM
"/lo: Done.\n"));
463 kfree(priv
->mpt_rxfidx
);
464 priv
->mpt_rxfidx
= NULL
;
466 kfree(priv
->SendCtl
);
467 priv
->SendCtl
= NULL
;
469 kfree(priv
->mpt_txfidx
);
470 priv
->mpt_txfidx
= NULL
;
474 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
475 /* Send a LanReset message to the FW. This should result in the FW returning
476 any buckets it still has. */
478 mpt_lan_reset(struct net_device
*dev
)
481 LANResetRequest_t
*pResetReq
;
482 struct mpt_lan_priv
*priv
= netdev_priv(dev
);
484 mf
= mpt_get_msg_frame(LanCtx
, priv
->mpt_dev
);
487 /* dlprintk((KERN_ERR MYNAM "/reset: Evil funkiness abounds! "
488 "Unable to allocate a request frame.\n"));
493 pResetReq
= (LANResetRequest_t
*) mf
;
495 pResetReq
->Function
= MPI_FUNCTION_LAN_RESET
;
496 pResetReq
->ChainOffset
= 0;
497 pResetReq
->Reserved
= 0;
498 pResetReq
->PortNumber
= priv
->pnum
;
499 pResetReq
->MsgFlags
= 0;
500 pResetReq
->Reserved2
= 0;
502 mpt_put_msg_frame(LanCtx
, priv
->mpt_dev
, mf
);
507 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
509 mpt_lan_close(struct net_device
*dev
)
511 struct mpt_lan_priv
*priv
= netdev_priv(dev
);
512 MPT_ADAPTER
*mpt_dev
= priv
->mpt_dev
;
513 unsigned long timeout
;
516 dlprintk((KERN_INFO MYNAM
": mpt_lan_close called\n"));
518 mpt_event_deregister(LanCtx
);
520 dlprintk((KERN_INFO MYNAM
":lan_close: Posted %d buckets "
521 "since driver was loaded, %d still out\n",
522 priv
->total_posted
,atomic_read(&priv
->buckets_out
)));
524 netif_stop_queue(dev
);
528 timeout
= jiffies
+ 2 * HZ
;
529 while (atomic_read(&priv
->buckets_out
) && time_before(jiffies
, timeout
))
530 schedule_timeout_interruptible(1);
532 for (i
= 0; i
< priv
->max_buckets_out
; i
++) {
533 if (priv
->RcvCtl
[i
].skb
!= NULL
) {
534 /**/ dlprintk((KERN_INFO MYNAM
"/lan_close: bucket %05x "
535 /**/ "is still out\n", i
));
536 pci_unmap_single(mpt_dev
->pcidev
, priv
->RcvCtl
[i
].dma
,
539 dev_kfree_skb(priv
->RcvCtl
[i
].skb
);
544 kfree(priv
->mpt_rxfidx
);
546 for (i
= 0; i
< priv
->tx_max_out
; i
++) {
547 if (priv
->SendCtl
[i
].skb
!= NULL
) {
548 pci_unmap_single(mpt_dev
->pcidev
, priv
->SendCtl
[i
].dma
,
549 priv
->SendCtl
[i
].len
,
551 dev_kfree_skb(priv
->SendCtl
[i
].skb
);
555 kfree(priv
->SendCtl
);
556 kfree(priv
->mpt_txfidx
);
558 atomic_set(&priv
->buckets_out
, 0);
560 printk(KERN_INFO MYNAM
": %s/%s: interface down & inactive\n",
561 IOC_AND_NETDEV_NAMES_s_s(dev
));
566 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
567 static struct net_device_stats
*
568 mpt_lan_get_stats(struct net_device
*dev
)
570 struct mpt_lan_priv
*priv
= netdev_priv(dev
);
572 return (struct net_device_stats
*) &priv
->stats
;
575 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
577 mpt_lan_change_mtu(struct net_device
*dev
, int new_mtu
)
579 if ((new_mtu
< MPT_LAN_MIN_MTU
) || (new_mtu
> MPT_LAN_MAX_MTU
))
585 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
586 /* Tx timeout handler. */
588 mpt_lan_tx_timeout(struct net_device
*dev
)
590 struct mpt_lan_priv
*priv
= netdev_priv(dev
);
591 MPT_ADAPTER
*mpt_dev
= priv
->mpt_dev
;
593 if (mpt_dev
->active
) {
594 dlprintk (("mptlan/tx_timeout: calling netif_wake_queue for %s.\n", dev
->name
));
595 netif_wake_queue(dev
);
599 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
602 mpt_lan_send_turbo(struct net_device
*dev
, u32 tmsg
)
604 struct mpt_lan_priv
*priv
= netdev_priv(dev
);
605 MPT_ADAPTER
*mpt_dev
= priv
->mpt_dev
;
606 struct sk_buff
*sent
;
610 ctx
= GET_LAN_BUFFER_CONTEXT(tmsg
);
611 sent
= priv
->SendCtl
[ctx
].skb
;
613 priv
->stats
.tx_packets
++;
614 priv
->stats
.tx_bytes
+= sent
->len
;
616 dioprintk((KERN_INFO MYNAM
": %s/%s: @%s, skb %p sent.\n",
617 IOC_AND_NETDEV_NAMES_s_s(dev
),
618 __FUNCTION__
, sent
));
620 priv
->SendCtl
[ctx
].skb
= NULL
;
621 pci_unmap_single(mpt_dev
->pcidev
, priv
->SendCtl
[ctx
].dma
,
622 priv
->SendCtl
[ctx
].len
, PCI_DMA_TODEVICE
);
623 dev_kfree_skb_irq(sent
);
625 spin_lock_irqsave(&priv
->txfidx_lock
, flags
);
626 priv
->mpt_txfidx
[++priv
->mpt_txfidx_tail
] = ctx
;
627 spin_unlock_irqrestore(&priv
->txfidx_lock
, flags
);
629 netif_wake_queue(dev
);
633 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
635 mpt_lan_send_reply(struct net_device
*dev
, LANSendReply_t
*pSendRep
)
637 struct mpt_lan_priv
*priv
= netdev_priv(dev
);
638 MPT_ADAPTER
*mpt_dev
= priv
->mpt_dev
;
639 struct sk_buff
*sent
;
641 int FreeReqFrame
= 0;
646 count
= pSendRep
->NumberOfContexts
;
648 dioprintk((KERN_INFO MYNAM
": send_reply: IOCStatus: %04x\n",
649 le16_to_cpu(pSendRep
->IOCStatus
)));
651 /* Add check for Loginfo Flag in IOCStatus */
653 switch (le16_to_cpu(pSendRep
->IOCStatus
) & MPI_IOCSTATUS_MASK
) {
654 case MPI_IOCSTATUS_SUCCESS
:
655 priv
->stats
.tx_packets
+= count
;
658 case MPI_IOCSTATUS_LAN_CANCELED
:
659 case MPI_IOCSTATUS_LAN_TRANSMIT_ABORTED
:
662 case MPI_IOCSTATUS_INVALID_SGL
:
663 priv
->stats
.tx_errors
+= count
;
664 printk (KERN_ERR MYNAM
": %s/%s: ERROR - Invalid SGL sent to IOC!\n",
665 IOC_AND_NETDEV_NAMES_s_s(dev
));
669 priv
->stats
.tx_errors
+= count
;
673 pContext
= &pSendRep
->BufferContext
;
675 spin_lock_irqsave(&priv
->txfidx_lock
, flags
);
677 ctx
= GET_LAN_BUFFER_CONTEXT(le32_to_cpu(*pContext
));
679 sent
= priv
->SendCtl
[ctx
].skb
;
680 priv
->stats
.tx_bytes
+= sent
->len
;
682 dioprintk((KERN_INFO MYNAM
": %s/%s: @%s, skb %p sent.\n",
683 IOC_AND_NETDEV_NAMES_s_s(dev
),
684 __FUNCTION__
, sent
));
686 priv
->SendCtl
[ctx
].skb
= NULL
;
687 pci_unmap_single(mpt_dev
->pcidev
, priv
->SendCtl
[ctx
].dma
,
688 priv
->SendCtl
[ctx
].len
, PCI_DMA_TODEVICE
);
689 dev_kfree_skb_irq(sent
);
691 priv
->mpt_txfidx
[++priv
->mpt_txfidx_tail
] = ctx
;
696 spin_unlock_irqrestore(&priv
->txfidx_lock
, flags
);
699 if (!(pSendRep
->MsgFlags
& MPI_MSGFLAGS_CONTINUATION_REPLY
))
702 netif_wake_queue(dev
);
706 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
708 mpt_lan_sdu_send (struct sk_buff
*skb
, struct net_device
*dev
)
710 struct mpt_lan_priv
*priv
= netdev_priv(dev
);
711 MPT_ADAPTER
*mpt_dev
= priv
->mpt_dev
;
713 LANSendRequest_t
*pSendReq
;
714 SGETransaction32_t
*pTrans
;
715 SGESimple64_t
*pSimple
;
719 u16 cur_naa
= 0x1000;
721 dioprintk((KERN_INFO MYNAM
": %s called, skb_addr = %p\n",
724 spin_lock_irqsave(&priv
->txfidx_lock
, flags
);
725 if (priv
->mpt_txfidx_tail
< 0) {
726 netif_stop_queue(dev
);
727 spin_unlock_irqrestore(&priv
->txfidx_lock
, flags
);
729 printk (KERN_ERR
"%s: no tx context available: %u\n",
730 __FUNCTION__
, priv
->mpt_txfidx_tail
);
734 mf
= mpt_get_msg_frame(LanCtx
, mpt_dev
);
736 netif_stop_queue(dev
);
737 spin_unlock_irqrestore(&priv
->txfidx_lock
, flags
);
739 printk (KERN_ERR
"%s: Unable to alloc request frame\n",
744 ctx
= priv
->mpt_txfidx
[priv
->mpt_txfidx_tail
--];
745 spin_unlock_irqrestore(&priv
->txfidx_lock
, flags
);
747 // dioprintk((KERN_INFO MYNAM ": %s/%s: Creating new msg frame (send).\n",
748 // IOC_AND_NETDEV_NAMES_s_s(dev)));
750 pSendReq
= (LANSendRequest_t
*) mf
;
752 /* Set the mac.raw pointer, since this apparently isn't getting
753 * done before we get the skb. Pull the data pointer past the mac data.
755 skb
->mac
.raw
= skb
->data
;
758 dma
= pci_map_single(mpt_dev
->pcidev
, skb
->data
, skb
->len
,
761 priv
->SendCtl
[ctx
].skb
= skb
;
762 priv
->SendCtl
[ctx
].dma
= dma
;
763 priv
->SendCtl
[ctx
].len
= skb
->len
;
766 pSendReq
->Reserved
= 0;
767 pSendReq
->Function
= MPI_FUNCTION_LAN_SEND
;
768 pSendReq
->ChainOffset
= 0;
769 pSendReq
->Reserved2
= 0;
770 pSendReq
->MsgFlags
= 0;
771 pSendReq
->PortNumber
= priv
->pnum
;
773 /* Transaction Context Element */
774 pTrans
= (SGETransaction32_t
*) pSendReq
->SG_List
;
776 /* No Flags, 8 bytes of Details, 32bit Context (bloody turbo replies) */
777 pTrans
->ContextSize
= sizeof(u32
);
778 pTrans
->DetailsLength
= 2 * sizeof(u32
);
780 pTrans
->TransactionContext
[0] = cpu_to_le32(ctx
);
782 // dioprintk((KERN_INFO MYNAM ": %s/%s: BC = %08x, skb = %p, buff = %p\n",
783 // IOC_AND_NETDEV_NAMES_s_s(dev),
784 // ctx, skb, skb->data));
786 #ifdef QLOGIC_NAA_WORKAROUND
788 struct NAA_Hosed
*nh
;
790 /* Munge the NAA for Tx packets to QLogic boards, which don't follow
791 RFC 2625. The longer I look at this, the more my opinion of Qlogic
793 read_lock_irq(&bad_naa_lock
);
794 for (nh
= mpt_bad_naa
; nh
!= NULL
; nh
=nh
->next
) {
795 if ((nh
->ieee
[0] == skb
->mac
.raw
[0]) &&
796 (nh
->ieee
[1] == skb
->mac
.raw
[1]) &&
797 (nh
->ieee
[2] == skb
->mac
.raw
[2]) &&
798 (nh
->ieee
[3] == skb
->mac
.raw
[3]) &&
799 (nh
->ieee
[4] == skb
->mac
.raw
[4]) &&
800 (nh
->ieee
[5] == skb
->mac
.raw
[5])) {
802 dlprintk ((KERN_INFO
"mptlan/sdu_send: using NAA value "
803 "= %04x.\n", cur_naa
));
807 read_unlock_irq(&bad_naa_lock
);
811 pTrans
->TransactionDetails
[0] = cpu_to_le32((cur_naa
<< 16) |
812 (skb
->mac
.raw
[0] << 8) |
813 (skb
->mac
.raw
[1] << 0));
814 pTrans
->TransactionDetails
[1] = cpu_to_le32((skb
->mac
.raw
[2] << 24) |
815 (skb
->mac
.raw
[3] << 16) |
816 (skb
->mac
.raw
[4] << 8) |
817 (skb
->mac
.raw
[5] << 0));
819 pSimple
= (SGESimple64_t
*) &pTrans
->TransactionDetails
[2];
821 /* If we ever decide to send more than one Simple SGE per LANSend, then
822 we will need to make sure that LAST_ELEMENT only gets set on the
823 last one. Otherwise, bad voodoo and evil funkiness will commence. */
824 pSimple
->FlagsLength
= cpu_to_le32(
825 ((MPI_SGE_FLAGS_LAST_ELEMENT
|
826 MPI_SGE_FLAGS_END_OF_BUFFER
|
827 MPI_SGE_FLAGS_SIMPLE_ELEMENT
|
828 MPI_SGE_FLAGS_SYSTEM_ADDRESS
|
829 MPI_SGE_FLAGS_HOST_TO_IOC
|
830 MPI_SGE_FLAGS_64_BIT_ADDRESSING
|
831 MPI_SGE_FLAGS_END_OF_LIST
) << MPI_SGE_FLAGS_SHIFT
) |
833 pSimple
->Address
.Low
= cpu_to_le32((u32
) dma
);
834 if (sizeof(dma_addr_t
) > sizeof(u32
))
835 pSimple
->Address
.High
= cpu_to_le32((u32
) ((u64
) dma
>> 32));
837 pSimple
->Address
.High
= 0;
839 mpt_put_msg_frame (LanCtx
, mpt_dev
, mf
);
840 dev
->trans_start
= jiffies
;
842 dioprintk((KERN_INFO MYNAM
": %s/%s: Sending packet. FlagsLength = %08x.\n",
843 IOC_AND_NETDEV_NAMES_s_s(dev
),
844 le32_to_cpu(pSimple
->FlagsLength
)));
849 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
851 mpt_lan_wake_post_buckets_task(struct net_device
*dev
, int priority
)
853 * @priority: 0 = put it on the timer queue, 1 = put it on the immediate queue
856 struct mpt_lan_priv
*priv
= dev
->priv
;
858 if (test_and_set_bit(0, &priv
->post_buckets_active
) == 0) {
860 schedule_delayed_work(&priv
->post_buckets_task
, 0);
862 schedule_delayed_work(&priv
->post_buckets_task
, 1);
863 dioprintk((KERN_INFO MYNAM
": post_buckets queued on "
866 dioprintk((KERN_INFO MYNAM
": %s/%s: Queued post_buckets task.\n",
867 IOC_AND_NETDEV_NAMES_s_s(dev
) ));
871 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
873 mpt_lan_receive_skb(struct net_device
*dev
, struct sk_buff
*skb
)
875 struct mpt_lan_priv
*priv
= dev
->priv
;
877 skb
->protocol
= mpt_lan_type_trans(skb
, dev
);
879 dioprintk((KERN_INFO MYNAM
": %s/%s: Incoming packet (%d bytes) "
880 "delivered to upper level.\n",
881 IOC_AND_NETDEV_NAMES_s_s(dev
), skb
->len
));
883 priv
->stats
.rx_bytes
+= skb
->len
;
884 priv
->stats
.rx_packets
++;
889 dioprintk((MYNAM
"/receive_skb: %d buckets remaining\n",
890 atomic_read(&priv
->buckets_out
)));
892 if (atomic_read(&priv
->buckets_out
) < priv
->bucketthresh
)
893 mpt_lan_wake_post_buckets_task(dev
, 1);
895 dioprintk((KERN_INFO MYNAM
"/receive_post_reply: %d buckets "
896 "remaining, %d received back since sod\n",
897 atomic_read(&priv
->buckets_out
), priv
->total_received
));
902 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
905 mpt_lan_receive_post_turbo(struct net_device
*dev
, u32 tmsg
)
907 struct mpt_lan_priv
*priv
= dev
->priv
;
908 MPT_ADAPTER
*mpt_dev
= priv
->mpt_dev
;
909 struct sk_buff
*skb
, *old_skb
;
913 ctx
= GET_LAN_BUCKET_CONTEXT(tmsg
);
914 skb
= priv
->RcvCtl
[ctx
].skb
;
916 len
= GET_LAN_PACKET_LENGTH(tmsg
);
918 if (len
< MPT_LAN_RX_COPYBREAK
) {
921 skb
= (struct sk_buff
*)dev_alloc_skb(len
);
923 printk (KERN_ERR MYNAM
": %s/%s: ERROR - Can't allocate skb! (%s@%d)\n",
924 IOC_AND_NETDEV_NAMES_s_s(dev
),
929 pci_dma_sync_single_for_cpu(mpt_dev
->pcidev
, priv
->RcvCtl
[ctx
].dma
,
930 priv
->RcvCtl
[ctx
].len
, PCI_DMA_FROMDEVICE
);
932 memcpy(skb_put(skb
, len
), old_skb
->data
, len
);
934 pci_dma_sync_single_for_device(mpt_dev
->pcidev
, priv
->RcvCtl
[ctx
].dma
,
935 priv
->RcvCtl
[ctx
].len
, PCI_DMA_FROMDEVICE
);
941 priv
->RcvCtl
[ctx
].skb
= NULL
;
943 pci_unmap_single(mpt_dev
->pcidev
, priv
->RcvCtl
[ctx
].dma
,
944 priv
->RcvCtl
[ctx
].len
, PCI_DMA_FROMDEVICE
);
947 spin_lock_irqsave(&priv
->rxfidx_lock
, flags
);
948 priv
->mpt_rxfidx
[++priv
->mpt_rxfidx_tail
] = ctx
;
949 spin_unlock_irqrestore(&priv
->rxfidx_lock
, flags
);
951 atomic_dec(&priv
->buckets_out
);
952 priv
->total_received
++;
954 return mpt_lan_receive_skb(dev
, skb
);
957 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
959 mpt_lan_receive_post_free(struct net_device
*dev
,
960 LANReceivePostReply_t
*pRecvRep
)
962 struct mpt_lan_priv
*priv
= dev
->priv
;
963 MPT_ADAPTER
*mpt_dev
= priv
->mpt_dev
;
970 count
= pRecvRep
->NumberOfContexts
;
972 /**/ dlprintk((KERN_INFO MYNAM
"/receive_post_reply: "
973 "IOC returned %d buckets, freeing them...\n", count
));
975 spin_lock_irqsave(&priv
->rxfidx_lock
, flags
);
976 for (i
= 0; i
< count
; i
++) {
977 ctx
= le32_to_cpu(pRecvRep
->BucketContext
[i
]);
979 skb
= priv
->RcvCtl
[ctx
].skb
;
981 // dlprintk((KERN_INFO MYNAM ": %s: dev_name = %s\n",
982 // IOC_AND_NETDEV_NAMES_s_s(dev)));
983 // dlprintk((KERN_INFO MYNAM "@rpr[2], priv = %p, buckets_out addr = %p",
984 // priv, &(priv->buckets_out)));
985 // dlprintk((KERN_INFO MYNAM "@rpr[2] TC + 3\n"));
987 priv
->RcvCtl
[ctx
].skb
= NULL
;
988 pci_unmap_single(mpt_dev
->pcidev
, priv
->RcvCtl
[ctx
].dma
,
989 priv
->RcvCtl
[ctx
].len
, PCI_DMA_FROMDEVICE
);
990 dev_kfree_skb_any(skb
);
992 priv
->mpt_rxfidx
[++priv
->mpt_rxfidx_tail
] = ctx
;
994 spin_unlock_irqrestore(&priv
->rxfidx_lock
, flags
);
996 atomic_sub(count
, &priv
->buckets_out
);
998 // for (i = 0; i < priv->max_buckets_out; i++)
999 // if (priv->RcvCtl[i].skb != NULL)
1000 // dlprintk((KERN_INFO MYNAM "@rpr: bucket %03x "
1001 // "is still out\n", i));
1003 /* dlprintk((KERN_INFO MYNAM "/receive_post_reply: freed %d buckets\n",
1006 /**/ dlprintk((KERN_INFO MYNAM
"@receive_post_reply: %d buckets "
1007 /**/ "remaining, %d received back since sod.\n",
1008 /**/ atomic_read(&priv
->buckets_out
), priv
->total_received
));
1012 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1014 mpt_lan_receive_post_reply(struct net_device
*dev
,
1015 LANReceivePostReply_t
*pRecvRep
)
1017 struct mpt_lan_priv
*priv
= dev
->priv
;
1018 MPT_ADAPTER
*mpt_dev
= priv
->mpt_dev
;
1019 struct sk_buff
*skb
, *old_skb
;
1020 unsigned long flags
;
1021 u32 len
, ctx
, offset
;
1022 u32 remaining
= le32_to_cpu(pRecvRep
->BucketsRemaining
);
1026 dioprintk((KERN_INFO MYNAM
": mpt_lan_receive_post_reply called\n"));
1027 dioprintk((KERN_INFO MYNAM
": receive_post_reply: IOCStatus: %04x\n",
1028 le16_to_cpu(pRecvRep
->IOCStatus
)));
1030 if ((le16_to_cpu(pRecvRep
->IOCStatus
) & MPI_IOCSTATUS_MASK
) ==
1031 MPI_IOCSTATUS_LAN_CANCELED
)
1032 return mpt_lan_receive_post_free(dev
, pRecvRep
);
1034 len
= le32_to_cpu(pRecvRep
->PacketLength
);
1036 printk (KERN_ERR MYNAM
": %s/%s: ERROR - Got a non-TURBO "
1037 "ReceivePostReply w/ PacketLength zero!\n",
1038 IOC_AND_NETDEV_NAMES_s_s(dev
));
1039 printk (KERN_ERR MYNAM
": MsgFlags = %02x, IOCStatus = %04x\n",
1040 pRecvRep
->MsgFlags
, le16_to_cpu(pRecvRep
->IOCStatus
));
1044 ctx
= le32_to_cpu(pRecvRep
->BucketContext
[0]);
1045 count
= pRecvRep
->NumberOfContexts
;
1046 skb
= priv
->RcvCtl
[ctx
].skb
;
1048 offset
= le32_to_cpu(pRecvRep
->PacketOffset
);
1049 // if (offset != 0) {
1050 // printk (KERN_INFO MYNAM ": %s/%s: Got a ReceivePostReply "
1051 // "w/ PacketOffset %u\n",
1052 // IOC_AND_NETDEV_NAMES_s_s(dev),
1056 dioprintk((KERN_INFO MYNAM
": %s/%s: @rpr, offset = %d, len = %d\n",
1057 IOC_AND_NETDEV_NAMES_s_s(dev
),
1063 // dioprintk((KERN_INFO MYNAM ": %s/%s: Multiple buckets returned "
1064 // "for single packet, concatenating...\n",
1065 // IOC_AND_NETDEV_NAMES_s_s(dev)));
1067 skb
= (struct sk_buff
*)dev_alloc_skb(len
);
1069 printk (KERN_ERR MYNAM
": %s/%s: ERROR - Can't allocate skb! (%s@%d)\n",
1070 IOC_AND_NETDEV_NAMES_s_s(dev
),
1071 __FILE__
, __LINE__
);
1075 spin_lock_irqsave(&priv
->rxfidx_lock
, flags
);
1076 for (i
= 0; i
< count
; i
++) {
1078 ctx
= le32_to_cpu(pRecvRep
->BucketContext
[i
]);
1079 old_skb
= priv
->RcvCtl
[ctx
].skb
;
1081 l
= priv
->RcvCtl
[ctx
].len
;
1085 // dioprintk((KERN_INFO MYNAM ": %s/%s: Buckets = %d, len = %u\n",
1086 // IOC_AND_NETDEV_NAMES_s_s(dev),
1089 pci_dma_sync_single_for_cpu(mpt_dev
->pcidev
,
1090 priv
->RcvCtl
[ctx
].dma
,
1091 priv
->RcvCtl
[ctx
].len
,
1092 PCI_DMA_FROMDEVICE
);
1093 memcpy(skb_put(skb
, l
), old_skb
->data
, l
);
1095 pci_dma_sync_single_for_device(mpt_dev
->pcidev
,
1096 priv
->RcvCtl
[ctx
].dma
,
1097 priv
->RcvCtl
[ctx
].len
,
1098 PCI_DMA_FROMDEVICE
);
1100 priv
->mpt_rxfidx
[++priv
->mpt_rxfidx_tail
] = ctx
;
1103 spin_unlock_irqrestore(&priv
->rxfidx_lock
, flags
);
1105 } else if (len
< MPT_LAN_RX_COPYBREAK
) {
1109 skb
= (struct sk_buff
*)dev_alloc_skb(len
);
1111 printk (KERN_ERR MYNAM
": %s/%s: ERROR - Can't allocate skb! (%s@%d)\n",
1112 IOC_AND_NETDEV_NAMES_s_s(dev
),
1113 __FILE__
, __LINE__
);
1117 pci_dma_sync_single_for_cpu(mpt_dev
->pcidev
,
1118 priv
->RcvCtl
[ctx
].dma
,
1119 priv
->RcvCtl
[ctx
].len
,
1120 PCI_DMA_FROMDEVICE
);
1122 memcpy(skb_put(skb
, len
), old_skb
->data
, len
);
1124 pci_dma_sync_single_for_device(mpt_dev
->pcidev
,
1125 priv
->RcvCtl
[ctx
].dma
,
1126 priv
->RcvCtl
[ctx
].len
,
1127 PCI_DMA_FROMDEVICE
);
1129 spin_lock_irqsave(&priv
->rxfidx_lock
, flags
);
1130 priv
->mpt_rxfidx
[++priv
->mpt_rxfidx_tail
] = ctx
;
1131 spin_unlock_irqrestore(&priv
->rxfidx_lock
, flags
);
1134 spin_lock_irqsave(&priv
->rxfidx_lock
, flags
);
1136 priv
->RcvCtl
[ctx
].skb
= NULL
;
1138 pci_unmap_single(mpt_dev
->pcidev
, priv
->RcvCtl
[ctx
].dma
,
1139 priv
->RcvCtl
[ctx
].len
, PCI_DMA_FROMDEVICE
);
1140 priv
->RcvCtl
[ctx
].dma
= 0;
1142 priv
->mpt_rxfidx
[++priv
->mpt_rxfidx_tail
] = ctx
;
1143 spin_unlock_irqrestore(&priv
->rxfidx_lock
, flags
);
1148 atomic_sub(count
, &priv
->buckets_out
);
1149 priv
->total_received
+= count
;
1151 if (priv
->mpt_rxfidx_tail
>= MPT_LAN_MAX_BUCKETS_OUT
) {
1152 printk (KERN_ERR MYNAM
": %s/%s: Yoohoo! mpt_rxfidx_tail = %d, "
1153 "MPT_LAN_MAX_BUCKETS_OUT = %d\n",
1154 IOC_AND_NETDEV_NAMES_s_s(dev
),
1155 priv
->mpt_rxfidx_tail
,
1156 MPT_LAN_MAX_BUCKETS_OUT
);
1162 printk (KERN_WARNING MYNAM
": %s/%s: WARNING - IOC out of buckets! "
1163 "(priv->buckets_out = %d)\n",
1164 IOC_AND_NETDEV_NAMES_s_s(dev
),
1165 atomic_read(&priv
->buckets_out
));
1166 else if (remaining
< 10)
1167 printk (KERN_INFO MYNAM
": %s/%s: IOC says %d buckets left. "
1168 "(priv->buckets_out = %d)\n",
1169 IOC_AND_NETDEV_NAMES_s_s(dev
),
1170 remaining
, atomic_read(&priv
->buckets_out
));
1172 if ((remaining
< priv
->bucketthresh
) &&
1173 ((atomic_read(&priv
->buckets_out
) - remaining
) >
1174 MPT_LAN_BUCKETS_REMAIN_MISMATCH_THRESH
)) {
1176 printk (KERN_WARNING MYNAM
" Mismatch between driver's "
1177 "buckets_out count and fw's BucketsRemaining "
1178 "count has crossed the threshold, issuing a "
1179 "LanReset to clear the fw's hashtable. You may "
1180 "want to check your /var/log/messages for \"CRC "
1181 "error\" event notifications.\n");
1184 mpt_lan_wake_post_buckets_task(dev
, 0);
1187 return mpt_lan_receive_skb(dev
, skb
);
1190 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1191 /* Simple SGE's only at the moment */
1194 mpt_lan_post_receive_buckets(struct mpt_lan_priv
*priv
)
1196 struct net_device
*dev
= priv
->dev
;
1197 MPT_ADAPTER
*mpt_dev
= priv
->mpt_dev
;
1199 LANReceivePostRequest_t
*pRecvReq
;
1200 SGETransaction32_t
*pTrans
;
1201 SGESimple64_t
*pSimple
;
1202 struct sk_buff
*skb
;
1204 u32 curr
, buckets
, count
, max
;
1205 u32 len
= (dev
->mtu
+ dev
->hard_header_len
+ 4);
1206 unsigned long flags
;
1209 curr
= atomic_read(&priv
->buckets_out
);
1210 buckets
= (priv
->max_buckets_out
- curr
);
1212 dioprintk((KERN_INFO MYNAM
": %s/%s: @%s, Start_buckets = %u, buckets_out = %u\n",
1213 IOC_AND_NETDEV_NAMES_s_s(dev
),
1214 __FUNCTION__
, buckets
, curr
));
1216 max
= (mpt_dev
->req_sz
- MPT_LAN_RECEIVE_POST_REQUEST_SIZE
) /
1217 (MPT_LAN_TRANSACTION32_SIZE
+ sizeof(SGESimple64_t
));
1220 mf
= mpt_get_msg_frame(LanCtx
, mpt_dev
);
1222 printk (KERN_ERR
"%s: Unable to alloc request frame\n",
1224 dioprintk((KERN_ERR
"%s: %u buckets remaining\n",
1225 __FUNCTION__
, buckets
));
1228 pRecvReq
= (LANReceivePostRequest_t
*) mf
;
1234 pRecvReq
->Function
= MPI_FUNCTION_LAN_RECEIVE
;
1235 pRecvReq
->ChainOffset
= 0;
1236 pRecvReq
->MsgFlags
= 0;
1237 pRecvReq
->PortNumber
= priv
->pnum
;
1239 pTrans
= (SGETransaction32_t
*) pRecvReq
->SG_List
;
1242 for (i
= 0; i
< count
; i
++) {
1245 spin_lock_irqsave(&priv
->rxfidx_lock
, flags
);
1246 if (priv
->mpt_rxfidx_tail
< 0) {
1247 printk (KERN_ERR
"%s: Can't alloc context\n",
1249 spin_unlock_irqrestore(&priv
->rxfidx_lock
,
1254 ctx
= priv
->mpt_rxfidx
[priv
->mpt_rxfidx_tail
--];
1256 skb
= priv
->RcvCtl
[ctx
].skb
;
1257 if (skb
&& (priv
->RcvCtl
[ctx
].len
!= len
)) {
1258 pci_unmap_single(mpt_dev
->pcidev
,
1259 priv
->RcvCtl
[ctx
].dma
,
1260 priv
->RcvCtl
[ctx
].len
,
1261 PCI_DMA_FROMDEVICE
);
1262 dev_kfree_skb(priv
->RcvCtl
[ctx
].skb
);
1263 skb
= priv
->RcvCtl
[ctx
].skb
= NULL
;
1267 skb
= dev_alloc_skb(len
);
1269 printk (KERN_WARNING
1270 MYNAM
"/%s: Can't alloc skb\n",
1272 priv
->mpt_rxfidx
[++priv
->mpt_rxfidx_tail
] = ctx
;
1273 spin_unlock_irqrestore(&priv
->rxfidx_lock
, flags
);
1277 dma
= pci_map_single(mpt_dev
->pcidev
, skb
->data
,
1278 len
, PCI_DMA_FROMDEVICE
);
1280 priv
->RcvCtl
[ctx
].skb
= skb
;
1281 priv
->RcvCtl
[ctx
].dma
= dma
;
1282 priv
->RcvCtl
[ctx
].len
= len
;
1285 spin_unlock_irqrestore(&priv
->rxfidx_lock
, flags
);
1287 pTrans
->ContextSize
= sizeof(u32
);
1288 pTrans
->DetailsLength
= 0;
1290 pTrans
->TransactionContext
[0] = cpu_to_le32(ctx
);
1292 pSimple
= (SGESimple64_t
*) pTrans
->TransactionDetails
;
1294 pSimple
->FlagsLength
= cpu_to_le32(
1295 ((MPI_SGE_FLAGS_END_OF_BUFFER
|
1296 MPI_SGE_FLAGS_SIMPLE_ELEMENT
|
1297 MPI_SGE_FLAGS_64_BIT_ADDRESSING
) << MPI_SGE_FLAGS_SHIFT
) | len
);
1298 pSimple
->Address
.Low
= cpu_to_le32((u32
) priv
->RcvCtl
[ctx
].dma
);
1299 if (sizeof(dma_addr_t
) > sizeof(u32
))
1300 pSimple
->Address
.High
= cpu_to_le32((u32
) ((u64
) priv
->RcvCtl
[ctx
].dma
>> 32));
1302 pSimple
->Address
.High
= 0;
1304 pTrans
= (SGETransaction32_t
*) (pSimple
+ 1);
1307 if (pSimple
== NULL
) {
1308 /**/ printk (KERN_WARNING MYNAM
"/%s: No buckets posted\n",
1310 mpt_free_msg_frame(mpt_dev
, mf
);
1314 pSimple
->FlagsLength
|= cpu_to_le32(MPI_SGE_FLAGS_END_OF_LIST
<< MPI_SGE_FLAGS_SHIFT
);
1316 pRecvReq
->BucketCount
= cpu_to_le32(i
);
1318 /* printk(KERN_INFO MYNAM ": posting buckets\n ");
1319 * for (i = 0; i < j + 2; i ++)
1320 * printk (" %08x", le32_to_cpu(msg[i]));
1324 mpt_put_msg_frame(LanCtx
, mpt_dev
, mf
);
1326 priv
->total_posted
+= i
;
1328 atomic_add(i
, &priv
->buckets_out
);
1332 dioprintk((KERN_INFO MYNAM
"/%s: End_buckets = %u, priv->buckets_out = %u\n",
1333 __FUNCTION__
, buckets
, atomic_read(&priv
->buckets_out
)));
1334 dioprintk((KERN_INFO MYNAM
"/%s: Posted %u buckets and received %u back\n",
1335 __FUNCTION__
, priv
->total_posted
, priv
->total_received
));
1337 clear_bit(0, &priv
->post_buckets_active
);
1341 mpt_lan_post_receive_buckets_work(struct work_struct
*work
)
1343 mpt_lan_post_receive_buckets(container_of(work
, struct mpt_lan_priv
,
1344 post_buckets_task
.work
));
1347 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1348 static struct net_device
*
1349 mpt_register_lan_device (MPT_ADAPTER
*mpt_dev
, int pnum
)
1351 struct net_device
*dev
= alloc_fcdev(sizeof(struct mpt_lan_priv
));
1352 struct mpt_lan_priv
*priv
= NULL
;
1353 u8 HWaddr
[FC_ALEN
], *a
;
1358 dev
->mtu
= MPT_LAN_MTU
;
1360 priv
= netdev_priv(dev
);
1363 priv
->mpt_dev
= mpt_dev
;
1366 memset(&priv
->post_buckets_task
, 0, sizeof(priv
->post_buckets_task
));
1367 INIT_DELAYED_WORK(&priv
->post_buckets_task
,
1368 mpt_lan_post_receive_buckets_work
);
1369 priv
->post_buckets_active
= 0;
1371 dlprintk((KERN_INFO MYNAM
"@%d: bucketlen = %d\n",
1372 __LINE__
, dev
->mtu
+ dev
->hard_header_len
+ 4));
1374 atomic_set(&priv
->buckets_out
, 0);
1375 priv
->total_posted
= 0;
1376 priv
->total_received
= 0;
1377 priv
->max_buckets_out
= max_buckets_out
;
1378 if (mpt_dev
->pfacts
[0].MaxLanBuckets
< max_buckets_out
)
1379 priv
->max_buckets_out
= mpt_dev
->pfacts
[0].MaxLanBuckets
;
1381 dlprintk((KERN_INFO MYNAM
"@%d: MaxLanBuckets=%d, max_buckets_out/priv=%d/%d\n",
1383 mpt_dev
->pfacts
[0].MaxLanBuckets
,
1385 priv
->max_buckets_out
));
1387 priv
->bucketthresh
= priv
->max_buckets_out
* 2 / 3;
1388 spin_lock_init(&priv
->txfidx_lock
);
1389 spin_lock_init(&priv
->rxfidx_lock
);
1391 memset(&priv
->stats
, 0, sizeof(priv
->stats
));
1393 /* Grab pre-fetched LANPage1 stuff. :-) */
1394 a
= (u8
*) &mpt_dev
->lan_cnfg_page1
.HardwareAddressLow
;
1403 dev
->addr_len
= FC_ALEN
;
1404 memcpy(dev
->dev_addr
, HWaddr
, FC_ALEN
);
1405 memset(dev
->broadcast
, 0xff, FC_ALEN
);
1407 /* The Tx queue is 127 deep on the 909.
1408 * Give ourselves some breathing room.
1410 priv
->tx_max_out
= (tx_max_out_p
<= MPT_TX_MAX_OUT_LIM
) ?
1411 tx_max_out_p
: MPT_TX_MAX_OUT_LIM
;
1413 dev
->open
= mpt_lan_open
;
1414 dev
->stop
= mpt_lan_close
;
1415 dev
->get_stats
= mpt_lan_get_stats
;
1416 dev
->set_multicast_list
= NULL
;
1417 dev
->change_mtu
= mpt_lan_change_mtu
;
1418 dev
->hard_start_xmit
= mpt_lan_sdu_send
;
1420 /* Not in 2.3.42. Need 2.3.45+ */
1421 dev
->tx_timeout
= mpt_lan_tx_timeout
;
1422 dev
->watchdog_timeo
= MPT_LAN_TX_TIMEOUT
;
1424 dlprintk((KERN_INFO MYNAM
": Finished registering dev "
1425 "and setting initial values\n"));
1427 SET_MODULE_OWNER(dev
);
1429 if (register_netdev(dev
) != 0) {
1437 mptlan_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
1439 MPT_ADAPTER
*ioc
= pci_get_drvdata(pdev
);
1440 struct net_device
*dev
;
1443 for (i
= 0; i
< ioc
->facts
.NumberOfPorts
; i
++) {
1444 printk(KERN_INFO MYNAM
": %s: PortNum=%x, "
1445 "ProtocolFlags=%02Xh (%c%c%c%c)\n",
1446 ioc
->name
, ioc
->pfacts
[i
].PortNumber
,
1447 ioc
->pfacts
[i
].ProtocolFlags
,
1448 MPT_PROTOCOL_FLAGS_c_c_c_c(
1449 ioc
->pfacts
[i
].ProtocolFlags
));
1451 if (!(ioc
->pfacts
[i
].ProtocolFlags
&
1452 MPI_PORTFACTS_PROTOCOL_LAN
)) {
1453 printk(KERN_INFO MYNAM
": %s: Hmmm... LAN protocol "
1454 "seems to be disabled on this adapter port!\n",
1459 dev
= mpt_register_lan_device(ioc
, i
);
1461 printk(KERN_ERR MYNAM
": %s: Unable to register "
1462 "port%d as a LAN device\n", ioc
->name
,
1463 ioc
->pfacts
[i
].PortNumber
);
1467 printk(KERN_INFO MYNAM
": %s: Fusion MPT LAN device "
1468 "registered as '%s'\n", ioc
->name
, dev
->name
);
1469 printk(KERN_INFO MYNAM
": %s/%s: "
1470 "LanAddr = %02X:%02X:%02X:%02X:%02X:%02X\n",
1471 IOC_AND_NETDEV_NAMES_s_s(dev
),
1472 dev
->dev_addr
[0], dev
->dev_addr
[1],
1473 dev
->dev_addr
[2], dev
->dev_addr
[3],
1474 dev
->dev_addr
[4], dev
->dev_addr
[5]);
1485 mptlan_remove(struct pci_dev
*pdev
)
1487 MPT_ADAPTER
*ioc
= pci_get_drvdata(pdev
);
1488 struct net_device
*dev
= ioc
->netdev
;
1491 unregister_netdev(dev
);
1496 static struct mpt_pci_driver mptlan_driver
= {
1497 .probe
= mptlan_probe
,
1498 .remove
= mptlan_remove
,
1501 static int __init
mpt_lan_init (void)
1503 show_mptmod_ver(LANAME
, LANVER
);
1505 if ((LanCtx
= mpt_register(lan_reply
, MPTLAN_DRIVER
)) <= 0) {
1506 printk (KERN_ERR MYNAM
": Failed to register with MPT base driver\n");
1510 /* Set the callback index to be used by driver core for turbo replies */
1511 mpt_lan_index
= LanCtx
;
1513 dlprintk((KERN_INFO MYNAM
": assigned context of %d\n", LanCtx
));
1515 if (mpt_reset_register(LanCtx
, mpt_lan_ioc_reset
)) {
1516 printk(KERN_ERR MYNAM
": Eieee! unable to register a reset "
1517 "handler with mptbase! The world is at an end! "
1518 "Everything is fading to black! Goodbye.\n");
1522 dlprintk((KERN_INFO MYNAM
": Registered for IOC reset notifications\n"));
1524 if (mpt_device_driver_register(&mptlan_driver
, MPTLAN_DRIVER
))
1525 dprintk((KERN_INFO MYNAM
": failed to register dd callbacks\n"));
1529 static void __exit
mpt_lan_exit(void)
1531 mpt_device_driver_deregister(MPTLAN_DRIVER
);
1532 mpt_reset_deregister(LanCtx
);
1535 mpt_deregister(LanCtx
);
1541 module_init(mpt_lan_init
);
1542 module_exit(mpt_lan_exit
);
1544 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1545 static unsigned short
1546 mpt_lan_type_trans(struct sk_buff
*skb
, struct net_device
*dev
)
1548 struct mpt_lan_ohdr
*fch
= (struct mpt_lan_ohdr
*)skb
->data
;
1549 struct fcllc
*fcllc
;
1551 skb
->mac
.raw
= skb
->data
;
1552 skb_pull(skb
, sizeof(struct mpt_lan_ohdr
));
1554 if (fch
->dtype
== htons(0xffff)) {
1555 u32
*p
= (u32
*) fch
;
1562 printk (KERN_WARNING MYNAM
": %s: WARNING - Broadcast swap F/W bug detected!\n",
1563 NETDEV_PTR_TO_IOC_NAME_s(dev
));
1564 printk (KERN_WARNING MYNAM
": Please update sender @ MAC_addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
1565 fch
->saddr
[0], fch
->saddr
[1], fch
->saddr
[2],
1566 fch
->saddr
[3], fch
->saddr
[4], fch
->saddr
[5]);
1569 if (*fch
->daddr
& 1) {
1570 if (!memcmp(fch
->daddr
, dev
->broadcast
, FC_ALEN
)) {
1571 skb
->pkt_type
= PACKET_BROADCAST
;
1573 skb
->pkt_type
= PACKET_MULTICAST
;
1576 if (memcmp(fch
->daddr
, dev
->dev_addr
, FC_ALEN
)) {
1577 skb
->pkt_type
= PACKET_OTHERHOST
;
1579 skb
->pkt_type
= PACKET_HOST
;
1583 fcllc
= (struct fcllc
*)skb
->data
;
1585 #ifdef QLOGIC_NAA_WORKAROUND
1587 u16 source_naa
= fch
->stype
, found
= 0;
1589 /* Workaround for QLogic not following RFC 2625 in regards to the NAA
1592 if ((source_naa
& 0xF000) == 0)
1593 source_naa
= swab16(source_naa
);
1595 if (fcllc
->ethertype
== htons(ETH_P_ARP
))
1596 dlprintk ((KERN_INFO
"mptlan/type_trans: got arp req/rep w/ naa of "
1597 "%04x.\n", source_naa
));
1599 if ((fcllc
->ethertype
== htons(ETH_P_ARP
)) &&
1600 ((source_naa
>> 12) != MPT_LAN_NAA_RFC2625
)){
1601 struct NAA_Hosed
*nh
, *prevnh
;
1604 dlprintk ((KERN_INFO
"mptlan/type_trans: ARP Req/Rep from "
1605 "system with non-RFC 2625 NAA value (%04x).\n",
1608 write_lock_irq(&bad_naa_lock
);
1609 for (prevnh
= nh
= mpt_bad_naa
; nh
!= NULL
;
1610 prevnh
=nh
, nh
=nh
->next
) {
1611 if ((nh
->ieee
[0] == fch
->saddr
[0]) &&
1612 (nh
->ieee
[1] == fch
->saddr
[1]) &&
1613 (nh
->ieee
[2] == fch
->saddr
[2]) &&
1614 (nh
->ieee
[3] == fch
->saddr
[3]) &&
1615 (nh
->ieee
[4] == fch
->saddr
[4]) &&
1616 (nh
->ieee
[5] == fch
->saddr
[5])) {
1618 dlprintk ((KERN_INFO
"mptlan/type_trans: ARP Re"
1619 "q/Rep w/ bad NAA from system already"
1625 if ((!found
) && (nh
== NULL
)) {
1627 nh
= kmalloc(sizeof(struct NAA_Hosed
), GFP_KERNEL
);
1628 dlprintk ((KERN_INFO
"mptlan/type_trans: ARP Req/Rep w/"
1629 " bad NAA from system not yet in DB.\n"));
1638 nh
->NAA
= source_naa
; /* Set the S_NAA value. */
1639 for (i
= 0; i
< FC_ALEN
; i
++)
1640 nh
->ieee
[i
] = fch
->saddr
[i
];
1641 dlprintk ((KERN_INFO
"Got ARP from %02x:%02x:%02x:%02x:"
1642 "%02x:%02x with non-compliant S_NAA value.\n",
1643 fch
->saddr
[0], fch
->saddr
[1], fch
->saddr
[2],
1644 fch
->saddr
[3], fch
->saddr
[4],fch
->saddr
[5]));
1646 printk (KERN_ERR
"mptlan/type_trans: Unable to"
1647 " kmalloc a NAA_Hosed struct.\n");
1649 } else if (!found
) {
1650 printk (KERN_ERR
"mptlan/type_trans: found not"
1651 " set, but nh isn't null. Evil "
1652 "funkiness abounds.\n");
1654 write_unlock_irq(&bad_naa_lock
);
1659 /* Strip the SNAP header from ARP packets since we don't
1660 * pass them through to the 802.2/SNAP layers.
1662 if (fcllc
->dsap
== EXTENDED_SAP
&&
1663 (fcllc
->ethertype
== htons(ETH_P_IP
) ||
1664 fcllc
->ethertype
== htons(ETH_P_ARP
))) {
1665 skb_pull(skb
, sizeof(struct fcllc
));
1666 return fcllc
->ethertype
;
1669 return htons(ETH_P_802_2
);
1672 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/